diff --git a/apps/client/src/widgets/dialogs/add_link.tsx b/apps/client/src/widgets/dialogs/add_link.tsx index 538c16683..0a69794ed 100644 --- a/apps/client/src/widgets/dialogs/add_link.tsx +++ b/apps/client/src/widgets/dialogs/add_link.tsx @@ -13,6 +13,7 @@ import note_autocomplete, { Suggestion } from "../../services/note_autocomplete" import type { default as TextTypeWidget } from "../type_widgets/editable_text.js"; import { logError } from "../../services/ws"; import FormGroup from "../react/FormGroup.js"; +import { refToJQuerySelector } from "../react/react_utils"; type LinkType = "reference-link" | "external-link" | "hyper-link"; @@ -26,7 +27,7 @@ function AddLinkDialogComponent({ text: _text, textTypeWidget }: AddLinkDialogPr const [ linkTitle, setLinkTitle ] = useState(""); const hasSelection = textTypeWidget?.hasSelection(); const [ linkType, setLinkType ] = useState(hasSelection ? "hyper-link" : "reference-link"); - const [ suggestion, setSuggestion ] = useState(null); + const [ suggestion, setSuggestion ] = useState(null); async function setDefaultLinkTitle(noteId: string) { const noteTitle = await tree.getNoteTitle(noteId); @@ -60,7 +61,7 @@ function AddLinkDialogComponent({ text: _text, textTypeWidget }: AddLinkDialogPr }, [suggestion]); function onShown() { - const $autocompleteEl = $(autocompleteRef.current); + const $autocompleteEl = refToJQuerySelector(autocompleteRef); if (!text) { note_autocomplete.showRecentNotes($autocompleteEl); } else { @@ -74,11 +75,11 @@ function AddLinkDialogComponent({ text: _text, textTypeWidget }: AddLinkDialogPr } function onSubmit() { - if (suggestion.notePath) { + if (suggestion?.notePath) { // Handle note link closeActiveDialog(); textTypeWidget?.addLink(suggestion.notePath, linkType === "reference-link" ? null : linkTitle); - } else if (suggestion.externalLink) { + } else if (suggestion?.externalLink) { // Handle external link closeActiveDialog(); textTypeWidget?.addLink(suggestion.externalLink, linkTitle, true); diff --git a/apps/client/src/widgets/dialogs/clone_to.tsx b/apps/client/src/widgets/dialogs/clone_to.tsx index 66d3177c7..49da990a3 100644 --- a/apps/client/src/widgets/dialogs/clone_to.tsx +++ b/apps/client/src/widgets/dialogs/clone_to.tsx @@ -17,15 +17,19 @@ import toast from "../../services/toast"; import NoteList from "../react/NoteList"; interface CloneToDialogProps { - clonedNoteIds: string[]; + clonedNoteIds?: string[]; } function CloneToDialogComponent({ clonedNoteIds }: CloneToDialogProps) { const [ prefix, setPrefix ] = useState(""); - const [ suggestion, setSuggestion ] = useState(null); + const [ suggestion, setSuggestion ] = useState(null); const autoCompleteRef = useRef(null); function onSubmit() { + if (!clonedNoteIds) { + return; + } + const notePath = suggestion?.notePath; if (!notePath) { logError(t("clone_to.no_path_to_clone_to")); @@ -64,7 +68,7 @@ function CloneToDialogComponent({ clonedNoteIds }: CloneToDialogProps) { export default class CloneToDialog extends ReactBasicWidget { - private props: CloneToDialogProps; + private props: CloneToDialogProps = {}; get component() { return ; @@ -75,7 +79,7 @@ export default class CloneToDialog extends ReactBasicWidget { noteIds = [appContext.tabManager.getActiveContextNoteId() ?? ""]; } - const clonedNoteIds = []; + const clonedNoteIds: string[] = []; for (const noteId of noteIds) { if (!clonedNoteIds.includes(noteId)) { diff --git a/apps/client/src/widgets/dialogs/confirm.tsx b/apps/client/src/widgets/dialogs/confirm.tsx index a58d34af4..2b731414a 100644 --- a/apps/client/src/widgets/dialogs/confirm.tsx +++ b/apps/client/src/widgets/dialogs/confirm.tsx @@ -20,6 +20,7 @@ function ConfirmDialogComponent({ title, message, callback, lastElementToFocus, return ( { froca.getNotes(noteIdsToBeDeleted).then(async (notes: FNote[]) => { - const noteLinks = []; + const noteLinks: string[] = []; for (const note of notes) { noteLinks.push((await link.createLink(note.noteId, { showNotePath: true })).html()); @@ -121,7 +121,9 @@ function BrokenRelations({ brokenRelations }: { brokenRelations: DeleteNotesPrev const [ notesWithBrokenRelations, setNotesWithBrokenRelations ] = useState([]); useEffect(() => { - const noteIds = brokenRelations.map(relation => relation.noteId); + const noteIds = brokenRelations + .map(relation => relation.noteId) + .filter(noteId => noteId) as string[]; froca.getNotes(noteIds).then(async (notes) => { const notesWithBrokenRelations: BrokenRelationData[] = []; for (const attr of brokenRelations) { @@ -142,7 +144,7 @@ function BrokenRelations({ brokenRelations }: { brokenRelations: DeleteNotesPrev {brokenRelations.map((_, index) => { return (
  • - + ) }} />
  • ); })} diff --git a/apps/client/src/widgets/dialogs/incorrect_cpu_arch.tsx b/apps/client/src/widgets/dialogs/incorrect_cpu_arch.tsx index 7b8675861..e00e28eaa 100644 --- a/apps/client/src/widgets/dialogs/incorrect_cpu_arch.tsx +++ b/apps/client/src/widgets/dialogs/incorrect_cpu_arch.tsx @@ -1,5 +1,5 @@ import { useRef } from "react"; -import { openDialog } from "../../services/dialog.js"; +import { closeActiveDialog, openDialog } from "../../services/dialog.js"; import { t } from "../../services/i18n.js"; import utils from "../../services/utils.js"; import Button from "../react/Button.js"; @@ -31,7 +31,7 @@ function IncorrectCpuArchDialogComponent() { } }}/>