diff --git a/client/src/App/SoundWrapper.jsx b/client/src/App/SoundWrapper.jsx index 065745de5..904f810b9 100644 --- a/client/src/App/SoundWrapper.jsx +++ b/client/src/App/SoundWrapper.jsx @@ -1,8 +1,6 @@ -// src/app/SoundWrapper.jsx import { useEffect } from "react"; import { useTranslation } from "react-i18next"; import { useNotification } from "../contexts/Notifications/notificationContext.jsx"; -import newMessageWav from "./../audio/messageTone.wav"; import { initNewMessageSound, unlockAudio } from "./../utils/soundManager"; export default function SoundWrapper({ children }) { @@ -11,7 +9,7 @@ export default function SoundWrapper({ children }) { useEffect(() => { // Initialize base audio - initNewMessageSound(newMessageWav, 0.7); + initNewMessageSound("https://images.imex.online/app/messageTone.wav", 0.7); // Show a one-time prompt when a play was blocked by autoplay policy const onNeedsUnlock = () => { diff --git a/client/src/audio/messageTone.wav b/client/src/audio/messageTone.wav deleted file mode 100644 index 4bed79ac1..000000000 Binary files a/client/src/audio/messageTone.wav and /dev/null differ diff --git a/client/src/components/notification-center/notification-center.container.jsx b/client/src/components/notification-center/notification-center.container.jsx index d0024c9d3..e534375f6 100644 --- a/client/src/components/notification-center/notification-center.container.jsx +++ b/client/src/components/notification-center/notification-center.container.jsx @@ -39,11 +39,15 @@ const NotificationCenterContainer = ({ visible, onClose, bodyshop, unreadCount, return showUnreadOnly ? { ...baseWhereClause, read: { _is_null: true } } : baseWhereClause; }, [baseWhereClause, showUnreadOnly]); + // before you call useQuery, compute skip once so you can reuse it + const skipQuery = !userAssociationId || !isEmployee; + const { data, fetchMore, loading: queryLoading, - refetch + refetch, + error } = useQuery(GET_NOTIFICATIONS, { variables: { limit: INITIAL_NOTIFICATIONS, @@ -52,14 +56,26 @@ const NotificationCenterContainer = ({ visible, onClose, bodyshop, unreadCount, }, fetchPolicy: "cache-and-network", notifyOnNetworkStatusChange: true, + errorPolicy: "all", pollInterval: isConnected ? 0 : day.duration(NOTIFICATION_POLL_INTERVAL_SECONDS, "seconds").asMilliseconds(), - skip: !userAssociationId || !isEmployee, - onError: (err) => { - console.error(`Error polling Notifications: ${err?.message || ""}`); - setTimeout(() => refetch(), day.duration(2, "seconds").asMilliseconds()); - } + skip: skipQuery }); + // Replace onError with a side-effect that reacts to the hook’s `error` + useEffect(() => { + if (!error || skipQuery) return; + + console.error(`Error polling Notifications: ${error?.message || ""}`); + + const t = setTimeout(() => { + // Guard: if component unmounted or query now skipped, do nothing + if (!skipQuery) { + refetch().catch((e) => console.error("Refetch failed:", e?.message || e)); + } + }, day.duration(2, "seconds").asMilliseconds()); + + return () => clearTimeout(t); + }, [error, refetch, skipQuery]); useEffect(() => { const handleClickOutside = (event) => { // Prevent open + close behavior from the header