Add functionality for marking all notifications as read
This commit is contained in:
parent
2ec52210f4
commit
c9c458252b
|
@ -25,6 +25,16 @@ class NotificationsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def read
|
||||||
|
current_user.notifications.where(new: true).update_all(new: false)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.turbo_stream do
|
||||||
|
render "navigation/notifications", locals: { notifications: [], notification_count: nil }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def paginate_notifications
|
def paginate_notifications
|
||||||
|
|
|
@ -19,16 +19,19 @@
|
||||||
%a.nav-link{ href: '#', data: { bs_target: '#modal-list-memberships', bs_toggle: :modal } }
|
%a.nav-link{ href: '#', data: { bs_target: '#modal-list-memberships', bs_toggle: :modal } }
|
||||||
%i.fa.fa-list.hidden-xs
|
%i.fa.fa-list.hidden-xs
|
||||||
%span.d-none.d-sm-inline.d-md-none= t(".list")
|
%span.d-none.d-sm-inline.d-md-none= t(".list")
|
||||||
= nav_entry t("navigation.notifications"), notifications_path, badge: notification_count, class: "d-block d-sm-none", hotkey: "g n"
|
= nav_entry t("navigation.notifications"), notifications_path, class: "d-block d-sm-none", hotkey: "g n"
|
||||||
%li.nav-item.dropdown.d-none.d-sm-block
|
%li.nav-item.dropdown.d-none.d-sm-block
|
||||||
%a.nav-link.dropdown-toggle{ href: '#', data: { bs_toggle: :dropdown } }
|
%a.nav-link.dropdown-toggle{ href: '#', data: { bs_toggle: :dropdown } }
|
||||||
- if notification_count.nil?
|
%turbo-frame#notification-desktop-icon
|
||||||
%i.fa.fa-bell-o
|
- if notification_count.nil?
|
||||||
- else
|
%i.fa.fa-bell-o
|
||||||
%i.fa.fa-bell
|
- else
|
||||||
%span.visually-hidden= t("navigation.notifications")
|
%i.fa.fa-bell
|
||||||
%span.badge= notification_count
|
%span.visually-hidden= t("navigation.notifications")
|
||||||
= render 'navigation/dropdown/notifications', notifications: notifications, size: "desktop"
|
%span.badge= notification_count
|
||||||
|
.dropdown-menu.dropdown-menu-end.notification-dropdown
|
||||||
|
%turbo-frame#notifications-dropdown-list
|
||||||
|
= render 'navigation/dropdown/notifications', notifications:, notification_count: nil
|
||||||
%li.nav-item.d-none.d-sm-block{ data: { bs_toggle: 'tooltip', bs_placement: 'bottom' }, title: t('.ask_question') }
|
%li.nav-item.d-none.d-sm-block{ data: { bs_toggle: 'tooltip', bs_placement: 'bottom' }, title: t('.ask_question') }
|
||||||
%a.nav-link{ href: "#", name: "toggle-all-ask", data: { bs_target: "#modal-ask-followers", bs_toggle: :modal, hotkey: "n" } }
|
%a.nav-link{ href: "#", name: "toggle-all-ask", data: { bs_target: "#modal-ask-followers", bs_toggle: :modal, hotkey: "n" } }
|
||||||
%i.fa.fa-pencil-square-o
|
%i.fa.fa-pencil-square-o
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
- if APP_CONFIG.dig(:features, :discover, :enabled) || current_user.mod?
|
- if APP_CONFIG.dig(:features, :discover, :enabled) || current_user.mod?
|
||||||
= nav_entry t("navigation.discover"), discover_path, icon: 'compass', icon_only: true
|
= nav_entry t("navigation.discover"), discover_path, icon: 'compass', icon_only: true
|
||||||
= nav_entry t("navigation.notifications"), notifications_path("all"), icon: notifications_icon,
|
= nav_entry t("navigation.notifications"), notifications_path("all"), icon: notifications_icon,
|
||||||
badge: notification_count, badge_color: "primary", icon_only: true
|
badge: notification_count, badge_color: "primary", badge_attr: { id: "notification-mobile-count" }, icon_only: true
|
||||||
%li.nav-item.profile--image-dropdown
|
%li.nav-item.profile--image-dropdown
|
||||||
%a.nav-link{ href: '#', data: { bs_toggle: 'dropdown', bs_target: '#rs-mobile-nav-profile' }, aria: { controls: 'rs-mobile-nav-profile', expanded: 'false' } }
|
%a.nav-link{ href: '#', data: { bs_toggle: 'dropdown', bs_target: '#rs-mobile-nav-profile' }, aria: { controls: 'rs-mobile-nav-profile', expanded: 'false' } }
|
||||||
%img.avatar-md.d-inline{ src: current_user.profile_picture.url(:small) }
|
%img.avatar-md.d-inline{ src: current_user.profile_picture.url(:small) }
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
%a.dropdown-item.text-center{ href: notifications_path }
|
%a.dropdown-item.text-center{ href: notifications_path }
|
||||||
%i.fa.fa-fw.fa-chevron-right
|
%i.fa.fa-fw.fa-chevron-right
|
||||||
= t(".new")
|
= t(".new")
|
||||||
|
= link_to notifications_read_path, class: "dropdown-item text-center", data: { turbo_stream: true, turbo_method: :post } do
|
||||||
|
%i.fa.fa-fw.fa-check-double
|
||||||
|
= t(".mark_as_read")
|
||||||
- notifications.each do |notification|
|
- notifications.each do |notification|
|
||||||
.dropdown-item
|
.dropdown-item
|
||||||
= render "notifications/type/#{notification.target.class.name.downcase.split('::').last}", notification: notification
|
= render "notifications/type/#{notification.target.class.name.downcase.split('::').last}", notification: notification
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
= turbo_stream.update "notifications-dropdown-list" do
|
||||||
|
= render "navigation/dropdown/notifications", notifications:
|
||||||
|
|
||||||
|
= turbo_stream.update "notification-desktop-icon" do
|
||||||
|
- if notification_count.nil?
|
||||||
|
%i.fa.fa-bell-o
|
||||||
|
- else
|
||||||
|
%i.fa.fa-bell
|
||||||
|
%span.visually-hidden= t("navigation.notifications")
|
||||||
|
%span.badge= notification_count
|
||||||
|
|
||||||
|
= turbo_stream.update "notification-mobile-count" do
|
||||||
|
%span.badge.badge-primary= notification_count
|
|
@ -318,6 +318,7 @@ en:
|
||||||
none: :notifications.index.none
|
none: :notifications.index.none
|
||||||
all: "Show all notifications"
|
all: "Show all notifications"
|
||||||
new: "Show all new notifications"
|
new: "Show all new notifications"
|
||||||
|
mark_as_read: "Mark all as read"
|
||||||
profile:
|
profile:
|
||||||
profile: "Show profile"
|
profile: "Show profile"
|
||||||
settings: "Settings"
|
settings: "Settings"
|
||||||
|
|
|
@ -143,6 +143,7 @@ Rails.application.routes.draw do
|
||||||
get "/list/:list_name", to: "timeline#list", as: :list_timeline
|
get "/list/:list_name", to: "timeline#list", as: :list_timeline
|
||||||
|
|
||||||
get "/notifications(/:type)", to: "notifications#index", as: :notifications, defaults: { type: "new" }
|
get "/notifications(/:type)", to: "notifications#index", as: :notifications, defaults: { type: "new" }
|
||||||
|
post "/notifications", to: "notifications#read", as: :notifications_read
|
||||||
|
|
||||||
post "/inbox/create", to: "inbox#create", as: :inbox_create
|
post "/inbox/create", to: "inbox#create", as: :inbox_create
|
||||||
get "/inbox", to: "inbox#show", as: :inbox
|
get "/inbox", to: "inbox#show", as: :inbox
|
||||||
|
|
Loading…
Reference in New Issue