浏览代码

errors in log fix

Viktoriia 11 月之前
父节点
当前提交
3f9544847a

+ 3 - 0
src/components/MenuDrawer/index.tsx

@@ -15,6 +15,7 @@ import DocumentIcon from '../../../assets/icons/document.svg';
 import ExitIcon from '../../../assets/icons/exit.svg';
 import UserXMark from '../../../assets/icons/user-xmark.svg';
 import { APP_VERSION, FASTEST_MAP_HOST } from 'src/constants';
+import { useNotification } from 'src/contexts/NotificationContext';
 
 export const MenuDrawer = (props: any) => {
   const { mutate: deleteUser } = useDeleteUserMutation();
@@ -26,6 +27,7 @@ export const MenuDrawer = (props: any) => {
     message: '',
     action: () => {}
   });
+  const { updateNotificationStatus } = useNotification();
 
   const openModal = (type: string, message: string, action: any) => {
     setModalInfo({
@@ -43,6 +45,7 @@ export const MenuDrawer = (props: any) => {
   const handleLogout = () => {
     storage.remove('token');
     storage.remove('uid');
+    updateNotificationStatus();
     navigation.dispatch(
       CommonActions.reset({
         index: 1,

+ 18 - 12
src/contexts/NotificationContext.tsx

@@ -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(() => {

+ 3 - 0
src/screens/InAppScreens/ProfileScreen/Profile/edit-personal-info.tsx

@@ -43,6 +43,7 @@ import LinkIcon from '../../../../../assets/icons/link.svg';
 import { ButtonVariants } from 'src/types/components';
 import { NAVIGATION_PAGES } from 'src/types';
 import { useDeleteUserMutation } from '@api/app';
+import { useNotification } from 'src/contexts/NotificationContext';
 
 const ProfileSchema = yup.object({
   username: yup.string().optional(),
@@ -72,6 +73,7 @@ export const EditPersonalInfo = () => {
   const queryClient = useQueryClient();
 
   const { data, error } = usePostGetProfileQuery(String(token), true);
+  const { updateNotificationStatus } = useNotification();
 
   const regions = useGetRegionsWithFlagQuery(true);
   const [modalInfo, setModalInfo] = useState({
@@ -102,6 +104,7 @@ export const EditPersonalInfo = () => {
   const handleLogout = () => {
     storage.remove('token');
     storage.remove('uid');
+    updateNotificationStatus();
     navigation.dispatch(
       CommonActions.reset({
         index: 1,

+ 3 - 0
src/screens/LoginScreen/index.tsx

@@ -13,6 +13,7 @@ import { NAVIGATION_PAGES } from '../../types';
 import { useLoginMutation } from '@api/auth';
 import { fetchAndSaveStatistics } from 'src/database/statisticsService';
 import { useNetInfo } from '@react-native-community/netinfo';
+import { useNotification } from 'src/contexts/NotificationContext';
 
 type Props = {
   navigation: NavigationProp<any>;
@@ -28,6 +29,7 @@ const LoginScreen: FC<Props> = ({ navigation }) => {
   const isFirstLaunch = storage.get('isFirstLaunch', StoreType.BOOLEAN) ?? true;
 
   const { data, mutate: userLogin } = useLoginMutation();
+  const { updateNotificationStatus } = useNotification();
 
   const updateLocalData = async (token: string) => {
     await fetchAndSaveStatistics(token);
@@ -41,6 +43,7 @@ const LoginScreen: FC<Props> = ({ navigation }) => {
       storage.set('token', data.token);
       storage.set('uid', data.uid.toString());
       storage.set('isFirstLaunch', false);
+      updateNotificationStatus();
       updateLocalData(data.token);
 
       isFirstLaunch