Skip to content

Commit 51513d3

Browse files
committed
fix(status_bar): count not refreshing properly after change
1 parent 13ce8cf commit 51513d3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

apps/client/src/widgets/layout/StatusBar.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Dropdown as BootstrapDropdown } from "bootstrap";
55
import clsx from "clsx";
66
import { type ComponentChildren, RefObject } from "preact";
77
import { createPortal } from "preact/compat";
8-
import { useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
8+
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
99

1010
import { CommandNames } from "../../components/app_context";
1111
import NoteContext from "../../components/note_context";
@@ -338,15 +338,19 @@ interface AttributesProps extends StatusBarContext {
338338
function AttributesButton({ note, attributesShown, setAttributesShown }: AttributesProps) {
339339
const [ count, setCount ] = useState(note.attributes.length);
340340

341+
const refreshCount = useCallback((note: FNote) => {
342+
return note.getAttributes().filter(a => !a.isAutoLink).length;
343+
}, []);
344+
341345
// React to note changes.
342346
useEffect(() => {
343-
setCount(note.getAttributes().filter(a => !a.isAutoLink).length);
344-
}, [ note ]);
347+
setCount(refreshCount(note));
348+
}, [ note, refreshCount ]);
345349

346350
// React to changes in count.
347351
useTriliumEvent("entitiesReloaded", (({loadResults}) => {
348352
if (loadResults.getAttributeRows().some(attr => attributes.isAffecting(attr, note))) {
349-
setCount(note.attributes.length);
353+
setCount(refreshCount(note));
350354
}
351355
}));
352356

0 commit comments

Comments
 (0)