add: paginate notifications/requests pages

This commit is contained in:
trisua 2025-06-02 21:39:35 -04:00
parent 4be98ead53
commit 1ac64d34ed
5 changed files with 74 additions and 6 deletions

View file

@ -54,7 +54,9 @@
(text "{{ text \"notifs:label.mark_all_as_unread\" }}")))))))
(div
("class" "card tertiary flex flex-col gap-4")
(text "{% for notification in notifications %} {{ components::notification(notification=notification) }} {% endfor %}"))))
(text "{% for notification in notifications %} {{ components::notification(notification=notification) }} {% endfor %}")))
(text "{{ components::pagination(page=page, items=notifications|length, key=\"&id=\", value=profile.id) }}"))
(script
(text "async function mark_all_as_read(read) {

View file

@ -128,7 +128,9 @@
("class" "red quaternary")
("onclick" "trigger('me::ip_block_question', ['{{ question[0].id }}'])")
(text "{{ text \"auth:action.ip_block\" }}")))))
(text "{% endfor %}"))))
(text "{% endfor %}")))
(text "{{ components::pagination(page=page, items=requests|length, key=\"&id=\", value=profile.id) }}"))
(script
(text "async function remove_request(id, linked_asset) {

View file

@ -361,6 +361,8 @@ pub async fn all_questions_request(
pub struct NotificationsProps {
#[serde(default)]
pub id: usize,
#[serde(default)]
pub page: usize,
}
/// `/notifs`
@ -379,7 +381,7 @@ pub async fn notifications_request(
}
};
let profile = if props.id != 0 {
let profile = if props.id != 0 && user.permissions.check(FinePermission::MANAGE_NOTIFICATIONS) {
match data.0.get_user_by_id(props.id).await {
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &None).await)),
@ -388,7 +390,11 @@ pub async fn notifications_request(
user.clone()
};
let notifications = match data.0.get_notifications_by_owner(profile.id).await {
let notifications = match data
.0
.get_notifications_by_owner_paginated(profile.id, 12, props.page)
.await
{
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
};
@ -396,6 +402,7 @@ pub async fn notifications_request(
let lang = get_lang!(jar, data.0);
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
context.insert("page", &props.page);
context.insert("profile", &profile);
context.insert("notifications", &notifications);
@ -421,7 +428,7 @@ pub async fn requests_request(
}
};
let profile = if props.id != 0 {
let profile = if props.id != 0 && user.permissions.check(FinePermission::MANAGE_REQUESTS) {
match data.0.get_user_by_id(props.id).await {
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &None).await)),
@ -432,7 +439,11 @@ pub async fn requests_request(
let requests = match data
.0
.get_requests_by_owner(if props.id != 0 { props.id } else { user.id })
.get_requests_by_owner_paginated(
if props.id != 0 { props.id } else { user.id },
12,
props.page,
)
.await
{
Ok(p) => p,
@ -481,6 +492,7 @@ pub async fn requests_request(
let lang = get_lang!(jar, data.0);
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
context.insert("page", &props.page);
context.insert("profile", &profile);
context.insert("requests", &requests);
context.insert("questions", &questions);