diff --git a/app/editor/components/LinkEditor.tsx b/app/editor/components/LinkEditor.tsx index beab3a47c6..85b8239937 100644 --- a/app/editor/components/LinkEditor.tsx +++ b/app/editor/components/LinkEditor.tsx @@ -70,7 +70,7 @@ const LinkEditor: React.FC = ({ React.useCallback(async () => { const res = await client.post("/suggestions.mention", { query }); res.data.documents.map(documents.add); - }, [query]) + }, [query, documents.add]) ); useEffect(() => { @@ -79,6 +79,22 @@ const LinkEditor: React.FC = ({ } }, [trimmedQuery, request]); + const save = React.useCallback( + (href: string, title?: string) => { + href = href.trim(); + + if (href.length === 0) { + return; + } + + discardRef.current = true; + href = sanitizeUrl(href) ?? ""; + + onSelectLink({ href, title, from, to }); + }, + [onSelectLink, from, to] + ); + useEffect(() => { const handleGlobalKeyDown = (event: KeyboardEvent) => { if (event.key === "k" && event.metaKey) { @@ -107,20 +123,7 @@ const LinkEditor: React.FC = ({ save(trimmedQuery, trimmedQuery); }; - }, [trimmedQuery, initialValue]); - - const save = (href: string, title?: string) => { - href = href.trim(); - - if (href.length === 0) { - return; - } - - discardRef.current = true; - href = sanitizeUrl(href) ?? ""; - - onSelectLink({ href, title, from, to }); - }; + }, [trimmedQuery, initialValue, handleRemoveLink, save]); const moveSelectionToEnd = () => { const { state, dispatch } = view; @@ -195,7 +198,7 @@ const LinkEditor: React.FC = ({ } }; - const handleRemoveLink = () => { + const handleRemoveLink = React.useCallback(() => { discardRef.current = true; const { state, dispatch } = view; @@ -203,9 +206,12 @@ const LinkEditor: React.FC = ({ dispatch(state.tr.removeMark(from, to, mark)); } - onRemoveLink?.(); + if (onRemoveLink) { + onRemoveLink(); + } + view.focus(); - }; + }, [view, mark, from, to, onRemoveLink]); const isInternal = isInternalUrl(query); const hasResults = !!results.length; diff --git a/app/editor/components/MentionMenu.tsx b/app/editor/components/MentionMenu.tsx index f20a597b1b..7731856d2e 100644 --- a/app/editor/components/MentionMenu.tsx +++ b/app/editor/components/MentionMenu.tsx @@ -184,7 +184,16 @@ function MentionMenu({ search, isActive, ...rest }: Props) { setItems(items); setLoaded(true); } - }, [t, actorId, loading, search, users, documents, maxResultsInSection]); + }, [ + t, + actorId, + loading, + search, + users, + documents, + maxResultsInSection, + collections, + ]); const handleSelect = useCallback( async (item: MentionItem) => { diff --git a/plugins/notion/client/Imports.tsx b/plugins/notion/client/Imports.tsx index 8d5766aa91..af7f3b8853 100644 --- a/plugins/notion/client/Imports.tsx +++ b/plugins/notion/client/Imports.tsx @@ -55,7 +55,15 @@ export const Notion = observer(() => { onClose: clearQueryParams, }); } - }, [t, dialogs, oauthSuccess, service, clearQueryParams]); + }, [ + t, + dialogs, + oauthSuccess, + service, + clearQueryParams, + handleSubmit, + integrationId, + ]); React.useEffect(() => { if (!oauthError) { diff --git a/plugins/notion/client/components/ImportDialog.tsx b/plugins/notion/client/components/ImportDialog.tsx index ecd66b8bac..3c4937d77f 100644 --- a/plugins/notion/client/components/ImportDialog.tsx +++ b/plugins/notion/client/components/ImportDialog.tsx @@ -52,7 +52,15 @@ export function ImportDialog({ integrationId, onSubmit }: Props) { toast.error(err.message); resetSubmitting(); } - }, [permission, onSubmit]); + }, [ + permission, + onSubmit, + integrationId, + t, + imports, + resetSubmitting, + setSubmitting, + ]); return (