diff --git a/appview/notifications/notifications.go b/appview/notifications/notifications.go index 3cda6baa..6ddc0a94 100644 --- a/appview/notifications/notifications.go +++ b/appview/notifications/notifications.go @@ -38,6 +38,7 @@ func (n *Notifications) Router(mw *middleware.Middleware) http.Handler { r.Group(func(r chi.Router) { r.Use(middleware.AuthMiddleware(n.oauth)) r.With(middleware.Paginate).Get("/", n.notificationsPage) + r.Get("/preview", n.previewHandler) r.Post("/{id}/read", n.markRead) r.Post("/read-all", n.markAllRead) r.Delete("/{id}", n.deleteNotification) @@ -89,6 +90,30 @@ func (n *Notifications) notificationsPage(w http.ResponseWriter, r *http.Request }) } +func (n *Notifications) previewHandler(w http.ResponseWriter, r *http.Request) { + l := n.logger.With("handler", "previewHandler") + user := n.oauth.GetMultiAccountUser(r) + + notifications, err := db.GetNotificationsWithEntities( + n.db, + pagination.Page{Limit: 5, Offset: 0}, + orm.FilterEq("recipient_did", user.Did), + ) + if err != nil { + l.Error("failed to get notifications", "err", err) + n.pages.Error500(w) + return + } + + err = n.pages.NotificationPreview(w, pages.NotificationPreviewParams{ + LoggedInUser: user, + Notifications: notifications, + }) + if err != nil { + l.Error("failed to render notification preview", "err", err) + } +} + func (n *Notifications) getUnreadCount(w http.ResponseWriter, r *http.Request) { user := n.oauth.GetMultiAccountUser(r) if user == nil { diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 47c2da74..35967655 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -473,6 +473,15 @@ func (p *Pages) NotificationCount(w io.Writer, params NotificationCountParams) e return p.executePlain("notifications/fragments/count", w, params) } +type NotificationPreviewParams struct { + LoggedInUser *oauth.MultiAccountUser + Notifications []*models.NotificationWithEntity +} + +func (p *Pages) NotificationPreview(w io.Writer, params NotificationPreviewParams) error { + return p.executePlain("notifications/fragments/preview", w, params) +} + type UserKeysSettingsParams struct { LoggedInUser *oauth.MultiAccountUser PubKeys []models.PublicKey diff --git a/appview/pages/templates/notifications/fragments/bell.html b/appview/pages/templates/notifications/fragments/bell.html index 5cb45d74..a00dd9a8 100644 --- a/appview/pages/templates/notifications/fragments/bell.html +++ b/appview/pages/templates/notifications/fragments/bell.html @@ -1,11 +1,45 @@ {{define "notifications/fragments/bell"}} -