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 @@