Merge pull request #548 from tabacha/2024-12-15-delete-notifications-on-gui

Feature: Add a "Delete Notifications" button
This commit is contained in:
Evgenii Burmakin 2024-12-16 14:27:29 +01:00 committed by GitHub
commit 41ac715fc5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 2 deletions

View file

@ -15,10 +15,15 @@ class NotificationsController < ApplicationController
def mark_as_read
current_user.notifications.unread.update_all(read_at: Time.zone.now)
redirect_to notifications_url, notice: 'All notifications marked as read.', status: :see_other
end
def destroy_all
current_user.notifications.destroy_all
redirect_to notifications_url, notice: 'All notifications where successfully destroyed.', status: :see_other
end
def destroy
@notification.destroy!
redirect_to notifications_url, notice: 'Notification was successfully destroyed.', status: :see_other

View file

@ -4,7 +4,10 @@
<h1 class="font-bold text-4xl mb-4">Notifications</h1>
<div class="flex items-center justify-center mb-4">
<% if @notifications.unread.any? %>
<%= link_to "Mark all as read", mark_notifications_as_read_path, method: :post, data: { turbo_method: :post }, class: "btn btn-sm btn-primary" %>
<%= link_to "Mark all as read", mark_notifications_as_read_path, method: :post, data: { turbo_method: :post }, class: "btn btn-sm btn-primary" %>&nbsp;
<% end %>
<% if @notifications.any? %>
<%= link_to "Delete all", delete_all_notifications_path, method: :post, data: { turbo_method: :post }, class: "btn btn-sm btn-warning" %>
<% end %>
</div>
<div class="mb-4">

View file

@ -38,6 +38,7 @@ Rails.application.routes.draw do
end
resources :notifications, only: %i[index show destroy]
post 'notifications/mark_as_read', to: 'notifications#mark_as_read', as: :mark_notifications_as_read
post 'notifications/destroy_all', to: 'notifications#destroy_all', as: :delete_all_notifications
resources :stats, only: :index do
collection do
post :update