Просмотр исходного кода

hit in-app-notification api with mutate

kaori 4 лет назад
Родитель
Сommit
2eaac99119
1 измененных файлов с 5 добавлено и 2 удалено
  1. 5 2
      packages/app/src/components/InAppNotification/InAppNotificationDropdown.tsx

+ 5 - 2
packages/app/src/components/InAppNotification/InAppNotificationDropdown.tsx

@@ -23,7 +23,7 @@ const InAppNotificationDropdown: FC<Props> = (props: Props) => {
   const [count, setCount] = useState(0);
   const [count, setCount] = useState(0);
   const [isOpen, setIsOpen] = useState(false);
   const [isOpen, setIsOpen] = useState(false);
   const limit = 6;
   const limit = 6;
-  const { data: inAppNotificationData } = useSWRxInAppNotifications(limit);
+  const { data: inAppNotificationData, mutate } = useSWRxInAppNotifications(limit);
 
 
   useEffect(() => {
   useEffect(() => {
     initializeSocket(props);
     initializeSocket(props);
@@ -59,11 +59,14 @@ const InAppNotificationDropdown: FC<Props> = (props: Props) => {
   };
   };
 
 
   const toggleDropdownHandler = () => {
   const toggleDropdownHandler = () => {
-    if (isOpen === false && count > 0) {
+    if (!isOpen && count > 0) {
       updateNotificationStatus();
       updateNotificationStatus();
     }
     }
 
 
     const newIsOpenState = !isOpen;
     const newIsOpenState = !isOpen;
+    if (newIsOpenState) {
+      mutate();
+    }
     setIsOpen(newIsOpenState);
     setIsOpen(newIsOpenState);
   };
   };