WIP: show notifications in a tray

This commit is contained in:
Kevin McConnell
2025-01-09 18:25:35 +00:00
parent 6b5e098407
commit 952895ae67
9 changed files with 45 additions and 2 deletions
+15
View File
@@ -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;
}
@@ -0,0 +1,5 @@
class NotificationsController < ApplicationController
def index
@notifications = Current.user.notifications.unread.ordered.limit(20)
end
end
+7
View File
@@ -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
+2 -2
View File
@@ -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
+2
View File
@@ -50,3 +50,5 @@
<%= render partial: "bubbles/list/bubble", collection: @bubbles, cached: true %>
</ul>
</section>
<%= notification_tray_tag %>
@@ -0,0 +1,3 @@
<div class="notification">
<p><%= notification.body %></p>
</div>
+3
View File
@@ -0,0 +1,3 @@
<%= turbo_frame_tag "notifications" do %>
<%= render @notifications %>
<% end %>
+1
View File
@@ -13,6 +13,7 @@ Rails.application.routes.draw do
end
resources :bubbles
resources :notifications
resources :buckets do
resources :bubbles do
@@ -0,0 +1,7 @@
require "test_helper"
class NotificationsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end