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() { addAttributes() {
return { return {
organizationId: {
default: '',
parseHTML: getDatasetAttribute('organizationId'),
},
wikiId: { wikiId: {
default: '', default: '',
parseHTML: getDatasetAttribute('wikiId'), parseHTML: getDatasetAttribute('wikiId'),

View File

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

View File

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

View File

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