@@ -5,7 +5,7 @@ import { Dropdown as BootstrapDropdown } from "bootstrap";
55import clsx from "clsx" ;
66import { type ComponentChildren , RefObject } from "preact" ;
77import { 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
1010import { CommandNames } from "../../components/app_context" ;
1111import NoteContext from "../../components/note_context" ;
@@ -338,15 +338,19 @@ interface AttributesProps extends StatusBarContext {
338338function 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