mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 21:38:44 +08:00
feat: Duplicate page in page list and clone naming improvements (#5818)
This commit is contained in:
@@ -31,10 +31,11 @@ const usePageOperationsRenderer = () => {
|
|||||||
const { setTrashModal } = useTrashModalHelper(
|
const { setTrashModal } = useTrashModalHelper(
|
||||||
currentWorkspace.blockSuiteWorkspace
|
currentWorkspace.blockSuiteWorkspace
|
||||||
);
|
);
|
||||||
const { toggleFavorite } = useBlockSuiteMetaHelper(
|
const { toggleFavorite, duplicate } = useBlockSuiteMetaHelper(
|
||||||
currentWorkspace.blockSuiteWorkspace
|
currentWorkspace.blockSuiteWorkspace
|
||||||
);
|
);
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
|
|
||||||
const pageOperationsRenderer = useCallback(
|
const pageOperationsRenderer = useCallback(
|
||||||
(page: PageMeta) => {
|
(page: PageMeta) => {
|
||||||
const onDisablePublicSharing = () => {
|
const onDisablePublicSharing = () => {
|
||||||
@@ -42,12 +43,16 @@ const usePageOperationsRenderer = () => {
|
|||||||
portal: document.body,
|
portal: document.body,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageOperationCell
|
<PageOperationCell
|
||||||
favorite={!!page.favorite}
|
favorite={!!page.favorite}
|
||||||
isPublic={!!page.isPublic}
|
isPublic={!!page.isPublic}
|
||||||
onDisablePublicSharing={onDisablePublicSharing}
|
onDisablePublicSharing={onDisablePublicSharing}
|
||||||
link={`/workspace/${currentWorkspace.id}/${page.id}`}
|
link={`/workspace/${currentWorkspace.id}/${page.id}`}
|
||||||
|
onDuplicate={() => {
|
||||||
|
duplicate(page.id, false);
|
||||||
|
}}
|
||||||
onRemoveToTrash={() =>
|
onRemoveToTrash={() =>
|
||||||
setTrashModal({
|
setTrashModal({
|
||||||
open: true,
|
open: true,
|
||||||
@@ -67,7 +72,7 @@ const usePageOperationsRenderer = () => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[currentWorkspace.id, setTrashModal, t, toggleFavorite]
|
[currentWorkspace.id, setTrashModal, t, toggleFavorite, duplicate]
|
||||||
);
|
);
|
||||||
|
|
||||||
return pageOperationsRenderer;
|
return pageOperationsRenderer;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
|||||||
import {
|
import {
|
||||||
DeleteIcon,
|
DeleteIcon,
|
||||||
DeletePermanentlyIcon,
|
DeletePermanentlyIcon,
|
||||||
|
DuplicateIcon,
|
||||||
EditIcon,
|
EditIcon,
|
||||||
FavoritedIcon,
|
FavoritedIcon,
|
||||||
FavoriteIcon,
|
FavoriteIcon,
|
||||||
@@ -39,6 +40,7 @@ export interface PageOperationCellProps {
|
|||||||
link: string;
|
link: string;
|
||||||
onToggleFavoritePage: () => void;
|
onToggleFavoritePage: () => void;
|
||||||
onRemoveToTrash: () => void;
|
onRemoveToTrash: () => void;
|
||||||
|
onDuplicate: () => void;
|
||||||
onDisablePublicSharing: () => void;
|
onDisablePublicSharing: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +50,7 @@ export const PageOperationCell = ({
|
|||||||
link,
|
link,
|
||||||
onToggleFavoritePage,
|
onToggleFavoritePage,
|
||||||
onRemoveToTrash,
|
onRemoveToTrash,
|
||||||
|
onDuplicate,
|
||||||
onDisablePublicSharing,
|
onDisablePublicSharing,
|
||||||
}: PageOperationCellProps) => {
|
}: PageOperationCellProps) => {
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
@@ -98,6 +101,18 @@ export const PageOperationCell = ({
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<MenuItem
|
||||||
|
preFix={
|
||||||
|
<MenuIcon>
|
||||||
|
<DuplicateIcon />
|
||||||
|
</MenuIcon>
|
||||||
|
}
|
||||||
|
onSelect={onDuplicate}
|
||||||
|
>
|
||||||
|
{t['com.affine.header.option.duplicate']()}
|
||||||
|
</MenuItem>
|
||||||
|
|
||||||
<MoveToTrash data-testid="move-to-trash" onSelect={onRemoveToTrash} />
|
<MoveToTrash data-testid="move-to-trash" onSelect={onRemoveToTrash} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ export function useBlockSuiteMetaHelper(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const duplicate = useAsyncCallback(
|
const duplicate = useAsyncCallback(
|
||||||
async (pageId: string) => {
|
async (pageId: string, openPageAfterDuplication: boolean = true) => {
|
||||||
const currentPageMeta = getPageMeta(pageId);
|
const currentPageMeta = getPageMeta(pageId);
|
||||||
const newPage = createPage();
|
const newPage = createPage();
|
||||||
const currentPage = blockSuiteWorkspace.getPage(pageId);
|
const currentPage = blockSuiteWorkspace.getPage(pageId);
|
||||||
@@ -164,9 +164,18 @@ export function useBlockSuiteMetaHelper(
|
|||||||
tags: currentPageMeta.tags,
|
tags: currentPageMeta.tags,
|
||||||
favorite: currentPageMeta.favorite,
|
favorite: currentPageMeta.favorite,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const lastDigitRegex = /\((\d+)\)$/;
|
||||||
|
const match = currentPageMeta.title.match(lastDigitRegex);
|
||||||
|
const newNumber = match ? parseInt(match[1], 10) + 1 : 1;
|
||||||
|
|
||||||
|
const newPageTitle =
|
||||||
|
currentPageMeta.title.replace(lastDigitRegex, '') + `(${newNumber})`;
|
||||||
|
|
||||||
setPageMode(newPage.id, currentMode);
|
setPageMode(newPage.id, currentMode);
|
||||||
setPageTitle(newPage.id, `${currentPageMeta.title}(1)`);
|
setPageTitle(newPage.id, newPageTitle);
|
||||||
openPage(blockSuiteWorkspace.id, newPage.id);
|
|
||||||
|
openPageAfterDuplication && openPage(blockSuiteWorkspace.id, newPage.id);
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
blockSuiteWorkspace,
|
blockSuiteWorkspace,
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ export const TrashPage = () => {
|
|||||||
permanentlyDeletePage(page.id);
|
permanentlyDeletePage(page.id);
|
||||||
toast(t['com.affine.toastMessage.permanentlyDeleted']());
|
toast(t['com.affine.toastMessage.permanentlyDeleted']());
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TrashOperationCell
|
<TrashOperationCell
|
||||||
onPermanentlyDeletePage={onPermanentlyDeletePage}
|
onPermanentlyDeletePage={onPermanentlyDeletePage}
|
||||||
|
|||||||
Reference in New Issue
Block a user