diff --git a/app/assets/stylesheets/notifications.css b/app/assets/stylesheets/notifications.css new file mode 100644 index 000000000..164330528 --- /dev/null +++ b/app/assets/stylesheets/notifications.css @@ -0,0 +1,15 @@ +.notification-tray { + position: fixed; + width: 40ch; + bottom: 1rem; + left: calc(50% - 20ch); + display: flex; + flex-direction: column; + gap: 1rem; +} + +.notification { + background-color: #eeed; + border-radius: 6px; + padding: 0.5rem; +} diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb new file mode 100644 index 000000000..22e40167e --- /dev/null +++ b/app/controllers/notifications_controller.rb @@ -0,0 +1,5 @@ +class NotificationsController < ApplicationController + def index + @notifications = Current.user.notifications.unread.ordered.limit(20) + end +end diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb new file mode 100644 index 000000000..b7fe8de4d --- /dev/null +++ b/app/helpers/notifications_helper.rb @@ -0,0 +1,7 @@ +module NotificationsHelper + def notification_tray_tag + tag.div class: "notification-tray" do + turbo_frame_tag "notifications", src: notifications_path, data: { turbo_permanent: true } + end + end +end diff --git a/app/models/notification.rb b/app/models/notification.rb index 56d2b8ffd..5553dfad9 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -2,6 +2,6 @@ class Notification < ApplicationRecord belongs_to :user belongs_to :bubble - scope :unread, -> { where.not(:read) } - scope :ordered, -> { order(created_at: :desc) } + scope :unread, -> { where(read: false) } + scope :ordered, -> { order(read: :desc, created_at: :desc) } end diff --git a/app/views/bubbles/index.html.erb b/app/views/bubbles/index.html.erb index bc43bf2ab..7928afacf 100644 --- a/app/views/bubbles/index.html.erb +++ b/app/views/bubbles/index.html.erb @@ -50,3 +50,5 @@ <%= render partial: "bubbles/list/bubble", collection: @bubbles, cached: true %> + +<%= notification_tray_tag %> diff --git a/app/views/notifications/_notification.html.erb b/app/views/notifications/_notification.html.erb new file mode 100644 index 000000000..c87ac7166 --- /dev/null +++ b/app/views/notifications/_notification.html.erb @@ -0,0 +1,3 @@ +
<%= notification.body %>
+