Skip to content

Build your personal knowledge base with Trilium Notes

refactor(react/dialogs): solve client errors

Elian Dorand3519b305983
diff --git a/apps/client/src/services/note_autocomplete.ts b/apps/client/src/services/note_autocomplete.ts
index a95f4083eb..1138b191e7 100644
--- a/apps/client/src/services/note_autocomplete.ts
+++ b/apps/client/src/services/note_autocomplete.ts
@@ -39,7 +39,7 @@ export interface Suggestion {
}
export interface Options {
- container?: HTMLElement;
+ container?: HTMLElement | null;
fastSearch?: boolean;
allowCreatingNotes?: boolean;
allowJumpToSearchNotes?: boolean;
diff --git a/apps/client/src/widgets/dialogs/export.tsx b/apps/client/src/widgets/dialogs/export.tsx
index bb71979fb6..3543e3b358 100644
--- a/apps/client/src/widgets/dialogs/export.tsx
+++ b/apps/client/src/widgets/dialogs/export.tsx
@@ -21,7 +21,7 @@ interface ExportDialogProps {
function ExportDialogComponent() {
const [ opts, setOpts ] = useState<ExportDialogProps>();
- const [ exportType, setExportType ] = useState(opts?.defaultType ?? "subtree");
+ const [ exportType, setExportType ] = useState<string>(opts?.defaultType ?? "subtree");
const [ subtreeFormat, setSubtreeFormat ] = useState("html");
const [ singleFormat, setSingleFormat ] = useState("html");
const [ opmlVersion, setOpmlVersion ] = useState("2.0");
diff --git a/apps/client/src/widgets/dialogs/jump_to_note.tsx b/apps/client/src/widgets/dialogs/jump_to_note.tsx
index 2883055a18..6f3e8457fb 100644
--- a/apps/client/src/widgets/dialogs/jump_to_note.tsx
+++ b/apps/client/src/widgets/dialogs/jump_to_note.tsx
@@ -52,7 +52,11 @@ function JumpToNoteDialogComponent() {
setIsCommandMode(text.startsWith(">"));
}, [ text ]);
- async function onItemSelected(suggestion: Suggestion) {
+ async function onItemSelected(suggestion?: Suggestion | null) {
+ if (!suggestion) {
+ return;
+ }
+
setShown(false);
if (suggestion.notePath) {
appContext.tabManager.getActiveContext()?.setNote(suggestion.notePath);
diff --git a/apps/client/src/widgets/dialogs/recent_changes.tsx b/apps/client/src/widgets/dialogs/recent_changes.tsx
index acd3637876..0bf3b08fef 100644
--- a/apps/client/src/widgets/dialogs/recent_changes.tsx
+++ b/apps/client/src/widgets/dialogs/recent_changes.tsx
@@ -8,7 +8,7 @@ import Button from "../react/Button";
import Modal from "../react/Modal";
import ReactBasicWidget from "../react/ReactBasicWidget";
import hoisted_note from "../../services/hoisted_note";
-import type { RecentChangesRow } from "@triliumnext/commons";
+import type { RecentChangeRow } from "@triliumnext/commons";
import froca from "../../services/froca";
import { formatDateTime } from "../../utils/formatters";
import link from "../../services/link";
@@ -18,7 +18,7 @@ import useTriliumEvent from "../react/hooks";
function RecentChangesDialogComponent() {
const [ ancestorNoteId, setAncestorNoteId ] = useState<string>();
- const [ groupedByDate, setGroupedByDate ] = useState<Map<String, RecentChangesRow[]>>();
+ const [ groupedByDate, setGroupedByDate ] = useState<Map<String, RecentChangeRow[]>>();
const [ needsRefresh, setNeedsRefresh ] = useState(false);
const [ shown, setShown ] = useState(false);
@@ -34,7 +34,7 @@ function RecentChangesDialogComponent() {
setNeedsRefresh(false);
}
- server.get<RecentChangesRow[]>(`recent-changes/${ancestorNoteId}`)
+ server.get<RecentChangeRow[]>(`recent-changes/${ancestorNoteId}`)
.then(async (recentChanges) => {
// preload all notes into cache
await froca.getNotes(
@@ -78,7 +78,7 @@ function RecentChangesDialogComponent() {
)
}
-function RecentChangesTimeline({ groupedByDate, setShown }: { groupedByDate: Map<String, RecentChangesRow[]>, setShown: Dispatch<StateUpdater<boolean>> }) {
+function RecentChangesTimeline({ groupedByDate, setShown }: { groupedByDate: Map<String, RecentChangeRow[]>, setShown: Dispatch<StateUpdater<boolean>> }) {
return (
<>
{ Array.from(groupedByDate.entries()).map(([dateDay, dayChanges]) => {
@@ -129,7 +129,7 @@ function NoteLink({ notePath, title }: { notePath: string, title: string }) {
);
}
-function DeletedNoteLink({ change, setShown }: { change: RecentChangesRow, setShown: Dispatch<StateUpdater<boolean>> }) {
+function DeletedNoteLink({ change, setShown }: { change: RecentChangeRow, setShown: Dispatch<StateUpdater<boolean>> }) {
return (
<>
<span className="note-title">{change.current_title}</span>
@@ -165,8 +165,8 @@ export default class RecentChangesDialog extends ReactBasicWidget {
}
-function groupByDate(rows: RecentChangesRow[]) {
- const groupedByDate = new Map<String, RecentChangesRow[]>();
+function groupByDate(rows: RecentChangeRow[]) {
+ const groupedByDate = new Map<String, RecentChangeRow[]>();
for (const row of rows) {
const dateDay = row.date.substr(0, 10);
diff --git a/apps/client/src/widgets/react/Dropdown.tsx b/apps/client/src/widgets/react/Dropdown.tsx
index 93b558a05d..71078e21b5 100644
--- a/apps/client/src/widgets/react/Dropdown.tsx
+++ b/apps/client/src/widgets/react/Dropdown.tsx
@@ -9,8 +9,8 @@ interface DropdownProps {
}
export default function Dropdown({ className, isStatic, children }: DropdownProps) {
- const dropdownRef = useRef<HTMLDivElement>();
- const triggerRef = useRef<HTMLButtonElement>();
+ const dropdownRef = useRef<HTMLDivElement | null>(null);
+ const triggerRef = useRef<HTMLButtonElement | null>(null);
if (triggerRef?.current) {
useEffect(() => {
diff --git a/apps/client/src/widgets/react/NoteAutocomplete.tsx b/apps/client/src/widgets/react/NoteAutocomplete.tsx
index 580c000025..49656bf715 100644
--- a/apps/client/src/widgets/react/NoteAutocomplete.tsx
+++ b/apps/client/src/widgets/react/NoteAutocomplete.tsx
@@ -9,7 +9,7 @@ interface NoteAutocompleteProps {
inputRef?: RefObject<HTMLInputElement>;
text?: string;
placeholder?: string;
- container?: RefObject<HTMLDivElement>;
+ container?: RefObject<HTMLElement | null | undefined>;
containerStyle?: CSSProperties;
opts?: Omit<Options, "container">;
onChange?: (suggestion: Suggestion | null) => void;