From c71366acc57dd86371135d831903e4b3881c7d52 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 14 Oct 2024 10:20:43 +0200 Subject: [PATCH] Update notifications flyout [SCI-10735] --- .../stylesheets/navigation/notifications.scss | 2 +- .../user_notifications_controller.rb | 25 ++++++-- .../notifications/notification_item.vue | 50 +++++++++++----- .../notifications/notifications_flyout.vue | 59 ++++++++++++++++++- app/javascript/vue/navigation/top_menu.vue | 12 ++-- app/serializers/notification_serializer.rb | 5 +- app/views/shared/navigation/_top.html.erb | 1 + config/locales/en.yml | 3 + config/routes.rb | 4 ++ 9 files changed, 132 insertions(+), 29 deletions(-) diff --git a/app/assets/stylesheets/navigation/notifications.scss b/app/assets/stylesheets/navigation/notifications.scss index 688a94995..c7049d6ef 100644 --- a/app/assets/stylesheets/navigation/notifications.scss +++ b/app/assets/stylesheets/navigation/notifications.scss @@ -30,7 +30,7 @@ flex-direction: column; height: calc(100vh - 8rem); padding: 1.5rem; - width: 400px; + width: 600px; .sci--navigation--notificaitons-flyout-title { @include font-h2; diff --git a/app/controllers/user_notifications_controller.rb b/app/controllers/user_notifications_controller.rb index ca05c3bbc..0f1ffa0eb 100644 --- a/app/controllers/user_notifications_controller.rb +++ b/app/controllers/user_notifications_controller.rb @@ -5,11 +5,18 @@ class UserNotificationsController < ApplicationController def index page = (params.dig(:page, :number) || 1).to_i - notifications = load_notifications.page(page).per(Constants::INFINITE_SCROLL_LIMIT) + notifications = load_notifications + + case params[:tab] + when 'all' + notifications = notifications.where.not(read_at: nil) + when 'unread' + notifications = notifications.where(read_at: nil) + end + + notifications = notifications.page(page).per(Constants::INFINITE_SCROLL_LIMIT) render json: notifications, each_serializer: NotificationSerializer - - notifications.mark_as_read! end def unseen_counter @@ -18,6 +25,17 @@ class UserNotificationsController < ApplicationController } end + def mark_all_read + load_notifications.mark_as_read! + render json: { success: true } + end + + def toggle_read + notification = current_user.notifications.find(params[:id]) + notification.update(read_at: (params[:mark_as_read] ? DateTime.now : nil)) + render json: notification, serializer: NotificationSerializer + end + private def load_notifications @@ -25,5 +43,4 @@ class UserNotificationsController < ApplicationController .in_app .order(created_at: :desc) end - end diff --git a/app/javascript/vue/navigation/notifications/notification_item.vue b/app/javascript/vue/navigation/notifications/notification_item.vue index b187636f1..1b33f05d8 100644 --- a/app/javascript/vue/navigation/notifications/notification_item.vue +++ b/app/javascript/vue/navigation/notifications/notification_item.vue @@ -1,12 +1,20 @@