diff --git a/pages/index.go b/pages/index.go index efebf63d..5bf0dc10 100644 --- a/pages/index.go +++ b/pages/index.go @@ -144,7 +144,8 @@ func Configure(app *aero.Application) { l.Page("/group/:id/forum", group.Forum) // Notifications - l.Page("/notifications", notifications.All) + l.Page("/notifications", notifications.ByUser) + l.Page("/notifications/all", notifications.All) // User profiles l.Page("/user", user.Get) @@ -162,7 +163,7 @@ func Configure(app *aero.Application) { l.Page("/user/:nick/animelist/dropped", animelist.FilterByStatus(arn.AnimeListStatusDropped)) l.Page("/user/:nick/animelist/anime/:id", animelistitem.Get) l.Page("/user/:nick/recommended/anime", recommended.Anime) - l.Page("/user/:nick/notifications", notifications.All) + l.Page("/user/:nick/notifications", notifications.ByUser) // Anime list l.Page("/animelist/watching", home.FilterByStatus(arn.AnimeListStatusWatching)) diff --git a/pages/notifications/notifications.go b/pages/notifications/notifications.go index 496cb3cb..158d193a 100644 --- a/pages/notifications/notifications.go +++ b/pages/notifications/notifications.go @@ -13,8 +13,8 @@ import ( const maxNotifications = 30 -// All shows all notifications sent so far. -func All(ctx *aero.Context) string { +// ByUser shows all notifications sent to the given user. +func ByUser(ctx *aero.Context) string { user := utils.GetUser(ctx) if user == nil { @@ -44,3 +44,24 @@ func All(ctx *aero.Context) string { return ctx.HTML(components.Notifications(notifications, viewUser, user)) } + +// All shows all notifications. +func All(ctx *aero.Context) string { + notifications, err := arn.AllNotifications() + + if err != nil { + return ctx.Error(http.StatusInternalServerError, "Could not retrieve notification list", err) + } + + // Sort by date + sort.Slice(notifications, func(i, j int) bool { + return notifications[i].Created > notifications[j].Created + }) + + // Limit results + if len(notifications) > maxNotifications { + notifications = notifications[:maxNotifications] + } + + return ctx.HTML(components.AllNotifications(notifications)) +} diff --git a/pages/notifications/notifications.pixy b/pages/notifications/notifications.pixy index 2b907406..c3b1f9a2 100644 --- a/pages/notifications/notifications.pixy +++ b/pages/notifications/notifications.pixy @@ -12,6 +12,17 @@ component Notifications(notifications []*arn.Notification, viewUser *arn.User, u each notification in notifications Notification(notification) +component AllNotifications(notifications []*arn.Notification) + h1 All notifications + + .notifications-container + .notifications + each notification in notifications + Notification(notification) + + .notification-user + a.ajax(href=notification.User().Link())= notification.User().Nick + component Notification(notification *arn.Notification) a.notification(href=notification.Link, target="_blank", data-seen=notification.Seen) .notification-icon @@ -19,6 +30,7 @@ component Notification(notification *arn.Notification) .notification-info h3.notification-title= notification.Title + .notification-footer p.notification-text= notification.Message .notification-date.utc-date(data-date=notification.Created) diff --git a/pages/notifications/notifications.scarlet b/pages/notifications/notifications.scarlet index c5b68bdd..48a00e64 100644 --- a/pages/notifications/notifications.scarlet +++ b/pages/notifications/notifications.scarlet @@ -15,6 +15,11 @@ position relative opacity 0.25 +.notification-user + text-align right + margin-bottom 0.5rem + font-size 0.9rem + .notification[data-seen=""] opacity 1.0