chore(status_bar): address requested changes

This commit is contained in:
Elian Doran
2025-12-13 00:43:00 +02:00
parent 4ab8af0995
commit 5bad043ed5
3 changed files with 16 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ import { Locale } from "@triliumnext/commons";
import clsx from "clsx"; import clsx from "clsx";
import { type ComponentChildren } from "preact"; import { type ComponentChildren } from "preact";
import { createPortal } from "preact/compat"; import { createPortal } from "preact/compat";
import { useContext, useMemo, useRef, useState } from "preact/hooks"; import { useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
import { CommandNames } from "../../components/app_context"; import { CommandNames } from "../../components/app_context";
import NoteContext from "../../components/note_context"; import NoteContext from "../../components/note_context";
@@ -263,6 +263,11 @@ interface AttributesProps extends StatusBarContext {
function AttributesButton({ note, attributesShown, setAttributesShown }: AttributesProps) { function AttributesButton({ note, attributesShown, setAttributesShown }: AttributesProps) {
const [ count, setCount ] = useState(note.attributes.length); const [ count, setCount ] = useState(note.attributes.length);
// React to note changes.
useEffect(() => {
setCount(note.attributes.length);
}, [ note ]);
// React to changes in count. // React to changes in count.
useTriliumEvent("entitiesReloaded", (({loadResults}) => { useTriliumEvent("entitiesReloaded", (({loadResults}) => {
if (loadResults.getAttributeRows().some(attr => attributes.isAffecting(attr, note))) { if (loadResults.getAttributeRows().some(attr => attributes.isAffecting(attr, note))) {

View File

@@ -349,9 +349,9 @@ export function useActiveNoteContext() {
useEffect(() => { useEffect(() => {
setNote(noteContext?.note); setNote(noteContext?.note);
}, [ notePath ]); }, [ noteContext ]);
useTriliumEvents([ "setNoteContext", "activeContextChanged", "noteSwitchedAndActivated", "noteSwitched" ], ({}) => { useTriliumEvents([ "setNoteContext", "activeContextChanged", "noteSwitchedAndActivated", "noteSwitched" ], () => {
const noteContext = appContext.tabManager.getActiveContext() ?? undefined; const noteContext = appContext.tabManager.getActiveContext() ?? undefined;
setNoteContext(noteContext); setNoteContext(noteContext);
setNotePath(noteContext?.notePath); setNotePath(noteContext?.notePath);

View File

@@ -17,19 +17,20 @@ export function LocaleSelector({ id, locales, currentValue, onChange, defaultLoc
const { activeLocale, processedLocales } = useProcessedLocales(locales, defaultLocale, currentValueWithDefault); const { activeLocale, processedLocales } = useProcessedLocales(locales, defaultLocale, currentValueWithDefault);
return ( return (
<Dropdown id={id} text={activeLocale?.name}> <Dropdown id={id} text={activeLocale?.name}>
{processedLocales.map(locale => { {processedLocales.map((locale, index) => (
if (typeof locale === "object") { (typeof locale === "object") ? (
return <FormListItem <FormListItem
key={locale.id}
rtl={locale.rtl} rtl={locale.rtl}
checked={locale.id === currentValue} checked={locale.id === currentValue}
onClick={() => { onClick={() => {
onChange(locale.id); onChange(locale.id);
}} }}
>{locale.name}</FormListItem> >{locale.name}</FormListItem>
} else { ) : (
return <FormDropdownDivider /> <FormDropdownDivider key={`divider-${index}`} />
} )
})} ))}
{extraChildren && ( {extraChildren && (
<> <>
<FormDropdownDivider /> <FormDropdownDivider />