From c9a8e8fc04928bc4154dab03a1fe5a5d8e9f82f2 Mon Sep 17 00:00:00 2001 From: vamsi krishna Date: Mon, 9 Dec 2024 17:19:21 +0530 Subject: [PATCH 1/2] chore: adjusted increment/decrement for unread count --- .../store/notifications/workspace-notifications.store.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/core/store/notifications/workspace-notifications.store.ts b/web/core/store/notifications/workspace-notifications.store.ts index b3ba8820353..0f12bfcca0f 100644 --- a/web/core/store/notifications/workspace-notifications.store.ts +++ b/web/core/store/notifications/workspace-notifications.store.ts @@ -50,7 +50,7 @@ export interface IWorkspaceNotificationStore { // actions setCurrentNotificationTab: (tab: TNotificationTab) => void; setCurrentSelectedNotificationId: (notificationId: string | undefined) => void; - setUnreadNotificationsCount: (type: "increment" | "decrement") => void; + setUnreadNotificationsCount: (type: "increment" | "decrement", newCount?: number) => void; getUnreadNotificationsCount: (workspaceSlug: string) => Promise; getNotifications: ( workspaceSlug: string, @@ -285,16 +285,16 @@ export class WorkspaceNotificationStore implements IWorkspaceNotificationStore { * @param { "increment" | "decrement" } type * @returns { void } */ - setUnreadNotificationsCount = (type: "increment" | "decrement"): void => { + setUnreadNotificationsCount = (type: "increment" | "decrement", newCount: number = 1): void => { switch (this.currentNotificationTab) { case ENotificationTab.ALL: update(this.unreadNotificationsCount, "total_unread_notifications_count", (count: 0) => - type === "increment" ? count + 1 : count - 1 + type === "increment" ? count + newCount : count - newCount ); break; case ENotificationTab.MENTIONS: update(this.unreadNotificationsCount, "mention_unread_notifications_count", (count: 0) => - type === "increment" ? count + 1 : count - 1 + type === "increment" ? count + newCount : count - newCount ); break; default: From bf57d9e6d63c321924640dbdd75df0aee23a89ec Mon Sep 17 00:00:00 2001 From: vamsi krishna Date: Mon, 9 Dec 2024 17:54:24 +0530 Subject: [PATCH 2/2] chore: improved param handling for unread notification count function --- .../notification-card/options/snooze/modal.tsx | 1 - .../notifications/workspace-notifications.store.ts | 14 ++++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/web/core/components/workspace-notifications/sidebar/notification-card/options/snooze/modal.tsx b/web/core/components/workspace-notifications/sidebar/notification-card/options/snooze/modal.tsx index 36302aa5f0c..e7bed668816 100644 --- a/web/core/components/workspace-notifications/sidebar/notification-card/options/snooze/modal.tsx +++ b/web/core/components/workspace-notifications/sidebar/notification-card/options/snooze/modal.tsx @@ -5,7 +5,6 @@ import { useParams } from "next/navigation"; import { useForm, Controller } from "react-hook-form"; import { X } from "lucide-react"; import { Transition, Dialog } from "@headlessui/react"; -import { TNotification } from "@plane/types"; import { Button, CustomSelect } from "@plane/ui"; // components import { DateDropdown } from "@/components/dropdowns"; diff --git a/web/core/store/notifications/workspace-notifications.store.ts b/web/core/store/notifications/workspace-notifications.store.ts index 0f12bfcca0f..a0de7bc0f60 100644 --- a/web/core/store/notifications/workspace-notifications.store.ts +++ b/web/core/store/notifications/workspace-notifications.store.ts @@ -286,15 +286,21 @@ export class WorkspaceNotificationStore implements IWorkspaceNotificationStore { * @returns { void } */ setUnreadNotificationsCount = (type: "increment" | "decrement", newCount: number = 1): void => { + const validCount = Math.max(0, Math.abs(newCount)); + switch (this.currentNotificationTab) { case ENotificationTab.ALL: - update(this.unreadNotificationsCount, "total_unread_notifications_count", (count: 0) => - type === "increment" ? count + newCount : count - newCount + update( + this.unreadNotificationsCount, + "total_unread_notifications_count", + (count: number) => +Math.max(0, type === "increment" ? count + validCount : count - validCount) ); break; case ENotificationTab.MENTIONS: - update(this.unreadNotificationsCount, "mention_unread_notifications_count", (count: 0) => - type === "increment" ? count + newCount : count - newCount + update( + this.unreadNotificationsCount, + "mention_unread_notifications_count", + (count: number) => +Math.max(0, type === "increment" ? count + validCount : count - validCount) ); break; default: