|
@@ -11,22 +11,28 @@ export const NotificationProvider = ({ children }: { children: React.ReactNode }
|
|
|
const [isNotificationActive, setIsNotificationActive] = useState(
|
|
|
storage.get('friendsNotification', StoreType.BOOLEAN) as boolean
|
|
|
);
|
|
|
- const token = storage.get('token', StoreType.STRING) as string;
|
|
|
-
|
|
|
- const updateNotificationStatus = useCallback(async () => {
|
|
|
- try {
|
|
|
- const data = await fetchFriendsNotification(token);
|
|
|
- const isActive = data && data.active;
|
|
|
- setIsNotificationActive(isActive as boolean);
|
|
|
- storage.set('friendsNotification', isActive as boolean);
|
|
|
- } catch (error) {
|
|
|
- console.error('Failed to fetch notifications', error);
|
|
|
+
|
|
|
+ const updateNotificationStatus = async () => {
|
|
|
+ const token = storage.get('token', StoreType.STRING);
|
|
|
+
|
|
|
+ if (token) {
|
|
|
+ try {
|
|
|
+ const data = await fetchFriendsNotification(token as string);
|
|
|
+ const isActive = data && data.active;
|
|
|
+ setIsNotificationActive(isActive as boolean);
|
|
|
+ storage.set('friendsNotification', isActive as boolean);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Failed to fetch notifications', error);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ setIsNotificationActive(false);
|
|
|
+ storage.set('friendsNotification', false);
|
|
|
}
|
|
|
- }, [token]);
|
|
|
+ };
|
|
|
|
|
|
useEffect(() => {
|
|
|
updateNotificationStatus();
|
|
|
- }, [token]);
|
|
|
+ }, []);
|
|
|
|
|
|
useEffect(() => {
|
|
|
const interval = setInterval(() => {
|