|
@@ -1,17 +1,22 @@
|
|
|
import { pagePathUtils } from '@growi/core/dist/utils';
|
|
import { pagePathUtils } from '@growi/core/dist/utils';
|
|
|
import { atom, useAtomValue } from 'jotai';
|
|
import { atom, useAtomValue } from 'jotai';
|
|
|
-
|
|
|
|
|
-import { EditorMode } from '~/states/ui/editor';
|
|
|
|
|
-import { useIsSharedUser } from '~/states/context';
|
|
|
|
|
import {
|
|
import {
|
|
|
- useIsEditable, usePageNotFound, useCurrentPagePath, useCurrentPageId,
|
|
|
|
|
-} from '~/states/page';
|
|
|
|
|
-
|
|
|
|
|
-// Import internal atoms with special naming
|
|
|
|
|
-import { _atomsForDerivedAbilities as pageAtoms } from '~/states/page';
|
|
|
|
|
-import { _atomsForDerivedAbilities as editorAtoms } from '~/states/ui/editor';
|
|
|
|
|
|
|
+ _atomsForDerivedAbilities as contextAtoms,
|
|
|
|
|
+ useIsSharedUser,
|
|
|
|
|
+} from '~/states/context';
|
|
|
import { _atomsForDerivedAbilities as globalAtoms } from '~/states/global';
|
|
import { _atomsForDerivedAbilities as globalAtoms } from '~/states/global';
|
|
|
-import { _atomsForDerivedAbilities as contextAtoms } from '~/states/context';
|
|
|
|
|
|
|
+// Import internal atoms with special naming
|
|
|
|
|
+import {
|
|
|
|
|
+ _atomsForDerivedAbilities as pageAtoms,
|
|
|
|
|
+ useCurrentPageId,
|
|
|
|
|
+ useCurrentPagePath,
|
|
|
|
|
+ useIsEditable,
|
|
|
|
|
+ usePageNotFound,
|
|
|
|
|
+} from '~/states/page';
|
|
|
|
|
+import {
|
|
|
|
|
+ EditorMode,
|
|
|
|
|
+ _atomsForDerivedAbilities as editorAtoms,
|
|
|
|
|
+} from '~/states/ui/editor';
|
|
|
|
|
|
|
|
const { isTrashTopPage, isUsersTopPage } = pagePathUtils;
|
|
const { isTrashTopPage, isUsersTopPage } = pagePathUtils;
|
|
|
|
|
|
|
@@ -24,15 +29,24 @@ const isAbleToShowTagLabelAtom = atom((get) => {
|
|
|
const editorMode = get(editorAtoms.editorModeAtom);
|
|
const editorMode = get(editorAtoms.editorModeAtom);
|
|
|
|
|
|
|
|
// Return false if any dependency is undefined
|
|
// Return false if any dependency is undefined
|
|
|
- if ([currentPagePath, isIdenticalPath, isNotFound, editorMode].some(v => v === undefined)) {
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ [currentPagePath, isIdenticalPath, isNotFound, editorMode].some(
|
|
|
|
|
+ (v) => v === undefined,
|
|
|
|
|
+ )
|
|
|
|
|
+ ) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const isViewMode = editorMode === EditorMode.View;
|
|
const isViewMode = editorMode === EditorMode.View;
|
|
|
|
|
|
|
|
// "/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
|
|
|
- return !isUsersTopPage(currentPagePath!) && !isTrashTopPage(currentPagePath!)
|
|
|
|
|
- && shareLinkId == null && !isIdenticalPath && !(isViewMode && isNotFound);
|
|
|
|
|
|
|
+ return (
|
|
|
|
|
+ !isUsersTopPage(currentPagePath!) &&
|
|
|
|
|
+ !isTrashTopPage(currentPagePath!) &&
|
|
|
|
|
+ shareLinkId == null &&
|
|
|
|
|
+ !isIdenticalPath &&
|
|
|
|
|
+ !(isViewMode && isNotFound)
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -51,7 +65,11 @@ const isAbleToShowTrashPageManagementButtonsAtom = atom((get) => {
|
|
|
const isReadOnlyUser = get(contextAtoms.isReadOnlyUserAtom);
|
|
const isReadOnlyUser = get(contextAtoms.isReadOnlyUserAtom);
|
|
|
|
|
|
|
|
// Return false if any dependency is undefined
|
|
// Return false if any dependency is undefined
|
|
|
- if ([currentUser, currentPageId, isNotFound, isReadOnlyUser, isTrashPage].some(v => v === undefined)) {
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ [currentUser, currentPageId, isNotFound, isReadOnlyUser, isTrashPage].some(
|
|
|
|
|
+ (v) => v === undefined,
|
|
|
|
|
+ )
|
|
|
|
|
+ ) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -80,16 +98,21 @@ const isAbleToShowPageManagementAtom = atom((get) => {
|
|
|
const pageId = currentPageId;
|
|
const pageId = currentPageId;
|
|
|
|
|
|
|
|
// Return false if any dependency is undefined
|
|
// Return false if any dependency is undefined
|
|
|
- if ([pageId, isTrashPage, isSharedUser, isNotFound].some(v => v === undefined)) {
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ [pageId, isTrashPage, isSharedUser, isNotFound].some((v) => v === undefined)
|
|
|
|
|
+ ) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const isPageExist = (pageId != null) && isNotFound === false;
|
|
|
|
|
- const isEmptyPage = (pageId != null) && isNotFound === true;
|
|
|
|
|
|
|
+ const isPageExist = pageId != null && isNotFound === false;
|
|
|
|
|
+ const isEmptyPage = pageId != null && isNotFound === true;
|
|
|
const isTrashPageCondition = isPageExist && isTrashPage === true;
|
|
const isTrashPageCondition = isPageExist && isTrashPage === true;
|
|
|
const isSharedUserCondition = isPageExist && isSharedUser === true;
|
|
const isSharedUserCondition = isPageExist && isSharedUser === true;
|
|
|
|
|
|
|
|
- return (isPageExist && !isTrashPageCondition && !isSharedUserCondition) || isEmptyPage;
|
|
|
|
|
|
|
+ return (
|
|
|
|
|
+ (isPageExist && !isTrashPageCondition && !isSharedUserCondition) ||
|
|
|
|
|
+ isEmptyPage
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -106,7 +129,9 @@ export const useIsAbleToChangeEditorMode = (): boolean => {
|
|
|
const isEditable = useIsEditable();
|
|
const isEditable = useIsEditable();
|
|
|
const isSharedUser = useIsSharedUser();
|
|
const isSharedUser = useIsSharedUser();
|
|
|
|
|
|
|
|
- const includesUndefined = [isEditable, isSharedUser].some(v => v === undefined);
|
|
|
|
|
|
|
+ const includesUndefined = [isEditable, isSharedUser].some(
|
|
|
|
|
+ (v) => v === undefined,
|
|
|
|
|
+ );
|
|
|
if (includesUndefined) return false;
|
|
if (includesUndefined) return false;
|
|
|
|
|
|
|
|
return !!isEditable && !isSharedUser;
|
|
return !!isEditable && !isSharedUser;
|
|
@@ -120,10 +145,12 @@ export const useIsAbleToShowPageAuthors = (): boolean => {
|
|
|
const isNotFound = usePageNotFound();
|
|
const isNotFound = usePageNotFound();
|
|
|
const pagePath = useCurrentPagePath();
|
|
const pagePath = useCurrentPagePath();
|
|
|
|
|
|
|
|
- const includesUndefined = [pageId, pagePath, isNotFound].some(v => v === undefined);
|
|
|
|
|
|
|
+ const includesUndefined = [pageId, pagePath, isNotFound].some(
|
|
|
|
|
+ (v) => v === undefined,
|
|
|
|
|
+ );
|
|
|
if (includesUndefined) return false;
|
|
if (includesUndefined) return false;
|
|
|
|
|
|
|
|
- const isPageExist = (pageId != null) && !isNotFound;
|
|
|
|
|
|
|
+ const isPageExist = pageId != null && !isNotFound;
|
|
|
const isUsersTopPagePath = pagePath != null && isUsersTopPage(pagePath);
|
|
const isUsersTopPagePath = pagePath != null && isUsersTopPage(pagePath);
|
|
|
|
|
|
|
|
return isPageExist && !isUsersTopPagePath;
|
|
return isPageExist && !isUsersTopPagePath;
|