Skip to content

Commit cb0c106

Browse files
committed
fix paging
1 parent 138cc99 commit cb0c106

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

routers/web/user/notification.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func Notifications(ctx *context.Context) {
4848

4949
func prepareUserNotificationsData(ctx *context.Context) {
5050
pageType := ctx.FormString("type", ctx.FormString("q")) // "q" is the legacy query parameter for "page type"
51-
page := min(1, ctx.FormInt("page"))
52-
perPage := util.IfZero(ctx.FormInt("perPage"), 20)
51+
page := max(1, ctx.FormInt("page"))
52+
perPage := util.IfZero(ctx.FormInt("perPage"), 20) // this value is never used or exposed ....
5353
queryStatus := util.Iif(pageType == "read", activities_model.NotificationStatusRead, activities_model.NotificationStatusUnread)
5454

5555
total, err := db.Count[activities_model.Notification](ctx, activities_model.FindNotificationOptions{
@@ -64,7 +64,7 @@ func prepareUserNotificationsData(ctx *context.Context) {
6464
// redirect to the last page if request page is more than total pages
6565
pager := context.NewPagination(int(total), perPage, page, 5)
6666
if pager.Paginater.Current() < page {
67-
ctx.Redirect(fmt.Sprintf("%s/notifications?q=%s&page=%d", setting.AppSubURL, url.QueryEscape(ctx.FormString("q")), pager.Paginater.Current()))
67+
ctx.Redirect(fmt.Sprintf("%s/notifications?type=%s&page=%d", setting.AppSubURL, url.QueryEscape(pageType), pager.Paginater.Current()))
6868
return
6969
}
7070

@@ -136,18 +136,18 @@ func prepareUserNotificationsData(ctx *context.Context) {
136136
// NotificationStatusPost is a route for changing the status of a notification
137137
func NotificationStatusPost(ctx *context.Context) {
138138
notificationID := ctx.FormInt64("notification_id")
139-
var status activities_model.NotificationStatus
139+
var newStatus activities_model.NotificationStatus
140140
switch ctx.FormString("notification_action") {
141141
case "mark_as_read":
142-
status = activities_model.NotificationStatusRead
142+
newStatus = activities_model.NotificationStatusRead
143143
case "mark_as_unread":
144-
status = activities_model.NotificationStatusUnread
144+
newStatus = activities_model.NotificationStatusUnread
145145
case "pin":
146-
status = activities_model.NotificationStatusPinned
146+
newStatus = activities_model.NotificationStatusPinned
147147
default:
148148
return // ignore user's invalid input
149149
}
150-
if _, err := activities_model.SetNotificationStatus(ctx, notificationID, ctx.Doer, status); err != nil {
150+
if _, err := activities_model.SetNotificationStatus(ctx, notificationID, ctx.Doer, newStatus); err != nil {
151151
ctx.ServerError("SetNotificationStatus", err)
152152
return
153153
}

templates/user/notification/notification_div.tmpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@
5454
{{DateUtils.TimeSince $one.UpdatedUnix}}
5555
{{end}}
5656
</div>
57-
<form class="notifications-buttons" action="{{AppSubUrl}}/notifications/status?type={{$.PageType}}" method="post"
57+
<form class="notifications-buttons" action="{{AppSubUrl}}/notifications/status?type={{$.PageType}}&page={{$.Page.Paginater.Current}}&perPage={{$.Page.Paginater.PagingNum}}" method="post"
5858
hx-boost="true" hx-target="#notification_div" hx-swap="outerHTML"
5959
>
6060
{{$.CsrfTokenHtml}}
6161
<input type="hidden" name="notification_id" value="{{$one.ID}}">
62-
<input type="hidden" name="page" value="{{$.Page.Paginater.Current}}">
6362
{{if ne $one.Status $statusPinned}}
6463
<button class="btn interact-bg tw-p-2" data-tooltip-content="{{ctx.Locale.Tr "notification.pin"}}"
6564
name="notification_action" value="pin"

0 commit comments

Comments
 (0)