diff --git a/pages/index.go b/pages/index.go index c0daf691..80a041f4 100644 --- a/pages/index.go +++ b/pages/index.go @@ -42,9 +42,9 @@ import ( "github.com/animenotifier/notify.moe/pages/popular" "github.com/animenotifier/notify.moe/pages/posts" "github.com/animenotifier/notify.moe/pages/profile" - "github.com/animenotifier/notify.moe/pages/recommended" "github.com/animenotifier/notify.moe/pages/quote" "github.com/animenotifier/notify.moe/pages/quotes" + "github.com/animenotifier/notify.moe/pages/recommended" "github.com/animenotifier/notify.moe/pages/search" "github.com/animenotifier/notify.moe/pages/settings" "github.com/animenotifier/notify.moe/pages/shop" @@ -143,6 +143,9 @@ func Configure(app *aero.Application) { l.Page("/group/:id/edit", group.Edit) l.Page("/group/:id/forum", group.Forum) + // Notifications + l.Page("/notifications", notifications.All) + // User profiles l.Page("/user", user.Get) l.Page("/user/:nick", profile.Get) diff --git a/pages/notifications/notifications.go b/pages/notifications/notifications.go index 82d57e96..0845f297 100644 --- a/pages/notifications/notifications.go +++ b/pages/notifications/notifications.go @@ -2,13 +2,33 @@ package notifications import ( "net/http" + "sort" "github.com/aerogo/aero" "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/utils" ) -// Test ... +// All shows all notifications sent so far. +func All(ctx *aero.Context) string { + user := utils.GetUser(ctx) + + if user == nil { + return ctx.Error(http.StatusBadRequest, "Not logged in", nil) + } + + notifications := user.Notifications().Notifications() + + // Sort by date + sort.Slice(notifications, func(i, j int) bool { + return notifications[i].Created > notifications[j].Created + }) + + return ctx.HTML(components.Notifications(notifications, user)) +} + +// Test sends a test notification to the logged in user. func Test(ctx *aero.Context) string { user := utils.GetUser(ctx) diff --git a/pages/notifications/notifications.pixy b/pages/notifications/notifications.pixy new file mode 100644 index 00000000..9277c884 --- /dev/null +++ b/pages/notifications/notifications.pixy @@ -0,0 +1,16 @@ +component Notifications(notifications []*arn.Notification, user *arn.User) + h1 Notifications + + .notifications + each notification in notifications + Notification(notification) + +component Notification(notification *arn.Notification) + .notification + .notification-icon + img.lazy(data-src=notification.Icon, alt=notification.Title) + + .notification-info + h3= notification.Title + p= notification.Message + .notification-date.utc-date(data-date=notification.Created) \ No newline at end of file diff --git a/pages/notifications/notifications.scarlet b/pages/notifications/notifications.scarlet new file mode 100644 index 00000000..2155daea --- /dev/null +++ b/pages/notifications/notifications.scarlet @@ -0,0 +1,22 @@ +.notifications + vertical + +.notification + horizontal + ui-element + padding 1rem + margin-bottom 0.5rem + +.notification-icon + margin-right 1rem + + img + width 64px + height 64px + +.notification-info + vertical + +.notification-date + opacity 0.5 + font-size 0.9em \ No newline at end of file