Skip to content

Commit 85ca9ac

Browse files
committed
fixup! ✨(frontend) interlinking custom inline content
1 parent 51fd6d5 commit 85ca9ac

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/* eslint-disable react-hooks/rules-of-hooks */
22
import { createReactInlineContentSpec } from '@blocknote/react';
3+
import { useEffect } from 'react';
34
import { css } from 'styled-components';
45

56
import { StyledLink, Text } from '@/components';
67
import { useCunninghamTheme } from '@/cunningham';
78
import SelectedPageIcon from '@/docs/doc-editor/assets/doc-selected.svg';
9+
import { useDoc } from '@/docs/doc-management';
810

911
export const InterlinkingLinkInlineContent = createReactInlineContentSpec(
1012
{
@@ -13,15 +15,32 @@ export const InterlinkingLinkInlineContent = createReactInlineContentSpec(
1315
url: {
1416
default: '',
1517
},
18+
docId: {
19+
default: '',
20+
},
1621
title: {
1722
default: '',
1823
},
1924
},
2025
content: 'none',
2126
},
2227
{
23-
render: (props) => {
24-
return <LinkSelected {...props.inlineContent.props} />;
28+
render: ({ inlineContent, updateInlineContent }) => {
29+
const { data: doc } = useDoc({ id: inlineContent.props.docId });
30+
31+
useEffect(() => {
32+
if (doc?.title && doc.title !== inlineContent.props.title) {
33+
updateInlineContent({
34+
type: 'interlinkingLinkInline',
35+
props: {
36+
...inlineContent.props,
37+
title: doc.title,
38+
},
39+
});
40+
}
41+
}, [inlineContent.props, doc?.title, updateInlineContent]);
42+
43+
return <LinkSelected {...inlineContent.props} />;
2544
},
2645
},
2746
);

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ import {
2525
} from '@/docs/doc-editor';
2626
import FoundPageIcon from '@/docs/doc-editor/assets/doc-found.svg';
2727
import AddPageIcon from '@/docs/doc-editor/assets/doc-plus.svg';
28-
import { useCreateChildDocTree, useDocStore } from '@/docs/doc-management';
28+
import {
29+
useCreateChildDocTree,
30+
useDocStore,
31+
useTrans,
32+
} from '@/docs/doc-management';
2933
import { DocSearchSubPageContent, DocSearchTarget } from '@/docs/doc-search';
3034
import { useResponsiveStore } from '@/stores';
3135

@@ -78,6 +82,7 @@ export const SearchPage = ({
7882
const inputRef = useRef<HTMLInputElement>(null);
7983
const [search, setSearch] = useState('');
8084
const { isDesktop } = useResponsiveStore();
85+
const { untitledDocument } = useTrans();
8186

8287
/**
8388
* createReactInlineContentSpec add automatically the focus after
@@ -195,7 +200,8 @@ export const SearchPage = ({
195200
type: 'interlinkingLinkInline',
196201
props: {
197202
url: `/docs/${doc.id}`,
198-
title: doc.title || '',
203+
docId: doc.id,
204+
title: doc.title || untitledDocument,
199205
},
200206
},
201207
' ',

0 commit comments

Comments
 (0)