panel uzytkownika
This commit is contained in:
@@ -41,6 +41,7 @@ type NotificationsContextValue = {
|
||||
unreadCount: number;
|
||||
markRead: (id: number) => void;
|
||||
markAllRead: () => void;
|
||||
clearAll: () => void;
|
||||
notify: (input: NotifyInput) => void;
|
||||
// Kasuje powiadomienia o kluczu zaczynajacym sie od prefiksu - uzywane przy usuwaniu
|
||||
// alertu cenowego, zeby nie zostal po nim slad.
|
||||
@@ -147,6 +148,15 @@ export function NotificationsProvider({ children }: { children: ReactNode }) {
|
||||
apiFetch('/notifications/read-all', { method: 'POST' }).catch(() => {});
|
||||
}, []);
|
||||
|
||||
// Kasuje wszystkie powiadomienia uzytkownika. Znikaja od razu z widoku, reszte sprzata backend.
|
||||
// Czyscimy tez blokade deduplikacji, inaczej te same zdarzenia nie wygenerowalyby juz
|
||||
// powiadomienia w tej sesji.
|
||||
const clearAll = useCallback(() => {
|
||||
setNotifications([]);
|
||||
sentDedupeKeys.current = new Set();
|
||||
apiFetch('/notifications/all', { method: 'DELETE' }).catch(() => {});
|
||||
}, []);
|
||||
|
||||
const notify = useCallback((input: NotifyInput) => {
|
||||
if (!getToken() || !input.title) {
|
||||
return;
|
||||
@@ -184,7 +194,7 @@ export function NotificationsProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
return (
|
||||
<NotificationsContext.Provider
|
||||
value={{ notifications, unreadCount, markRead, markAllRead, notify, dismissByDedupePrefix, refresh }}
|
||||
value={{ notifications, unreadCount, markRead, markAllRead, clearAll, notify, dismissByDedupePrefix, refresh }}
|
||||
>
|
||||
{children}
|
||||
</NotificationsContext.Provider>
|
||||
|
||||
Reference in New Issue
Block a user