[WEB-2382]chore: notifications code improvement (#6172)
* chore: adjusted increment/decrement for unread count * chore: improved param handling for unread notification count function
This commit is contained in:
parent
547c138084
commit
d04619477b
2 changed files with 12 additions and 7 deletions
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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<TUnreadNotificationsCount | undefined>;
|
||||
getNotifications: (
|
||||
workspaceSlug: string,
|
||||
|
|
@ -285,16 +285,22 @@ export class WorkspaceNotificationStore implements IWorkspaceNotificationStore {
|
|||
* @param { "increment" | "decrement" } type
|
||||
* @returns { void }
|
||||
*/
|
||||
setUnreadNotificationsCount = (type: "increment" | "decrement"): 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 + 1 : count - 1
|
||||
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 + 1 : count - 1
|
||||
update(
|
||||
this.unreadNotificationsCount,
|
||||
"mention_unread_notifications_count",
|
||||
(count: number) => +Math.max(0, type === "increment" ? count + validCount : count - validCount)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue