Skip to content

Commit 5ed6abd

Browse files
committed
✨(frontend) create page from dropdown search
We are now able to create a new page from the dropdown search.
1 parent 6c9c036 commit 5ed6abd

File tree

6 files changed

+82
-38
lines changed

6 files changed

+82
-38
lines changed

src/frontend/apps/impress/src/components/BoxButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ const BoxButton = forwardRef<HTMLDivElement, BoxButtonType>(
3131
$background="none"
3232
$margin="none"
3333
$padding="none"
34+
$hasTransition
3435
$css={css`
3536
cursor: ${props.disabled ? 'not-allowed' : 'pointer'};
3637
border: none;
3738
outline: none;
38-
transition: all 0.2s ease-in-out;
3939
font-family: inherit;
4040
4141
color: ${props.disabled
Loading

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-inline-content/Interlinking/InterlinkingSearchInlineContent.tsx

+8-37
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
/* eslint-disable react-hooks/rules-of-hooks */
22
import { createReactInlineContentSpec } from '@blocknote/react';
3-
import { useTreeContext } from '@gouvfr-lasuite/ui-kit';
43
import { TFunction } from 'i18next';
5-
import { useRouter } from 'next/navigation';
6-
import { useCallback } from 'react';
74

85
import { DocsBlockNoteEditor } from '@/docs/doc-editor';
96
import LinkPageIcon from '@/docs/doc-editor/assets/doc-link.svg';
107
import AddPageIcon from '@/docs/doc-editor/assets/doc-plus.svg';
11-
import { Doc, useCreateChildDoc, useDocStore } from '@/docs/doc-management';
8+
import { useCreateChildDocTree, useDocStore } from '@/docs/doc-management';
129

1310
import { SearchPage } from './SearchPage';
1411

@@ -29,12 +26,12 @@ export const InterlinkingSearchInlineContent = createReactInlineContentSpec(
2926
return null;
3027
}
3128

32-
return <SearchPage {...props} />;
29+
return <SearchPage {...props} contentRef={props.contentRef} />;
3330
},
3431
},
3532
);
3633

37-
export const getInterlinkingMenuItems = (
34+
export const getInterlinkinghMenuItems = (
3835
editor: DocsBlockNoteEditor,
3936
t: TFunction<'translation', undefined>,
4037
group: string,
@@ -68,37 +65,11 @@ export const getInterlinkingMenuItems = (
6865
];
6966

7067
export const useGetInterlinkingMenuItems = () => {
71-
const treeContext = useTreeContext<Doc>();
72-
const router = useRouter();
7368
const { currentDoc } = useDocStore();
69+
const createChildDoc = useCreateChildDocTree(currentDoc?.id);
7470

75-
const { mutate: createChildDoc } = useCreateChildDoc({
76-
onSuccess: (createdDoc) => {
77-
const newDoc = {
78-
...createdDoc,
79-
children: [],
80-
childrenCount: 0,
81-
parentId: currentDoc?.id ?? undefined,
82-
};
83-
treeContext?.treeData.addChild(currentDoc?.id || null, newDoc);
84-
85-
router.push(`/docs/${newDoc.id}`);
86-
treeContext?.treeData.setSelectedNode(createdDoc);
87-
},
88-
});
89-
90-
return useCallback(
91-
(editor: DocsBlockNoteEditor, t: TFunction<'translation', undefined>) =>
92-
getInterlinkingMenuItems(
93-
editor,
94-
t,
95-
t('Links'),
96-
() =>
97-
currentDoc?.id &&
98-
createChildDoc({
99-
parentId: currentDoc.id,
100-
}),
101-
),
102-
[createChildDoc, currentDoc?.id],
103-
);
71+
return (
72+
editor: DocsBlockNoteEditor,
73+
t: TFunction<'translation', undefined>,
74+
) => getInterlinkinghMenuItems(editor, t, t('Links'), createChildDoc);
10475
};

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-inline-content/Interlinking/SearchPage.tsx

+34
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import {
55
} from '@blocknote/core';
66
import { useBlockNoteEditor } from '@blocknote/react';
77
import { useEffect, useRef, useState } from 'react';
8+
import { useTranslation } from 'react-i18next';
89
import { css } from 'styled-components';
910

1011
import {
1112
Box,
13+
BoxButton,
1214
Card,
1315
Icon,
1416
QuickSearch,
@@ -22,6 +24,8 @@ import {
2224
DocsStyleSchema,
2325
} from '@/docs/doc-editor';
2426
import FoundPageIcon from '@/docs/doc-editor/assets/doc-found.svg';
27+
import AddPageIcon from '@/docs/doc-editor/assets/doc-plus.svg';
28+
import { useCreateChildDocTree, useDocStore } from '@/docs/doc-management';
2529
import { DocSearchSubPageContent, DocSearchTarget } from '@/docs/doc-search';
2630

2731
const inputStyle = css`
@@ -62,6 +66,9 @@ export const SearchPage = ({
6266
DocsInlineContentSchema,
6367
DocsStyleSchema
6468
>();
69+
const { t } = useTranslation();
70+
const { currentDoc } = useDocStore();
71+
const createChildDoc = useCreateChildDocTree(currentDoc?.id);
6572
const inputRef = useRef<HTMLInputElement>(null);
6673
const [search, setSearch] = useState('');
6774

@@ -211,6 +218,33 @@ export const SearchPage = ({
211218
/>
212219
)}
213220
/>
221+
<Box
222+
$css={css`
223+
border-top: 1px solid var(--c--theme--colors--greyscale-200);
224+
`}
225+
>
226+
<BoxButton
227+
$direction="row"
228+
$gap="0.4rem"
229+
$align="center"
230+
$padding={{ vertical: '0.5rem', horizontal: '0.3rem' }}
231+
$css={css`
232+
&:hover {
233+
background-color: var(--c--theme--colors--greyscale-100);
234+
}
235+
`}
236+
onClick={createChildDoc}
237+
$hasTransition={false}
238+
>
239+
<AddPageIcon />
240+
<Text
241+
$size="14px"
242+
$color="var(--c--theme--colors--greyscale-1000)"
243+
>
244+
{t('Add a new page')}
245+
</Text>
246+
</BoxButton>
247+
</Box>
214248
</Card>
215249
</QuickSearch>
216250
</Box>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './useCollaboration';
2+
export * from './useCreateChildDocTree';
23
export * from './useTrans';
34
export * from './useCopyDocLink';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { useTreeContext } from '@gouvfr-lasuite/ui-kit';
2+
import { useRouter } from 'next/navigation';
3+
4+
import { useCreateChildDoc } from '../api';
5+
import { Doc } from '../types';
6+
7+
export const useCreateChildDocTree = (parentId?: string) => {
8+
const treeContext = useTreeContext<Doc>();
9+
const router = useRouter();
10+
11+
const { mutate: createChildDoc } = useCreateChildDoc({
12+
onSuccess: (createdDoc) => {
13+
const newDoc = {
14+
...createdDoc,
15+
children: [],
16+
childrenCount: 0,
17+
parentId: parentId ?? undefined,
18+
};
19+
treeContext?.treeData.addChild(parentId || null, newDoc);
20+
21+
router.push(`/docs/${newDoc.id}`);
22+
treeContext?.treeData.setSelectedNode(createdDoc);
23+
},
24+
});
25+
26+
return () => {
27+
if (!parentId) {
28+
return null;
29+
}
30+
31+
createChildDoc({
32+
parentId,
33+
});
34+
};
35+
};

0 commit comments

Comments
 (0)