Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(client): flash the sidebar section a badge press lands on
Elian Doran7ebc2362343f
diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.css b/apps/client/src/widgets/sidebar/RightPanelContainer.cssindex e4a36f94b9..2d9bf03b99 100644--- a/apps/client/src/widgets/sidebar/RightPanelContainer.css+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.css@@ -165,6 +165,28 @@ body.experimental-feature-new-layout #right-pane {transform: rotate(-90deg);}+ /* Where a press from outside the pane (the status bar's connection badges) landed: the card+ is named by a flash that fades out, since the sections of a tab look much alike and the+ scroll that brings one into view can be a few pixels or none at all. A layer over the card+ rather than its own background, which is left to whatever the theme makes it — the card is+ `overflow: hidden` (above), so the layer keeps to it. */+ &.highlighted {+ position: relative;++ &::after {+ content: "";+ position: absolute;+ inset: 0;+ z-index: 1;+ pointer-events: none;+ background: var(--active-item-background-color);+ /* Where the animation leaves it, and where it stands should there be none at all+ (the layer is otherwise a cover rather than a flash). */+ opacity: 0;+ animation: right-pane-widget-highlight 1s ease-out;+ }+ }+/* The only widget of a tab has no chevron (see RightPanelWidget.tsx): its header is notsomething to press, and its title takes over where the chevron would have started. */&.not-collapsible .card-header {@@ -283,6 +305,12 @@ body.experimental-feature-new-layout #right-pane {}}+/* A wash rather than a cover: what is in the card stays readable throughout the flash. */+@keyframes right-pane-widget-highlight {+ from { opacity: 0.4; }+ to { opacity: 0; }+}+/* Backdrop effects are disabled, so peek mode needs a solid background. */body.experimental-feature-new-layout.backdrop-effects-disabled #right-pane.right-pane-mode-peek {background: var(--right-pane-background-color);diff --git a/apps/client/src/widgets/sidebar/RightPanelWidget.spec.tsx b/apps/client/src/widgets/sidebar/RightPanelWidget.spec.tsxindex ef4420668c..03f73563a3 100644--- a/apps/client/src/widgets/sidebar/RightPanelWidget.spec.tsx+++ b/apps/client/src/widgets/sidebar/RightPanelWidget.spec.tsx@@ -78,15 +78,28 @@ describe("RightPanelWidget", () => {await renderWith({ id: "shared", counter: 2 });expect(card("shared")?.className).not.toContain("collapsed");- // A widget the request opens is scrolled to once the body it opened is laid out; one that was- // open all along is scrolled to on the spot, which is all such a press amounts to.+ // A widget the request opens is scrolled to and flashed once the body it opened is laid out;+ // one that was open all along gets both on the spot, which is all such a press amounts to.const scrollIntoView = vi.fn();const solitary = card("solitary");if (solitary) solitary.scrollIntoView = scrollIntoView;await renderWith({ id: "solitary", counter: 3 });expect(card("solitary")?.className).not.toContain("collapsed");expect(scrollIntoView).toHaveBeenCalledTimes(1);+ expect(card("solitary")?.className).toContain("highlighted");++ // The flash lasts as long as its animation, and the card's own — not one from within it.+ await act(async () => { card("solitary")?.querySelector(".card-body")?.dispatchEvent(animationEnd()); });+ expect(card("solitary")?.className).toContain("highlighted");+ await act(async () => { card("solitary")?.dispatchEvent(animationEnd()); });+ expect(card("solitary")?.className).not.toContain("highlighted");+await renderWith({ id: "solitary", counter: 4 });expect(scrollIntoView).toHaveBeenCalledTimes(2);+ expect(card("solitary")?.className).toContain("highlighted");});});++function animationEnd() {+ return new Event("animationend", { bubbles: true });+}diff --git a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx b/apps/client/src/widgets/sidebar/RightPanelWidget.tsxindex cd33cb360f..1971f7ba9e 100644--- a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx+++ b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx@@ -55,6 +55,7 @@ export default function RightPanelWidget({ id, title, buttons, children, containconst [ rightPaneCollapsedItems, setRightPaneCollapsedItems ] = useTriliumOptionJson<string[]>("rightPaneCollapsedItems");const [ collapsedByUser, setCollapsedByUser ] = useState(rightPaneCollapsedItems.includes(id));const [ scrollPending, setScrollPending ] = useState(false);+ const [ highlighted, setHighlighted ] = useState(false);const containerRef = useSyncedRef<HTMLDivElement>(externalContainerRef, null);const parentComponent = useContext(ParentComponent);const collapsible = useContext(CollapsibleWidgets);@@ -77,11 +78,13 @@ export default function RightPanelWidget({ id, title, buttons, children, contain// eslint-disable-next-line react-hooks/exhaustive-deps}, [ expandRequest, id ]);- // Scrolled to only once the body it opened is laid out, hence the pass of its own — which is also- // all such a press amounts to for a widget that was open all along but out of sight below the rest.+ // Scrolled to and flashed once the body it opened is laid out, hence the pass of its own. The flash+ // is what says which section answered: a tab holds several, one much like the next, and a press+ // that lands on a widget already open and in view would otherwise pass unnoticed.useEffect(() => {if (!scrollPending || !expanded) return;containerRef.current?.scrollIntoView({ block: "nearest" });+ setHighlighted(true);setScrollPending(false);}, [ scrollPending, expanded, containerRef ]);@@ -96,8 +99,14 @@ export default function RightPanelWidget({ id, title, buttons, children, containclass={clsx("card widget", {collapsed: !expanded,"not-collapsible": !collapsible,- grow+ grow,+ highlighted})}+ // The flash lasts as long as its animation (see RightPanelContainer.css) rather than a+ // duration kept in step here; a bubbled one from something within the widget is not it.+ onAnimationEnd={(e) => {+ if (e.target === containerRef.current) setHighlighted(false);+ }}><divclass="card-header"