فهرست منبع

delete useIsEmpty

yuken 3 سال پیش
والد
کامیت
a2a2633254

+ 3 - 4
packages/app/src/components/Page/DisplaySwitcher.tsx

@@ -7,7 +7,7 @@ import { TabContent, TabPane } from 'reactstrap';
 
 
 import { smoothScrollIntoView } from '~/client/util/smooth-scroll';
 import { smoothScrollIntoView } from '~/client/util/smooth-scroll';
 import {
 import {
-  useCurrentPagePath, useIsSharedUser, useIsEditable, useIsUserPage, usePageUser, useShareLinkId, useIsNotFound, useIsNotCreatable, useIsEmpty,
+  useCurrentPagePath, useIsSharedUser, useIsEditable, useIsUserPage, usePageUser, useShareLinkId, useIsNotFound, useIsNotCreatable,
 } from '~/stores/context';
 } from '~/stores/context';
 import { useDescendantsPageListModal } from '~/stores/modal';
 import { useDescendantsPageListModal } from '~/stores/modal';
 import { useSWRxCurrentPage } from '~/stores/page';
 import { useSWRxCurrentPage } from '~/stores/page';
@@ -49,7 +49,6 @@ const DisplaySwitcher = (): JSX.Element => {
   const { data: pageUser } = usePageUser();
   const { data: pageUser } = usePageUser();
   const { data: isNotFound } = useIsNotFound();
   const { data: isNotFound } = useIsNotFound();
   const { data: isNotCreatable } = useIsNotCreatable();
   const { data: isNotCreatable } = useIsNotCreatable();
-  const { data: isEmpty } = useIsEmpty();
   const { data: currentPage } = useSWRxCurrentPage(shareLinkId ?? undefined);
   const { data: currentPage } = useSWRxCurrentPage(shareLinkId ?? undefined);
 
 
   const { data: editorMode } = useEditorMode();
   const { data: editorMode } = useEditorMode();
@@ -69,8 +68,8 @@ const DisplaySwitcher = (): JSX.Element => {
 
 
             <div className="flex-grow-1 flex-basis-0 mw-0">
             <div className="flex-grow-1 flex-basis-0 mw-0">
               { isUserPage && <UserInfo pageUser={pageUser} />}
               { isUserPage && <UserInfo pageUser={pageUser} />}
-              { !isNotFound && !isEmpty && <Page /> }
-              { (isNotFound || isEmpty) && <NotFoundPage /> }
+              { !isNotFound && <Page /> }
+              { isNotFound && <NotFoundPage /> }
             </div>
             </div>
 
 
             { !isNotFound && !currentPage?.isEmpty && (
             { !isNotFound && !currentPage?.isEmpty && (

+ 3 - 3
packages/app/src/components/PageAlert/PageAlerts.tsx

@@ -2,7 +2,7 @@ import React from 'react';
 
 
 import dynamic from 'next/dynamic';
 import dynamic from 'next/dynamic';
 
 
-import { useIsEmpty } from '~/stores/context';
+import { useIsNotFound } from '~/stores/context';
 
 
 import { FixPageGrantAlert } from './FixPageGrantAlert';
 import { FixPageGrantAlert } from './FixPageGrantAlert';
 import { OldRevisionAlert } from './OldRevisionAlert';
 import { OldRevisionAlert } from './OldRevisionAlert';
@@ -14,13 +14,13 @@ const TrashPageAlert = dynamic(() => import('./TrashPageAlert').then(mod => mod.
 
 
 export const PageAlerts = (): JSX.Element => {
 export const PageAlerts = (): JSX.Element => {
 
 
-  const { data: isEmpty } = useIsEmpty();
+  const { data: isNotFound } = useIsNotFound();
 
 
   return (
   return (
     <div className="row d-edit-none">
     <div className="row d-edit-none">
       <div className="col-sm-12">
       <div className="col-sm-12">
         {/* alerts */}
         {/* alerts */}
-        { !isEmpty && <FixPageGrantAlert /> }
+        { !isNotFound && <FixPageGrantAlert /> }
         <PageGrantAlert />
         <PageGrantAlert />
         <TrashPageAlert />
         <TrashPageAlert />
         <PageStaleAlert />
         <PageStaleAlert />

+ 3 - 3
packages/app/src/components/PagePathNav.tsx

@@ -3,7 +3,7 @@ import React, { FC } from 'react';
 import { DevidedPagePath } from '@growi/core';
 import { DevidedPagePath } from '@growi/core';
 import dynamic from 'next/dynamic';
 import dynamic from 'next/dynamic';
 
 
-import { useIsEmpty } from '~/stores/context';
+import { useIsNotFound } from '~/stores/context';
 
 
 import LinkedPagePath from '../models/linked-page-path';
 import LinkedPagePath from '../models/linked-page-path';
 
 
@@ -23,7 +23,7 @@ const PagePathNav: FC<Props> = (props: Props) => {
   } = props;
   } = props;
   const dPagePath = new DevidedPagePath(pagePath, false, true);
   const dPagePath = new DevidedPagePath(pagePath, false, true);
 
 
-  const { data: isEmpty } = useIsEmpty();
+  const { data: isNotFound } = useIsNotFound();
 
 
   const CopyDropdown = dynamic(() => import('./Page/CopyDropdown'), { ssr: false });
   const CopyDropdown = dynamic(() => import('./Page/CopyDropdown'), { ssr: false });
 
 
@@ -51,7 +51,7 @@ const PagePathNav: FC<Props> = (props: Props) => {
       {formerLink}
       {formerLink}
       <span className="d-flex align-items-center">
       <span className="d-flex align-items-center">
         <h1 className="m-0">{latterLink}</h1>
         <h1 className="m-0">{latterLink}</h1>
-        { pageId != null && !isEmpty && (
+        { pageId != null && !isNotFound && (
           <div className="mx-2">
           <div className="mx-2">
             <CopyDropdown pageId={pageId} pagePath={pagePath} dropdownToggleId={copyDropdownId} dropdownToggleClassName={copyDropdownToggleClassName}>
             <CopyDropdown pageId={pageId} pagePath={pagePath} dropdownToggleId={copyDropdownId} dropdownToggleClassName={copyDropdownToggleClassName}>
               <i className="ti ti-clipboard"></i>
               <i className="ti ti-clipboard"></i>

+ 4 - 6
packages/app/src/pages/[[...path]].page.tsx

@@ -41,11 +41,11 @@ import loggerFactory from '~/utils/logger';
 
 
 // import GrowiSubNavigation from '../client/js/components/Navbar/GrowiSubNavigation';
 // import GrowiSubNavigation from '../client/js/components/Navbar/GrowiSubNavigation';
 // import GrowiSubNavigationSwitcher from '../client/js/components/Navbar/GrowiSubNavigationSwitcher';
 // import GrowiSubNavigationSwitcher from '../client/js/components/Navbar/GrowiSubNavigationSwitcher';
+import ForbiddenPage from '../components/ForbiddenPage';
 import { BasicLayout } from '../components/Layout/BasicLayout';
 import { BasicLayout } from '../components/Layout/BasicLayout';
 import GrowiContextualSubNavigation from '../components/Navbar/GrowiContextualSubNavigation';
 import GrowiContextualSubNavigation from '../components/Navbar/GrowiContextualSubNavigation';
-import DisplaySwitcher from '../components/Page/DisplaySwitcher';
 import { NotCreatablePage } from '../components/NotCreatablePage';
 import { NotCreatablePage } from '../components/NotCreatablePage';
-import ForbiddenPage from '../components/ForbiddenPage';
+import DisplaySwitcher from '../components/Page/DisplaySwitcher';
 
 
 // import { serializeUserSecurely } from '../server/models/serializers/user-serializer';
 // import { serializeUserSecurely } from '../server/models/serializers/user-serializer';
 // import PageStatusAlert from '../client/js/components/PageStatusAlert';
 // import PageStatusAlert from '../client/js/components/PageStatusAlert';
@@ -57,7 +57,7 @@ import {
   useIsForbidden, useIsNotFound, useIsTrashPage, useIsSharedUser,
   useIsForbidden, useIsNotFound, useIsTrashPage, useIsSharedUser,
   useIsEnabledStaleNotification, useIsIdenticalPath,
   useIsEnabledStaleNotification, useIsIdenticalPath,
   useIsSearchServiceConfigured, useIsSearchServiceReachable, useDisableLinkSharing,
   useIsSearchServiceConfigured, useIsSearchServiceReachable, useDisableLinkSharing,
-  useHackmdUri, useIsEmpty,
+  useHackmdUri,
   useIsAclEnabled, useIsUserPage, useIsNotCreatable,
   useIsAclEnabled, useIsUserPage, useIsNotCreatable,
   useCsrfToken, useIsSearchScopeChildrenAsDefault, useCurrentPageId, useCurrentPathname,
   useCsrfToken, useIsSearchScopeChildrenAsDefault, useCurrentPageId, useCurrentPathname,
   useIsSlackConfigured, useIsBlinkedHeaderAtBoot, useRendererConfig, useEditingMarkdown,
   useIsSlackConfigured, useIsBlinkedHeaderAtBoot, useRendererConfig, useEditingMarkdown,
@@ -131,7 +131,6 @@ type Props = CommonProps & {
   isForbidden: boolean,
   isForbidden: boolean,
   isNotFound: boolean,
   isNotFound: boolean,
   IsNotCreatable: boolean,
   IsNotCreatable: boolean,
-  isEmpty: boolean,
   // isAbleToDeleteCompletely: boolean,
   // isAbleToDeleteCompletely: boolean,
 
 
   isSearchServiceConfigured: boolean,
   isSearchServiceConfigured: boolean,
@@ -198,7 +197,6 @@ const GrowiPage: NextPage<Props> = (props: Props) => {
   useIsForbidden(props.isForbidden);
   useIsForbidden(props.isForbidden);
   useIsNotFound(props.isNotFound);
   useIsNotFound(props.isNotFound);
   useIsNotCreatable(props.IsNotCreatable);
   useIsNotCreatable(props.IsNotCreatable);
-  useIsEmpty(props.isEmpty);
   // useIsTrashPage(_isTrashPage(props.currentPagePath));
   // useIsTrashPage(_isTrashPage(props.currentPagePath));
   // useShared();
   // useShared();
   // useShareLinkId(props.shareLinkId);
   // useShareLinkId(props.shareLinkId);
@@ -420,7 +418,7 @@ async function injectRoutingInformation(context: GetServerSidePropsContext, prop
     props.isForbidden = count > 0;
     props.isForbidden = count > 0;
   }
   }
   else {
   else {
-    props.isEmpty = page.isEmpty;
+    page.isNotFound = page.isEmpty;
 
 
     // /62a88db47fed8b2d94f30000 ==> /path/to/page
     // /62a88db47fed8b2d94f30000 ==> /path/to/page
     if (isPermalink && page.isEmpty) {
     if (isPermalink && page.isEmpty) {

+ 0 - 4
packages/app/src/stores/context.tsx

@@ -100,10 +100,6 @@ export const useIsNotFound = (initialData?: boolean): SWRResponse<boolean, Error
   return useStaticSWR<boolean, Error>('isNotFound', initialData, { fallbackData: false });
   return useStaticSWR<boolean, Error>('isNotFound', initialData, { fallbackData: false });
 };
 };
 
 
-export const useIsEmpty = (initialData?: boolean): SWRResponse<boolean, Error> => {
-  return useStaticSWR<boolean, Error>('isEmpty', initialData, { fallbackData: false });
-};
-
 export const usePageUser = (initialData?: Nullable<any>): SWRResponse<Nullable<any>, Error> => {
 export const usePageUser = (initialData?: Nullable<any>): SWRResponse<Nullable<any>, Error> => {
   return useStaticSWR<Nullable<any>, Error>('pageUser', initialData);
   return useStaticSWR<Nullable<any>, Error>('pageUser', initialData);
 };
 };

+ 6 - 7
packages/app/src/stores/ui.tsx

@@ -21,7 +21,7 @@ import loggerFactory from '~/utils/logger';
 
 
 import {
 import {
   useCurrentPageId, useCurrentPagePath, useIsEditable, useIsTrashPage, useIsUserPage, useIsGuestUser,
   useCurrentPageId, useCurrentPagePath, useIsEditable, useIsTrashPage, useIsUserPage, useIsGuestUser,
-  useIsNotCreatable, useIsSharedUser, useIsForbidden, useIsIdenticalPath, useCurrentUser, useIsNotFound, useShareLinkId, useIsEmpty,
+  useIsNotCreatable, useIsSharedUser, useIsForbidden, useIsIdenticalPath, useCurrentUser, useIsNotFound, useShareLinkId,
 } from './context';
 } from './context';
 import { localStorageMiddleware } from './middlewares/sync-to-storage';
 import { localStorageMiddleware } from './middlewares/sync-to-storage';
 import { useStaticSWR } from './use-static-swr';
 import { useStaticSWR } from './use-static-swr';
@@ -416,13 +416,13 @@ export const useIsAbleToShowPageManagement = (): SWRResponse<boolean, Error> =>
   const { data: currentPageId } = useCurrentPageId();
   const { data: currentPageId } = useCurrentPageId();
   const { data: isTrashPage } = useIsTrashPage();
   const { data: isTrashPage } = useIsTrashPage();
   const { data: isSharedUser } = useIsSharedUser();
   const { data: isSharedUser } = useIsSharedUser();
-  const { data: isEmpty } = useIsEmpty();
+  const { data: isNotFound } = useIsNotFound();
 
 
   const key = `isAbleToShowPageManagement ${currentPageId}`;
   const key = `isAbleToShowPageManagement ${currentPageId}`;
 
 
   const pageId = currentPageId;
   const pageId = currentPageId;
   const includesUndefined = [pageId, isTrashPage, isSharedUser].some(v => v === undefined);
   const includesUndefined = [pageId, isTrashPage, isSharedUser].some(v => v === undefined);
-  const isPageExist = (pageId != null) && !isEmpty;
+  const isPageExist = (pageId != null) && !isNotFound;
 
 
   return useSWRImmutable(
   return useSWRImmutable(
     includesUndefined ? null : key,
     includesUndefined ? null : key,
@@ -436,7 +436,6 @@ export const useIsAbleToShowTagLabel = (): SWRResponse<boolean, Error> => {
   const { data: currentPagePath } = useCurrentPagePath();
   const { data: currentPagePath } = useCurrentPagePath();
   const { data: isIdenticalPath } = useIsIdenticalPath();
   const { data: isIdenticalPath } = useIsIdenticalPath();
   const { data: isNotFound } = useIsNotFound();
   const { data: isNotFound } = useIsNotFound();
-  const { data: isEmpty } = useIsEmpty();
   const { data: editorMode } = useEditorMode();
   const { data: editorMode } = useEditorMode();
   const { data: shareLinkId } = useShareLinkId();
   const { data: shareLinkId } = useShareLinkId();
 
 
@@ -450,7 +449,7 @@ export const useIsAbleToShowTagLabel = (): SWRResponse<boolean, Error> => {
     includesUndefined ? null : [key, editorMode],
     includesUndefined ? null : [key, editorMode],
     // "/trash" page does not exist on page collection and unable to add tags
     // "/trash" page does not exist on page collection and unable to add tags
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    () => !isUserPage && !isTrashTopPage(currentPagePath!) && shareLinkId == null && !isIdenticalPath && !(isViewMode && isNotFound) && !isEmpty,
+    () => !isUserPage && !isTrashTopPage(currentPagePath!) && shareLinkId == null && !isIdenticalPath && !(isViewMode && isNotFound),
   );
   );
 };
 };
 
 
@@ -472,12 +471,12 @@ export const useIsAbleToShowPageEditorModeManager = (): SWRResponse<boolean, Err
 export const useIsAbleToShowPageAuthors = (): SWRResponse<boolean, Error> => {
 export const useIsAbleToShowPageAuthors = (): SWRResponse<boolean, Error> => {
   const { data: currentPageId } = useCurrentPageId();
   const { data: currentPageId } = useCurrentPageId();
   const { data: isUserPage } = useIsUserPage();
   const { data: isUserPage } = useIsUserPage();
-  const { data: isEmpty } = useIsEmpty();
+  const { data: isNotFound } = useIsNotFound();
 
 
   const key = `isAbleToShowPageAuthors ${currentPageId}`;
   const key = `isAbleToShowPageAuthors ${currentPageId}`;
 
 
   const includesUndefined = [currentPageId, isUserPage].some(v => v === undefined);
   const includesUndefined = [currentPageId, isUserPage].some(v => v === undefined);
-  const isPageExist = (currentPageId != null) && !isEmpty;
+  const isPageExist = (currentPageId != null) && !isNotFound;
 
 
   return useSWRImmutable(
   return useSWRImmutable(
     includesUndefined ? null : key,
     includesUndefined ? null : key,