Skip to content

Commit 2ec7de7

Browse files
authored
fix(core): add linked doc button (#10417)
1 parent e5e5c0a commit 2ec7de7

File tree

1 file changed

+34
-11
lines changed
  • packages/frontend/core/src/modules/explorer/views/nodes/doc

1 file changed

+34
-11
lines changed

packages/frontend/core/src/modules/explorer/views/nodes/doc/operations.tsx

+34-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
IconButton,
23
MenuItem,
34
MenuSeparator,
45
toast,
@@ -22,10 +23,11 @@ import {
2223
InformationIcon,
2324
LinkedPageIcon,
2425
OpenInNewIcon,
26+
PlusIcon,
2527
SplitViewIcon,
2628
} from '@blocksuite/icons/rc';
2729
import { useLiveData, useServices } from '@toeverything/infra';
28-
import { useCallback, useMemo } from 'react';
30+
import { useCallback, useMemo, useState } from 'react';
2931

3032
import type { NodeOperation } from '../../tree/types';
3133

@@ -52,6 +54,7 @@ export const useExplorerDocNodeOperations = (
5254
});
5355
const { openConfirmModal } = useConfirmModal();
5456

57+
const [addLinkedPageLoading, setAddLinkedPageLoading] = useState(false);
5558
const docRecord = useLiveData(docsService.list.doc$(docId));
5659

5760
const { createPage } = usePageHelper(
@@ -117,17 +120,22 @@ export const useExplorerDocNodeOperations = (
117120
}, [docId, workbenchService.workbench]);
118121

119122
const handleAddLinkedPage = useAsyncCallback(async () => {
120-
const canEdit = await guardService.can('Doc_Update', docId);
121-
if (!canEdit) {
122-
toast(t['com.affine.no-permission']());
123-
return;
123+
setAddLinkedPageLoading(true);
124+
try {
125+
const canEdit = await guardService.can('Doc_Update', docId);
126+
if (!canEdit) {
127+
toast(t['com.affine.no-permission']());
128+
return;
129+
}
130+
const newDoc = createPage();
131+
// TODO: handle timeout & error
132+
await docsService.addLinkedDoc(docId, newDoc.id);
133+
track.$.navigationPanel.docs.createDoc({ control: 'linkDoc' });
134+
track.$.navigationPanel.docs.linkDoc({ control: 'createDoc' });
135+
options.openNodeCollapsed();
136+
} finally {
137+
setAddLinkedPageLoading(false);
124138
}
125-
const newDoc = createPage();
126-
// TODO: handle timeout & error
127-
await docsService.addLinkedDoc(docId, newDoc.id);
128-
track.$.navigationPanel.docs.createDoc({ control: 'linkDoc' });
129-
track.$.navigationPanel.docs.linkDoc({ control: 'createDoc' });
130-
options.openNodeCollapsed();
131139
}, [createPage, guardService, docId, docsService, options, t]);
132140

133141
const handleToggleFavoriteDoc = useCallback(() => {
@@ -139,6 +147,20 @@ export const useExplorerDocNodeOperations = (
139147

140148
return useMemo(
141149
() => [
150+
{
151+
index: 0,
152+
inline: true,
153+
view: (
154+
<IconButton
155+
size="16"
156+
icon={<PlusIcon />}
157+
tooltip={t['com.affine.rootAppSidebar.explorer.doc-add-tooltip']()}
158+
onClick={handleAddLinkedPage}
159+
loading={addLinkedPageLoading}
160+
disabled={addLinkedPageLoading}
161+
/>
162+
),
163+
},
142164
{
143165
index: 50,
144166
view: (
@@ -233,6 +255,7 @@ export const useExplorerDocNodeOperations = (
233255
},
234256
],
235257
[
258+
addLinkedPageLoading,
236259
docId,
237260
favorite,
238261
handleAddLinkedPage,

0 commit comments

Comments
 (0)