mirror of
https://github.com/zadam/trilium.git
synced 2025-11-13 09:59:02 +01:00
feat(board/promoted_attributes): react to changes
This commit is contained in:
parent
76f791da93
commit
3c42577da4
@ -1,5 +1,8 @@
|
|||||||
|
import { useState } from "preact/hooks";
|
||||||
import FNote from "../../entities/fnote";
|
import FNote from "../../entities/fnote";
|
||||||
import "./PromotedAttributesDisplay.css";
|
import "./PromotedAttributesDisplay.css";
|
||||||
|
import { useTriliumEvent } from "../react/hooks";
|
||||||
|
import attributes from "../../services/attributes";
|
||||||
|
|
||||||
interface PromotedAttributesDisplayProps {
|
interface PromotedAttributesDisplayProps {
|
||||||
note: FNote;
|
note: FNote;
|
||||||
@ -30,10 +33,21 @@ export default function PromotedAttributesDisplay({ note, ignoredAttributes }: P
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function useNoteAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] = []): AttributeWithDefinitions[] {
|
function useNoteAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] = []): AttributeWithDefinitions[] {
|
||||||
|
const [ promotedDefinitionAttributes, setPromotedDefinitionAttributes ] = useState<AttributeWithDefinitions[]>(getAttributesWithDefinitions(note, attributesToIgnore));
|
||||||
|
|
||||||
|
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
|
||||||
|
if (loadResults.getAttributeRows().some(attr => attributes.isAffecting(attr, note))) {
|
||||||
|
setPromotedDefinitionAttributes(getAttributesWithDefinitions(note, attributesToIgnore));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return promotedDefinitionAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] = []): AttributeWithDefinitions[] {
|
||||||
const promotedDefinitionAttributes = note.getPromotedDefinitionAttributes();
|
const promotedDefinitionAttributes = note.getPromotedDefinitionAttributes();
|
||||||
const result: AttributeWithDefinitions[] = [];
|
const result: AttributeWithDefinitions[] = [];
|
||||||
|
|
||||||
for (const attr of promotedDefinitionAttributes) {
|
for (const attr of promotedDefinitionAttributes) {
|
||||||
const def = attr.getDefinition();
|
const def = attr.getDefinition();
|
||||||
const [ type, name ] = attr.name.split(":", 2);
|
const [ type, name ] = attr.name.split(":", 2);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user