Mark notification read when viewing the Bubble

This commit is contained in:
Kevin McConnell
2025-01-13 12:31:31 +00:00
parent 271ac063f9
commit 46989f6ebe
14 changed files with 35 additions and 44 deletions
@@ -1,5 +0,0 @@
class Notifications::ReadingsController < ApplicationController
def create
Current.user.notifications.find(params[:notification_id]).update!(read: true)
end
end
+8
View File
@@ -0,0 +1,8 @@
class ReadingsController < ApplicationController
include BubbleScoped, BucketScoped
def create
@notifications = Current.user.notifications.where(bubble: @bubble)
@notifications.update(read: true)
end
end
+1 -5
View File
@@ -1,10 +1,6 @@
module NotificationsHelper
def notification_tag(notification, &)
link_to notification.resource, id: dom_id(notification), class: "notification",
data: {
turbo_frame: "_top",
action: "turbo:click->notifications--readings#record",
notifications__readings_url_param: notification_readings_url(notification)
}, &
data: { turbo_frame: "_top", }, &
end
end
@@ -1,18 +0,0 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
record({ target, params: { url } }) {
navigator.sendBeacon(url, this.#csrfPayload())
target.remove()
}
#csrfPayload() {
const data = new FormData()
data.append("authenticity_token", this.#csrfToken())
return data
}
#csrfToken() {
return document.querySelector('meta[name="csrf-token"]').content
}
}
@@ -0,0 +1,10 @@
import { post } from "@rails/request.js"
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static values = { url: String }
connect() {
post(this.urlValue, { responseKind: "turbo-stream" })
}
}
+3 -1
View File
@@ -2,7 +2,9 @@
<div class="bubble"
style="view-transition-name: bubble-<%= bubble.id -%>; --bubble-color: <%= bubble.color %>; <%= bubble_rotation(bubble) %> <%= bubble_size(bubble) %>"
data-controller="animation upload-preview"
data-animation-play-class="bubble--wobble" data-animation-play-on-load-value="true" data-action="mouseover->animation#play">
data-animation-play-class="bubble--wobble"
data-animation-play-on-load-value="true"
data-action="mouseover->animation#play">
<div>
<h1 class="bubble__title">
+1 -1
View File
@@ -65,7 +65,7 @@
</div>
</aside>
<div class="bubble__container">
<div class="bubble__container" data-controller="readings" data-readings-url-value="<%= bucket_bubble_readings_url(@bubble.bucket, @bubble) %>">
<div class="bubble__perma flex justify-center center margin-block-end-double">
<%= render "bubbles/bubble", bubble: @bubble, editing: params[:editing] %>
</div>
+1 -1
View File
@@ -1,5 +1,5 @@
<%= turbo_stream_from Current.user, :notifications %>
<%= tag.div id: "notification-tray", class: "notification-tray", data: { turbo_permanent: true, controller: "notifications--readings" } do %>
<%= tag.div id: "notification-tray", class: "notification-tray", data: { turbo_permanent: true } do %>
<%= turbo_frame_tag("notifications", src: notifications_path) %>
<% end %>
@@ -0,0 +1,3 @@
<% @notifications.each do |notification| %>
<%= turbo_stream.remove notification %>
<% end %>
+1
View File
@@ -4,6 +4,7 @@ pin "application"
pin "@hotwired/turbo-rails", to: "turbo.min.js"
pin "@hotwired/stimulus", to: "stimulus.min.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin "@rails/request.js", to: "@rails--request.js" # @0.0.11
pin "house", to: "house.min.js"
pin_all_from "app/javascript/controllers", under: "controllers"
+2 -5
View File
@@ -18,16 +18,13 @@ Rails.application.routes.draw do
end
resources :bubbles
resources :notifications do
scope module: :notifications do
resource :readings, only: :create
end
end
resources :notifications
resources :buckets do
resources :bubbles do
resources :boosts
resources :comments
resource :readings, only: :create
scope module: :bubbles do
resource :image
@@ -1,7 +0,0 @@
require "test_helper"
class Notifications::ReadingsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
+1 -1
View File
@@ -10,7 +10,7 @@ logo_created_kevin:
layout_created_kevin:
user: kevin
creator: david
bubble: logo
bubble: layout
resource: layout_overflowing_david (Comment)
read: false
body: "re: Layout is broken"
File diff suppressed because one or more lines are too long