tiptap: fix doc url

This commit is contained in:
fantasticit 2022-07-05 15:21:06 +08:00
parent 24f8f07f41
commit 4161d5fd2d
4 changed files with 16 additions and 8 deletions

View File

@ -25,6 +25,10 @@ export const DocumentReference = Node.create({
addAttributes() {
return {
organizationId: {
default: '',
parseHTML: getDatasetAttribute('organizationId'),
},
wikiId: {
default: '',
parseHTML: getDatasetAttribute('wikiId'),

View File

@ -33,11 +33,11 @@ export const DocumentReferenceBubbleMenu = ({ editor }) => {
const shouldShow = useCallback(() => editor.isActive(DocumentReference.name), [editor]);
const selectDoc = useCallback(
(item) => {
const { wikiId, title, id: documentId } = item;
const { organizationId, wikiId, title, id: documentId } = item;
editor
.chain()
.updateAttributes(DocumentReference.name, { wikiId, documentId, title })
.updateAttributes(DocumentReference.name, { organizationId, wikiId, documentId, title })
.setNodeSelection(editor.state.selection.from)
.focus()
.run();

View File

@ -59,8 +59,10 @@ export const DocumentChildrenWrapper = ({ editor, node, updateAttributes }) => {
<Link
key={doc.id}
href={{
pathname: `${!isShare ? '' : '/share'}/wiki/[wikiId]/document/[documentId]`,
query: { wikiId: doc.wikiId, documentId: doc.id },
pathname: isShare
? `/share/wiki/[wikiId]/document/[documentId]`
: `/app/org/[organizationId]/wiki/[wikiId]/doc/[documentId]`,
query: { organizationId: doc.organizationId, wikiId: doc.wikiId, documentId: doc.id },
}}
>
<a className={styles.itemWrap} target="_blank">

View File

@ -11,7 +11,7 @@ export const DocumentReferenceWrapper = ({ editor, node, updateAttributes }) =>
const { pathname } = useRouter();
const isShare = pathname.includes('share');
const isEditable = editor.isEditable;
const { wikiId, documentId, title } = node.attrs;
const { organizationId, wikiId, documentId, title } = node.attrs;
const content = useMemo(() => {
if (!wikiId && !documentId) {
@ -35,8 +35,10 @@ export const DocumentReferenceWrapper = ({ editor, node, updateAttributes }) =>
<Link
key={documentId}
href={{
pathname: `${!isShare ? '' : '/share'}/wiki/[wikiId]/document/[documentId]`,
query: { wikiId, documentId },
pathname: isShare
? `/share/wiki/[wikiId]/document/[documentId]`
: `/app/org/[organizationId]/wiki/[wikiId]/doc/[documentId]`,
query: { organizationId, wikiId, documentId },
}}
>
<a className={cls(styles.itemWrap, !isEditable && 'render-wrapper')} target="_blank">
@ -45,7 +47,7 @@ export const DocumentReferenceWrapper = ({ editor, node, updateAttributes }) =>
</a>
</Link>
);
}, [wikiId, documentId, isEditable, isShare, title]);
}, [organizationId, wikiId, documentId, isEditable, isShare, title]);
return (
<DragableWrapper editor={editor} as="div" className={cls(styles.wrap, isEditable && 'render-wrapper')}>