Quellcode durchsuchen

remove update arg and rename

yuken vor 3 Jahren
Ursprung
Commit
6d129b5545

+ 4 - 8
packages/app/src/components/Admin/Customize/CustomizeSidebarSetting.tsx

@@ -5,13 +5,13 @@ import { Card, CardBody } from 'reactstrap';
 
 import { toastSuccess, toastError } from '~/client/util/apiNotification';
 import { isDarkMode as isDarkModeByUtil } from '~/client/util/color-scheme';
-import { useSidebarConfig } from '~/stores/ui';
+import { useSWRxSidebarConfig } from '~/stores/ui';
 
 const CustomizeSidebarsetting = (): JSX.Element => {
   const { t } = useTranslation();
   const {
     update, isSidebarDrawerMode, isSidebarClosedAtDockMode, setIsSidebarDrawerMode, setIsSidebarClosedAtDockMode,
-  } = useSidebarConfig();
+  } = useSWRxSidebarConfig();
 
   const isDarkMode = isDarkModeByUtil();
   const colorText = isDarkMode ? 'dark' : 'light';
@@ -19,18 +19,14 @@ const CustomizeSidebarsetting = (): JSX.Element => {
   const dockIconFileName = `/images/customize-settings/dock-${colorText}.svg`;
 
   const onClickSubmit = useCallback(async() => {
-    const sidebarConfig = {
-      isSidebarDrawerMode,
-      isSidebarClosedAtDockMode,
-    };
     try {
-      await update(sidebarConfig);
+      await update();
       toastSuccess(t('toaster.update_successed', { target: t('admin:customize_setting.default_sidebar_mode.title') }));
     }
     catch (err) {
       toastError(err);
     }
-  }, [t, isSidebarDrawerMode, isSidebarClosedAtDockMode, update]);
+  }, [t, update]);
 
   return (
     <React.Fragment>

+ 10 - 5
packages/app/src/stores/ui.tsx

@@ -281,28 +281,33 @@ export const useDrawerMode = (): SWRResponse<boolean, Error> => {
 };
 
 type SidebarConfigOption = {
-  update: (updateData: Partial<ISidebarConfig>) => Promise<void>,
+  update: () => Promise<void>,
   isSidebarDrawerMode: boolean|undefined,
   isSidebarClosedAtDockMode: boolean|undefined,
   setIsSidebarDrawerMode: (isSidebarDrawerMode: boolean) => void,
   setIsSidebarClosedAtDockMode: (isSidebarClosedAtDockMode: boolean) => void
 }
 
-export const useSidebarConfig = (): SWRResponse<ISidebarConfig, Error> & SidebarConfigOption => {
+export const useSWRxSidebarConfig = (): SWRResponse<ISidebarConfig, Error> & SidebarConfigOption => {
   const swrResponse = useSWRImmutable<ISidebarConfig>(
     '/customize-setting/sidebar',
     endpoint => apiv3Get(endpoint).then(result => result.data),
   );
   return {
     ...swrResponse,
-    update: async(updateData) => {
-      const { data, mutate } = swrResponse;
+    update: async() => {
+      const { data } = swrResponse;
 
       if (data == null) {
         return;
       }
 
-      mutate({ ...data, ...updateData }, false);
+      const { isSidebarDrawerMode, isSidebarClosedAtDockMode } = data;
+
+      const updateData = {
+        isSidebarDrawerMode,
+        isSidebarClosedAtDockMode,
+      };
 
       // invoke API
       await apiv3Put('/customize-setting/sidebar', updateData);