|
@@ -1,4 +1,7 @@
|
|
|
-import { pagePathUtils } from '@growi/core/dist/utils';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ isCreatablePage,
|
|
|
|
|
+ isPermalink,
|
|
|
|
|
+} from '@growi/core/dist/utils/page-path-utils';
|
|
|
import { useAtomValue } from 'jotai';
|
|
import { useAtomValue } from 'jotai';
|
|
|
import { useAtomCallback } from 'jotai/utils';
|
|
import { useAtomCallback } from 'jotai/utils';
|
|
|
import { useCallback, useMemo } from 'react';
|
|
import { useCallback, useMemo } from 'react';
|
|
@@ -10,11 +13,9 @@ import {
|
|
|
currentPagePathAtom,
|
|
currentPagePathAtom,
|
|
|
isForbiddenAtom,
|
|
isForbiddenAtom,
|
|
|
isIdenticalPathAtom,
|
|
isIdenticalPathAtom,
|
|
|
- isNotCreatableAtom,
|
|
|
|
|
isRevisionOutdatedAtom,
|
|
isRevisionOutdatedAtom,
|
|
|
isTrashPageAtom,
|
|
isTrashPageAtom,
|
|
|
latestRevisionAtom,
|
|
latestRevisionAtom,
|
|
|
- pageNotCreatableAtom,
|
|
|
|
|
pageNotFoundAtom,
|
|
pageNotFoundAtom,
|
|
|
redirectFromAtom,
|
|
redirectFromAtom,
|
|
|
remoteRevisionBodyAtom,
|
|
remoteRevisionBodyAtom,
|
|
@@ -38,14 +39,10 @@ export const useCurrentPageData = () => useAtomValue(currentPageDataAtom);
|
|
|
|
|
|
|
|
export const usePageNotFound = () => useAtomValue(pageNotFoundAtom);
|
|
export const usePageNotFound = () => useAtomValue(pageNotFoundAtom);
|
|
|
|
|
|
|
|
-export const usePageNotCreatable = () => useAtomValue(pageNotCreatableAtom);
|
|
|
|
|
-
|
|
|
|
|
export const useIsIdenticalPath = () => useAtomValue(isIdenticalPathAtom);
|
|
export const useIsIdenticalPath = () => useAtomValue(isIdenticalPathAtom);
|
|
|
|
|
|
|
|
export const useIsForbidden = () => useAtomValue(isForbiddenAtom);
|
|
export const useIsForbidden = () => useAtomValue(isForbiddenAtom);
|
|
|
|
|
|
|
|
-export const useIsNotCreatable = () => useAtomValue(isNotCreatableAtom);
|
|
|
|
|
-
|
|
|
|
|
export const useLatestRevision = () => useAtomValue(latestRevisionAtom);
|
|
export const useLatestRevision = () => useAtomValue(latestRevisionAtom);
|
|
|
|
|
|
|
|
export const useShareLinkId = () => useAtomValue(shareLinkIdAtom);
|
|
export const useShareLinkId = () => useAtomValue(shareLinkIdAtom);
|
|
@@ -80,7 +77,7 @@ export const useCurrentPagePath = (): string | undefined => {
|
|
|
if (currentPagePath != null) {
|
|
if (currentPagePath != null) {
|
|
|
return currentPagePath;
|
|
return currentPagePath;
|
|
|
}
|
|
}
|
|
|
- if (currentPathname != null && !pagePathUtils.isPermalink(currentPathname)) {
|
|
|
|
|
|
|
+ if (currentPathname != null && !isPermalink(currentPathname)) {
|
|
|
return currentPathname;
|
|
return currentPathname;
|
|
|
}
|
|
}
|
|
|
return undefined;
|
|
return undefined;
|
|
@@ -99,24 +96,37 @@ export const useIsTrashPage = (): boolean => useAtomValue(isTrashPageAtom);
|
|
|
export const useIsRevisionOutdated = (): boolean =>
|
|
export const useIsRevisionOutdated = (): boolean =>
|
|
|
useAtomValue(isRevisionOutdatedAtom);
|
|
useAtomValue(isRevisionOutdatedAtom);
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Computed hook for checking if current page is creatable
|
|
|
|
|
+ */
|
|
|
|
|
+export const useIsNotCreatable = (): boolean => {
|
|
|
|
|
+ const pagePath = useCurrentPagePath();
|
|
|
|
|
+ return pagePath == null ? true : !isCreatablePage(pagePath);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Computed hook for checking if current page is editable
|
|
* Computed hook for checking if current page is editable
|
|
|
*/
|
|
*/
|
|
|
export const useIsEditable = () => {
|
|
export const useIsEditable = () => {
|
|
|
const isGuestUser = useIsGuestUser();
|
|
const isGuestUser = useIsGuestUser();
|
|
|
const isReadOnlyUser = useIsReadOnlyUser();
|
|
const isReadOnlyUser = useIsReadOnlyUser();
|
|
|
|
|
+ const isNotCreatable = useIsNotCreatable();
|
|
|
|
|
|
|
|
const getCombinedConditions = useAtomCallback(
|
|
const getCombinedConditions = useAtomCallback(
|
|
|
useCallback((get) => {
|
|
useCallback((get) => {
|
|
|
const isForbidden = get(isForbiddenAtom);
|
|
const isForbidden = get(isForbiddenAtom);
|
|
|
- const isNotCreatable = get(isNotCreatableAtom);
|
|
|
|
|
const isIdenticalPath = get(isIdenticalPathAtom);
|
|
const isIdenticalPath = get(isIdenticalPathAtom);
|
|
|
|
|
|
|
|
- return !isForbidden && !isIdenticalPath && !isNotCreatable;
|
|
|
|
|
|
|
+ return !isForbidden && !isIdenticalPath;
|
|
|
}, []),
|
|
}, []),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
return useMemo(() => {
|
|
return useMemo(() => {
|
|
|
- return !isGuestUser && !isReadOnlyUser && getCombinedConditions();
|
|
|
|
|
- }, [getCombinedConditions, isGuestUser, isReadOnlyUser]);
|
|
|
|
|
|
|
+ return (
|
|
|
|
|
+ !isGuestUser &&
|
|
|
|
|
+ !isReadOnlyUser &&
|
|
|
|
|
+ !isNotCreatable &&
|
|
|
|
|
+ getCombinedConditions()
|
|
|
|
|
+ );
|
|
|
|
|
+ }, [getCombinedConditions, isGuestUser, isReadOnlyUser, isNotCreatable]);
|
|
|
};
|
|
};
|