feat: refactor trash, page would delete from its parent's subpageIds after move to trash (#1871)

This commit is contained in:
Qi
2023-04-12 14:14:57 +08:00
committed by GitHub
parent ba4a2fc9d2
commit af04c1b889
12 changed files with 119 additions and 82 deletions
@@ -14,6 +14,7 @@ import { useAtom } from 'jotai';
import { useState } from 'react';
import { workspacePreferredModeAtom } from '../../../../atoms';
import { useMetaHelper } from '../../../../hooks/affine/use-meta-helper';
import { useCurrentPageId } from '../../../../hooks/current/use-current-page-id';
import { useCurrentWorkspace } from '../../../../hooks/current/use-current-workspace';
import {
@@ -47,7 +48,7 @@ export const EditorOptionMenu = () => {
const { favorite } = pageMeta;
const { setPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
const [openConfirm, setOpenConfirm] = useState(false);
const { removeToTrash } = useMetaHelper(blockSuiteWorkspace);
const EditMenu = (
<>
<MenuItem
@@ -118,11 +119,8 @@ export const EditorOptionMenu = () => {
open={openConfirm}
meta={pageMeta}
onConfirm={() => {
removeToTrash(pageMeta.id);
toast(t('Moved to Trash'));
setPageMeta(pageMeta.id, {
trash: true,
trashDate: +new Date(),
});
}}
onCancel={() => {
setOpenConfirm(false);
@@ -4,12 +4,10 @@ import { assertExists } from '@blocksuite/store';
import { useRouter } from 'next/router';
import { useState } from 'react';
import { useMetaHelper } from '../../../../hooks/affine/use-meta-helper';
import { useCurrentPageId } from '../../../../hooks/current/use-current-page-id';
import { useCurrentWorkspace } from '../../../../hooks/current/use-current-workspace';
import {
usePageMeta,
usePageMetaHelper,
} from '../../../../hooks/use-page-meta';
import { usePageMeta } from '../../../../hooks/use-page-meta';
export const TrashButtonGroup = () => {
// fixme(himself65): remove these hooks ASAP
@@ -22,12 +20,12 @@ export const TrashButtonGroup = () => {
meta => meta.id === pageId
);
assertExists(pageMeta);
const { setPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
const { t } = useTranslation();
const router = useRouter();
//
const { restoreFromTrash } = useMetaHelper(blockSuiteWorkspace);
const [open, setOpen] = useState(false);
const { t } = useTranslation();
return (
<>
<Button
@@ -35,7 +33,7 @@ export const TrashButtonGroup = () => {
shape="round"
style={{ marginRight: '24px' }}
onClick={() => {
setPageMeta(pageId, { trash: false });
restoreFromTrash(pageId);
}}
>
{t('Restore it')}