forked from github/plane
refactor: fetching notification only when popover is open (#1706)
This commit is contained in:
parent
e0affa21c4
commit
35bb71303e
@ -45,6 +45,7 @@ export const NotificationPopover = () => {
|
|||||||
isLoadingMore,
|
isLoadingMore,
|
||||||
hasMore,
|
hasMore,
|
||||||
isRefreshing,
|
isRefreshing,
|
||||||
|
setFetchNotifications,
|
||||||
} = useUserNotification();
|
} = useUserNotification();
|
||||||
|
|
||||||
// theme context
|
// theme context
|
||||||
@ -66,7 +67,10 @@ export const NotificationPopover = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Popover className="relative w-full">
|
<Popover className="relative w-full">
|
||||||
{({ open: isActive, close: closePopover }) => (
|
{({ open: isActive, close: closePopover }) => {
|
||||||
|
if (isActive) setFetchNotifications(true);
|
||||||
|
|
||||||
|
return (
|
||||||
<>
|
<>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
tooltipContent="Notifications"
|
tooltipContent="Notifications"
|
||||||
@ -189,7 +193,8 @@ export const NotificationPopover = () => {
|
|||||||
</Popover.Panel>
|
</Popover.Panel>
|
||||||
</Transition>
|
</Transition>
|
||||||
</>
|
</>
|
||||||
)}
|
);
|
||||||
|
}}
|
||||||
</Popover>
|
</Popover>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -25,6 +25,7 @@ const useUserNotification = () => {
|
|||||||
const [snoozed, setSnoozed] = useState<boolean>(false);
|
const [snoozed, setSnoozed] = useState<boolean>(false);
|
||||||
const [archived, setArchived] = useState<boolean>(false);
|
const [archived, setArchived] = useState<boolean>(false);
|
||||||
const [readNotification, setReadNotification] = useState<boolean>(false);
|
const [readNotification, setReadNotification] = useState<boolean>(false);
|
||||||
|
const [fetchNotifications, setFetchNotifications] = useState<boolean>(false);
|
||||||
const [selectedNotificationForSnooze, setSelectedNotificationForSnooze] = useState<string | null>(
|
const [selectedNotificationForSnooze, setSelectedNotificationForSnooze] = useState<string | null>(
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
@ -49,7 +50,7 @@ const useUserNotification = () => {
|
|||||||
isValidating,
|
isValidating,
|
||||||
mutate: notificationMutate,
|
mutate: notificationMutate,
|
||||||
} = useSWRInfinite(
|
} = useSWRInfinite(
|
||||||
workspaceSlug
|
fetchNotifications && workspaceSlug
|
||||||
? (index, prevData) =>
|
? (index, prevData) =>
|
||||||
getPaginatedNotificationKey(index, prevData, workspaceSlug.toString(), params)
|
getPaginatedNotificationKey(index, prevData, workspaceSlug.toString(), params)
|
||||||
: () => null,
|
: () => null,
|
||||||
@ -282,6 +283,7 @@ const useUserNotification = () => {
|
|||||||
isLoadingMore,
|
isLoadingMore,
|
||||||
hasMore,
|
hasMore,
|
||||||
isRefreshing,
|
isRefreshing,
|
||||||
|
setFetchNotifications,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user