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

Merge pull request #7914 from weseek/fix/127402

fix: Sidebar doesn't show the link to the administration panel when logged in as an Admin
Yuki Takei 2 лет назад
Родитель
Сommit
a5873146a4
1 измененных файлов с 9 добавлено и 7 удалено
  1. 9 7
      apps/app/src/stores/context.tsx

+ 9 - 7
apps/app/src/stores/context.tsx

@@ -1,5 +1,5 @@
 import type { ColorScheme, IUserHasId } from '@growi/core';
-import { SWRResponse } from 'swr';
+import useSWR, { SWRResponse } from 'swr';
 import useSWRImmutable from 'swr/immutable';
 
 import { SupportedActionType } from '~/interfaces/activity';
@@ -232,14 +232,16 @@ export const useIsReadOnlyUser = (): SWRResponse<boolean, Error> => {
 export const useIsAdmin = (): SWRResponse<boolean, Error> => {
   const { data: currentUser, isLoading } = useCurrentUser();
 
-  const isAdminUser = currentUser != null ? currentUser.admin : false;
-
-  return useSWRImmutable(
-    isLoading ? null : ['isAdminUser', currentUser?._id],
-    () => isAdminUser,
+  return useSWR(
+    isLoading ? null : ['isAdminUser', currentUser?._id, currentUser?.admin],
+    ([, , isAdmin]) => isAdmin ?? false,
     {
-      fallbackData: isAdminUser,
+      fallbackData: currentUser?.admin ?? false,
       keepPreviousData: true,
+      // disable all revalidation but revalidateIfStale
+      revalidateOnMount: false,
+      revalidateOnFocus: false,
+      revalidateOnReconnect: false,
     },
   );
 };