Repository navigation
Session Based Chat Notifications - #302
Conversation
✅ Deploy Preview for hope-for-haiti ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Greptile SummaryThis PR adds Key changes:
Area needing improvement:
Confidence Score: 4/5
|
| const dismissNotification = useCallback( | ||
| async (id: string | number) => { | ||
| if (Number(id) > 0) { | ||
| try { | ||
| await apiClient.delete(`/api/notifications/${id}`); | ||
| } catch (error) { | ||
| console.error(`Failed to delete notification ${id}: ${error}`); | ||
| } | ||
| } | ||
| setNotifications((prev) => prev.filter((n) => n.id !== id)); | ||
| }, | ||
| [apiClient] | ||
| ); |
There was a problem hiding this comment.
Missing isChat guard before DELETE call
The dismissNotification callback checks Number(id) > 0 before making the DELETE API call, but this is insufficient for chat notifications.
Chat notification IDs fall back to Date.now() when event.message?.id is undefined (line 269). A timestamp like 1709913600000 evaluates to Number(id) > 0 === true, so the callback fires an unnecessary DELETE /api/notifications/<timestamp> request for a notification that only exists locally (in sessionStorage), not in the database.
Since every notification has an explicit isChat flag, the fix is straightforward — look up the notification from state and preserve the original guard:
const dismissNotification = useCallback(
async (id: string | number) => {
const notification = notifications.find((n) => n.id === id);
if (!notification?.isChat && Number(id) > 0) {
try {
await apiClient.delete(`/api/notifications/${id}`);
} catch (error) {
console.error(`Failed to delete notification ${id}: ${error}`);
}
}
setNotifications((prev) => prev.filter((n) => n.id !== id));
},
[apiClient, notifications]
);a02ec5a to
7c7da36
Compare
|
nice work, thanks for refactoring some of the notification handler functions, the code is really clean |
Description
Resolves ticket number: #291
Explain what your code changes:
Added support for using sessionStorage to persist and mirror chat notifications across refreshes. Also cleaned up logic for dismissing notifications by putting it in
NotificationsHandler.tsx.List the steps you took to test your code:
Triggered chat notifications and navigated across pages.
Checklist