Skip to content

Commit 3c42577

Browse files
committed
feat(board/promoted_attributes): react to changes
1 parent 76f791d commit 3c42577

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { useState } from "preact/hooks";
12
import FNote from "../../entities/fnote";
23
import "./PromotedAttributesDisplay.css";
4+
import { useTriliumEvent } from "../react/hooks";
5+
import attributes from "../../services/attributes";
36

47
interface PromotedAttributesDisplayProps {
58
note: FNote;
@@ -30,10 +33,21 @@ export default function PromotedAttributesDisplay({ note, ignoredAttributes }: P
3033

3134
}
3235

33-
function useNoteAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] = []): AttributeWithDefinitions[] {
36+
function useNoteAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] = []): AttributeWithDefinitions[] {
37+
const [ promotedDefinitionAttributes, setPromotedDefinitionAttributes ] = useState<AttributeWithDefinitions[]>(getAttributesWithDefinitions(note, attributesToIgnore));
38+
39+
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
40+
if (loadResults.getAttributeRows().some(attr => attributes.isAffecting(attr, note))) {
41+
setPromotedDefinitionAttributes(getAttributesWithDefinitions(note, attributesToIgnore));
42+
}
43+
});
44+
45+
return promotedDefinitionAttributes;
46+
}
47+
48+
function getAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] = []): AttributeWithDefinitions[] {
3449
const promotedDefinitionAttributes = note.getPromotedDefinitionAttributes();
3550
const result: AttributeWithDefinitions[] = [];
36-
3751
for (const attr of promotedDefinitionAttributes) {
3852
const def = attr.getDefinition();
3953
const [ type, name ] = attr.name.split(":", 2);

0 commit comments

Comments
 (0)