From 1e885625f6102bc042c81391371649936bd4bde0 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 20 Dec 2025 12:58:06 +0200 Subject: [PATCH] chore(right_pane): address requested changes --- apps/client/src/widgets/react/hooks.tsx | 13 ++++++++++--- apps/client/src/widgets/sidebar/HighlightsList.tsx | 4 ++-- .../client/src/widgets/sidebar/RightPanelWidget.tsx | 5 +---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index 034e77dab..10a5983c6 100644 --- a/apps/client/src/widgets/react/hooks.tsx +++ b/apps/client/src/widgets/react/hooks.tsx @@ -22,7 +22,8 @@ import shortcuts, { Handler, removeIndividualBinding } from "../../services/shor import SpacedUpdate from "../../services/spaced_update"; import toast, { ToastOptions } from "../../services/toast"; import tree from "../../services/tree"; -import utils, { escapeRegExp, randomString, reloadFrontendApp } from "../../services/utils"; +import utils, { escapeRegExp, getErrorMessage, randomString, reloadFrontendApp } from "../../services/utils"; +import ws from "../../services/ws"; import BasicWidget, { ReactWrappedWidget } from "../basic_widget"; import NoteContextAwareWidget from "../note_context_aware_widget"; import { DragData } from "../note_tree"; @@ -168,14 +169,20 @@ export function useTriliumOption(name: OptionNames, needsRefresh?: boolean): [st const wrappedSetValue = useMemo(() => { return async (newValue: OptionValue) => { + const originalValue = value; setValue(String(newValue)); - await options.save(name, newValue); + try { + await options.save(name, newValue); + } catch (e: unknown) { + ws.logError(getErrorMessage(e)); + setValue(originalValue); + } if (needsRefresh) { reloadFrontendApp(`option change: ${name}`); } }; - }, [ name, needsRefresh ]); + }, [ name, needsRefresh, value ]); useTriliumEvent("entitiesReloaded", useCallback(({ loadResults }) => { if (loadResults.getOptionNames().includes(name)) { diff --git a/apps/client/src/widgets/sidebar/HighlightsList.tsx b/apps/client/src/widgets/sidebar/HighlightsList.tsx index 0eaeb40dc..66249f329 100644 --- a/apps/client/src/widgets/sidebar/HighlightsList.tsx +++ b/apps/client/src/widgets/sidebar/HighlightsList.tsx @@ -222,7 +222,7 @@ interface DomHighlight extends RawHighlight { function ReadOnlyTextHighlightsList() { const { noteContext } = useActiveNoteContext(); const contentEl = useContentElement(noteContext); - const highlights = extractHeadingsFromStaticHtml(contentEl); + const highlights = extractHighlightsFromStaticHtml(contentEl); const scrollToHighlight = useCallback((highlight: DomHighlight) => { highlight.element.scrollIntoView(); @@ -234,7 +234,7 @@ function ReadOnlyTextHighlightsList() { />; } -function extractHeadingsFromStaticHtml(el: HTMLElement | null) { +function extractHighlightsFromStaticHtml(el: HTMLElement | null) { if (!el) return []; const { color: defaultColor, backgroundColor: defaultBackgroundColor } = getComputedStyle(el); diff --git a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx index 4cb8aedf3..099a37089 100644 --- a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx +++ b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx @@ -5,7 +5,6 @@ import { useContext, useState } from "preact/hooks"; import contextMenu, { MenuItem } from "../../menus/context_menu"; import ActionButton from "../react/ActionButton"; import { useSyncedRef, useTriliumOptionJson } from "../react/hooks"; -import Icon from "../react/Icon"; import { ParentComponent } from "../react/react_utils"; interface RightPanelWidgetProps { @@ -47,9 +46,7 @@ export default function RightPanelWidget({ id, title, buttons, children, contain } else { rightPaneCollapsedItemsSet.add(id); } - if (rightPaneCollapsedItemsSet.size !== rightPaneCollapsedItems.length) { - setRightPaneCollapsedItems(Array.from(rightPaneCollapsedItemsSet)); - } + setRightPaneCollapsedItems(Array.from(rightPaneCollapsedItemsSet)); }} >