|
| 1 | +import { useState } from "preact/hooks"; |
1 | 2 | import FNote from "../../entities/fnote"; |
2 | 3 | import "./PromotedAttributesDisplay.css"; |
| 4 | +import { useTriliumEvent } from "../react/hooks"; |
| 5 | +import attributes from "../../services/attributes"; |
3 | 6 |
|
4 | 7 | interface PromotedAttributesDisplayProps { |
5 | 8 | note: FNote; |
@@ -30,10 +33,21 @@ export default function PromotedAttributesDisplay({ note, ignoredAttributes }: P |
30 | 33 |
|
31 | 34 | } |
32 | 35 |
|
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[] { |
34 | 49 | const promotedDefinitionAttributes = note.getPromotedDefinitionAttributes(); |
35 | 50 | const result: AttributeWithDefinitions[] = []; |
36 | | - |
37 | 51 | for (const attr of promotedDefinitionAttributes) { |
38 | 52 | const def = attr.getDefinition(); |
39 | 53 | const [ type, name ] = attr.name.split(":", 2); |
|
0 commit comments