Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-12 12:39:47 +08:00
parent 71f758fe0b
commit fa92d924f4
50 changed files with 2202 additions and 2623 deletions
+10 -9
View File
@@ -17,7 +17,8 @@ const DEFAULT_PAGINATION = { page: 1, limit: 10, pages: 1, total: 0 };
export function ClientNotificationProvider({ children }) {
const [notifications, setNotifications] = useState([]);
const [unseenCount, setUnseenCount] = useState(0);
const [stickyAnnouncement, setStickyAnnouncement] = useState(null);
const [stickyAnnouncements, setStickyAnnouncements] = useState([]);
const [bannerImage, setBannerImage] = useState(null);
const [loading, setLoading] = useState(false);
const [pagination, setPagination] = useState(DEFAULT_PAGINATION);
const intervalRef = useRef(null);
@@ -35,7 +36,8 @@ export function ClientNotificationProvider({ children }) {
const fetchStickyAnnouncement = useCallback(async () => {
try {
const res = await api.get("/client/notifications/sticky");
setStickyAnnouncement(res.data?.data?.announcement ?? null);
setStickyAnnouncements(res.data?.data?.announcements ?? []);
setBannerImage(res.data?.data?.bannerImage ?? null);
} catch {
// silent
}
@@ -66,7 +68,7 @@ export function ClientNotificationProvider({ children }) {
setNotifications([]);
setUnseenCount(0);
setPagination(DEFAULT_PAGINATION);
setStickyAnnouncement(null);
setStickyAnnouncements([]);
return true;
} catch {
return false;
@@ -80,9 +82,7 @@ export function ClientNotificationProvider({ children }) {
prev.map(n => n.notification_id === id ? { ...n, seen: true } : n)
);
if (stickyAnnouncement?.notification_id === id) {
setStickyAnnouncement(null);
}
setStickyAnnouncements(prev => prev.filter(a => a.notification_id !== id));
// Re-sync badge + sticky immediately (handles cases where the marked
// row isn't present in the currently loaded notifications page).
@@ -90,14 +90,14 @@ export function ClientNotificationProvider({ children }) {
} catch {
// silent
}
}, [stickyAnnouncement?.notification_id, fetchUnseen, fetchStickyAnnouncement]);
}, [fetchUnseen, fetchStickyAnnouncement]);
const markAllSeen = useCallback(async () => {
try {
await api.patch("/client/notifications/seen-all");
setNotifications(prev => prev.map(n => ({ ...n, seen: true })));
setUnseenCount(0);
setStickyAnnouncement(null);
setStickyAnnouncements([]);
} catch {
// silent
}
@@ -131,7 +131,8 @@ export function ClientNotificationProvider({ children }) {
<ClientNotificationContext.Provider value={{
notifications,
unseenCount,
stickyAnnouncement,
stickyAnnouncements,
bannerImage,
loading,
pagination,
fetchNotifications,