Update inbox/notification counters when paginating

This commit is contained in:
Karina Kwiatek 2023-06-16 18:07:53 +02:00
parent 2c3e156dca
commit a6f526b9c4
5 changed files with 28 additions and 10 deletions

View File

@ -1,3 +1,5 @@
- inbox_count = current_user.unread_inbox_count
= turbo_stream.append "entries" do = turbo_stream.append "entries" do
- @inbox.each do |i| - @inbox.each do |i|
= render "inbox/entry", i: = render "inbox/entry", i:
@ -10,3 +12,13 @@
params: { last_id: @inbox_last_id, author: @author }.compact, params: { last_id: @inbox_last_id, author: @author }.compact,
data: { controller: :hotkey, hotkey: "." }, data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } } form: { data: { turbo_stream: true } }
= turbo_stream.update "nav-inbox-desktop" do
= nav_entry t("navigation.inbox"), "/inbox",
badge: inbox_count, badge_attr: { data: { controller: "pwa-badge" } },
icon: "inbox", hotkey: "g i"
= turbo_stream.update "nav-inbox-mobile" do
= nav_entry t("navigation.inbox"), "/inbox",
badge: inbox_count, badge_color: "primary", badge_pill: true,
icon: "inbox", icon_only: true

View File

@ -10,7 +10,8 @@
DEV DEV
%ul.nav.navbar-nav.me-auto %ul.nav.navbar-nav.me-auto
= nav_entry t("navigation.timeline"), root_path, icon: "home", hotkey: "g t" = nav_entry t("navigation.timeline"), root_path, icon: "home", hotkey: "g t"
= nav_entry t("navigation.inbox"), "/inbox", icon: "inbox", badge: inbox_count, badge_attr: { data: { controller: "pwa-badge" } }, hotkey: "g i" #nav-inbox-desktop
= nav_entry t("navigation.inbox"), "/inbox", icon: "inbox", badge: inbox_count, badge_attr: { data: { controller: "pwa-badge" } }, hotkey: "g i"
- 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", hotkey: "g d" = nav_entry t("navigation.discover"), discover_path, icon: "compass", hotkey: "g d"
%ul.nav.navbar-nav %ul.nav.navbar-nav
@ -23,12 +24,7 @@
%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 } }
%turbo-frame#notification-desktop-icon %turbo-frame#notification-desktop-icon
- if notification_count.nil? = render "navigation/icons/notifications", notification_count:
%i.fa.fa-bell-o
- else
%i.fa.fa-bell
%span.visually-hidden= t("navigation.notifications")
%span.badge= notification_count
.dropdown-menu.dropdown-menu-end.notification-dropdown .dropdown-menu.dropdown-menu-end.notification-dropdown
%turbo-frame#notifications-dropdown-list %turbo-frame#notifications-dropdown-list
- cache current_user.notification_dropdown_cache_key do - cache current_user.notification_dropdown_cache_key do

View File

@ -3,9 +3,10 @@
.container .container
%ul.nav.navbar-nav.navbar-icon-row %ul.nav.navbar-nav.navbar-icon-row
= nav_entry t("navigation.timeline"), root_path, icon: 'home', icon_only: true = nav_entry t("navigation.timeline"), root_path, icon: 'home', icon_only: true
= nav_entry t("navigation.inbox"), '/inbox', #nav-inbox-mobile
badge: inbox_count, badge_color: 'primary', badge_pill: true, = nav_entry t("navigation.inbox"), '/inbox',
icon: 'inbox', icon_only: true badge: inbox_count, badge_color: 'primary', badge_pill: true,
icon: 'inbox', icon_only: true
- 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,

View File

@ -0,0 +1,6 @@
- if notification_count.nil?
%i.fa.fa-bell-o
- else
%i.fa.fa-bell
%span.visually-hidden= t("navigation.notifications")
%span.badge= notification_count

View File

@ -13,3 +13,6 @@
params: { last_id: @notifications_last_id }, params: { last_id: @notifications_last_id },
data: { controller: :hotkey, hotkey: "." }, data: { controller: :hotkey, hotkey: "." },
form: { data: { turbo_stream: true } } form: { data: { turbo_stream: true } }
= turbo_stream.update "notification-desktop-icon" do
= render "navigation/icons/notifications", notification_count: current_user.unread_notification_count