Use one controller for all notification readings
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
class Notifications::MarkAllReadsController < ApplicationController
|
||||
def create
|
||||
Current.user.notifications.unread.read_all
|
||||
|
||||
set_page_and_extract_portion_from Current.user.notifications.read.ordered if request.format.turbo_stream?
|
||||
|
||||
Turbo::StreamsChannel.broadcast_update_to(
|
||||
[ Current.user, :notifications ],
|
||||
target: "notifications",
|
||||
html: ""
|
||||
)
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream
|
||||
format.html
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
class Notifications::ReadingsController < ApplicationController
|
||||
def create
|
||||
@notification = Current.user.notifications.find(params[:id])
|
||||
@notification.update!(read_at: Time.current)
|
||||
end
|
||||
|
||||
def create_all
|
||||
Current.user.notifications.unread.read_all
|
||||
|
||||
set_page_and_extract_portion_from Current.user.notifications.read.ordered if request.format.turbo_stream?
|
||||
|
||||
Turbo::StreamsChannel.broadcast_update_to [ Current.user, :notifications ], target: "notifications", html: ""
|
||||
end
|
||||
end
|
||||
@@ -6,14 +6,4 @@ class NotificationsController < ApplicationController
|
||||
@unread = Current.user.notifications.unread.ordered
|
||||
end
|
||||
end
|
||||
|
||||
def mark_read
|
||||
@notification = Current.user.notifications.find(params[:id])
|
||||
@notification.update!(read_at: Time.current)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_back fallback_location: notifications_path }
|
||||
format.turbo_stream
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user