mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
feat: connect pinboard and reference link (#1859)
This commit is contained in:
42
apps/web/src/hooks/affine/use-reference-link.ts
Normal file
42
apps/web/src/hooks/affine/use-reference-link.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { currentEditorAtom } from '../../atoms';
|
||||
|
||||
export function useReferenceLink(props?: {
|
||||
pageLinkClicked?: (params: { pageId: string }) => void;
|
||||
subpageLinked?: (params: { pageId: string }) => void;
|
||||
subpageUnlinked?: (params: { pageId: string }) => void;
|
||||
}) {
|
||||
const { pageLinkClicked, subpageLinked, subpageUnlinked } = props ?? {};
|
||||
const editor = useAtomValue(currentEditorAtom);
|
||||
|
||||
useEffect(() => {
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
|
||||
const linkClickedDisposable = editor.slots.pageLinkClicked.on(
|
||||
({ pageId }) => {
|
||||
pageLinkClicked?.({ pageId });
|
||||
}
|
||||
);
|
||||
|
||||
const subpageLinkedDisposable = editor.slots.subpageLinked.on(
|
||||
({ pageId }) => {
|
||||
subpageLinked?.({ pageId });
|
||||
}
|
||||
);
|
||||
const subpageUnlinkedDisposable = editor.slots.subpageUnlinked.on(
|
||||
({ pageId }) => {
|
||||
subpageUnlinked?.({ pageId });
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
linkClickedDisposable.dispose();
|
||||
subpageLinkedDisposable.dispose();
|
||||
subpageUnlinkedDisposable.dispose();
|
||||
};
|
||||
}, [editor, pageLinkClicked, subpageLinked, subpageUnlinked]);
|
||||
}
|
||||
Reference in New Issue
Block a user