-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[WEB-2555] fix: add "mark all as read" in the notifications header #5770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,13 +1,14 @@ | ||||||||||||||||||||||||||||||||||||||
| import { FC } from "react"; | ||||||||||||||||||||||||||||||||||||||
| import { observer } from "mobx-react"; | ||||||||||||||||||||||||||||||||||||||
| import { RefreshCw } from "lucide-react"; | ||||||||||||||||||||||||||||||||||||||
| import { Tooltip } from "@plane/ui"; | ||||||||||||||||||||||||||||||||||||||
| import { CheckCheck, RefreshCw } from "lucide-react"; | ||||||||||||||||||||||||||||||||||||||
| import { Spinner, Tooltip } from "@plane/ui"; | ||||||||||||||||||||||||||||||||||||||
| // components | ||||||||||||||||||||||||||||||||||||||
| import { NotificationFilter, NotificationHeaderMenuOption } from "@/components/workspace-notifications"; | ||||||||||||||||||||||||||||||||||||||
| // constants | ||||||||||||||||||||||||||||||||||||||
| import { NOTIFICATIONS_READ } from "@/constants/event-tracker"; | ||||||||||||||||||||||||||||||||||||||
| import { ENotificationLoader, ENotificationQueryParamType } from "@/constants/notification"; | ||||||||||||||||||||||||||||||||||||||
| // hooks | ||||||||||||||||||||||||||||||||||||||
| import { useWorkspaceNotifications } from "@/hooks/store"; | ||||||||||||||||||||||||||||||||||||||
| import { useEventTracker, useWorkspaceNotifications } from "@/hooks/store"; | ||||||||||||||||||||||||||||||||||||||
| import { usePlatformOS } from "@/hooks/use-platform-os"; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| type TNotificationSidebarHeaderOptions = { | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -18,7 +19,8 @@ export const NotificationSidebarHeaderOptions: FC<TNotificationSidebarHeaderOpti | |||||||||||||||||||||||||||||||||||||
| const { workspaceSlug } = props; | ||||||||||||||||||||||||||||||||||||||
| // hooks | ||||||||||||||||||||||||||||||||||||||
| const { isMobile } = usePlatformOS(); | ||||||||||||||||||||||||||||||||||||||
| const { loader, getNotifications } = useWorkspaceNotifications(); | ||||||||||||||||||||||||||||||||||||||
| const { loader, getNotifications, markAllNotificationsAsRead } = useWorkspaceNotifications(); | ||||||||||||||||||||||||||||||||||||||
| const { captureEvent } = useEventTracker(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const refreshNotifications = async () => { | ||||||||||||||||||||||||||||||||||||||
| if (loader) return; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -29,8 +31,35 @@ export const NotificationSidebarHeaderOptions: FC<TNotificationSidebarHeaderOpti | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const handleMarkAllNotificationsAsRead = async () => { | ||||||||||||||||||||||||||||||||||||||
| // NOTE: We are using loader to prevent continues request when we are making all the notification to read | ||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the typo and improve the clarity of the comment. The comment contains grammatical errors that might lead to confusion. Apply this fix: -// NOTE: We are using loader to prevent continues request when we are making all the notification to read
+// NOTE: We are using loader to prevent continuous requests when marking all notifications as read📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| if (loader) return; | ||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| await markAllNotificationsAsRead(workspaceSlug); | ||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||
| console.error(error); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+38
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance error handling by notifying the user upon failure. In the catch block, errors are logged to the console, but the user remains uninformed. Providing user feedback improves the user experience. Consider adding a user notification: } catch (error) {
console.error(error);
+ // Optionally, display an error message to the user
+ // showToast("Failed to mark all notifications as read.", "error");
}
|
||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+36
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Ensure the loader state correctly prevents concurrent requests. Currently, you're checking Update the condition as follows: -if (loader) return;
+if (loader === ENotificationLoader.MARK_ALL_AS_READY) return;This ensures that only the relevant loader state prevents concurrent requests for this action.
Comment on lines
+34
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refine loader state check for better concurrency control. The current loader check might prevent the action if any loader is active. Consider checking for the specific loader state related to marking notifications as read. Update the condition as follows: -if (loader) return;
+if (loader === ENotificationLoader.MARK_ALL_AS_READY) return;This ensures that only the relevant loader state prevents concurrent requests for this action. 📝 Committable suggestion
Suggested change
🛠️ Refactor suggestion Enhance error handling with user feedback. Currently, errors are only logged to the console. Consider providing feedback to the user when an error occurs. Add user notification in the catch block: } catch (error) {
console.error(error);
+ // TODO: Implement a user-facing error notification
+ // For example: showToast("Failed to mark all notifications as read. Please try again.", "error");
}This improvement will enhance the user experience by keeping them informed of any issues.
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||
| <div className="relative flex justify-center items-center gap-2 text-sm"> | ||||||||||||||||||||||||||||||||||||||
| {/* mark all notifications as read*/} | ||||||||||||||||||||||||||||||||||||||
| <Tooltip tooltipContent="Mark all as read" isMobile={isMobile} position="bottom"> | ||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||
| className="flex-shrink-0 w-5 h-5 flex justify-center items-center overflow-hidden cursor-pointer transition-all hover:bg-custom-background-80 rounded-sm" | ||||||||||||||||||||||||||||||||||||||
| onClick={() => { | ||||||||||||||||||||||||||||||||||||||
| captureEvent(NOTIFICATIONS_READ); | ||||||||||||||||||||||||||||||||||||||
| handleMarkAllNotificationsAsRead(); | ||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||
| {loader === ENotificationLoader.MARK_ALL_AS_READY ? ( | ||||||||||||||||||||||||||||||||||||||
| <Spinner height="14px" width="14px" /> | ||||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||||
| <CheckCheck className="h-3 w-3" /> | ||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||
| </Tooltip> | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| {/* refetch current notifications */} | ||||||||||||||||||||||||||||||||||||||
| <Tooltip tooltipContent="Refresh" isMobile={isMobile} position="bottom"> | ||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -45,7 +74,7 @@ export const NotificationSidebarHeaderOptions: FC<TNotificationSidebarHeaderOpti | |||||||||||||||||||||||||||||||||||||
| <NotificationFilter /> | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| {/* notification menu options */} | ||||||||||||||||||||||||||||||||||||||
| <NotificationHeaderMenuOption workspaceSlug={workspaceSlug} /> | ||||||||||||||||||||||||||||||||||||||
| <NotificationHeaderMenuOption /> | ||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Refactor to prevent multiple calls to
useWorkspaceNotifications.You are invoking
useWorkspaceNotifications()twice to destructure different values. This can be optimized by combining them into a single call to enhance performance and readability.Apply the following change:
const { isMobile } = usePlatformOS(); -const { loader, getNotifications } = useWorkspaceNotifications(); +const { loader, getNotifications, markAllNotificationsAsRead } = useWorkspaceNotifications(); const { captureEvent } = useEventTracker(); -const { markAllNotificationsAsRead } = useWorkspaceNotifications();Also applies to: 23-24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense, can you fix this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gakshita, sure, I've applied the refactoring to combine the calls to
useWorkspaceNotifications()into a single call. Here's the updated code:This change enhances performance and readability by reducing unnecessary calls to the hook.
(^‿^)