mirror of
https://github.com/zadam/trilium.git
synced 2026-02-27 00:53:35 +01:00
fix(active_content_badges): not refreshing on type or mime update
This commit is contained in:
parent
092a60fdd9
commit
47601cd1da
@ -9,7 +9,7 @@ import { openInAppHelpFromUrl } from "../../services/utils";
|
|||||||
import { BadgeWithDropdown } from "../react/Badge";
|
import { BadgeWithDropdown } from "../react/Badge";
|
||||||
import { FormDropdownDivider, FormListItem } from "../react/FormList";
|
import { FormDropdownDivider, FormListItem } from "../react/FormList";
|
||||||
import FormToggle from "../react/FormToggle";
|
import FormToggle from "../react/FormToggle";
|
||||||
import { useNoteContext, useTriliumEvent } from "../react/hooks";
|
import { useNoteContext, useNoteProperty, useTriliumEvent } from "../react/hooks";
|
||||||
import { BookProperty, ViewProperty } from "../react/NotePropertyMenu";
|
import { BookProperty, ViewProperty } from "../react/NotePropertyMenu";
|
||||||
|
|
||||||
const NON_DANGEROUS_ACTIVE_CONTENT = [ "appCss", "appTheme" ];
|
const NON_DANGEROUS_ACTIVE_CONTENT = [ "appCss", "appTheme" ];
|
||||||
@ -213,6 +213,8 @@ function ActiveContentToggle({ note, info }: { note: FNote, info: ActiveContentI
|
|||||||
|
|
||||||
function useActiveContentInfo(note: FNote | null | undefined) {
|
function useActiveContentInfo(note: FNote | null | undefined) {
|
||||||
const [ info, setInfo ] = useState<ActiveContentInfo | null>(null);
|
const [ info, setInfo ] = useState<ActiveContentInfo | null>(null);
|
||||||
|
const noteType = useNoteProperty(note, "type");
|
||||||
|
const noteMime = useNoteProperty(note, "mime");
|
||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
let type: ActiveContentInfo["type"] | null = null;
|
let type: ActiveContentInfo["type"] | null = null;
|
||||||
@ -224,13 +226,13 @@ function useActiveContentInfo(note: FNote | null | undefined) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (note.type === "render") {
|
if (noteType === "render") {
|
||||||
type = "renderNote";
|
type = "renderNote";
|
||||||
isEnabled = note.hasRelation("renderNote");
|
isEnabled = note.hasRelation("renderNote");
|
||||||
} else if (note.type === "webView") {
|
} else if (noteType === "webView") {
|
||||||
type = "webView";
|
type = "webView";
|
||||||
isEnabled = note.hasLabel("webViewSrc");
|
isEnabled = note.hasLabel("webViewSrc");
|
||||||
} else if (note.type === "code" && note.mime === "application/javascript;env=backend") {
|
} else if (noteType === "code" && noteMime === "application/javascript;env=backend") {
|
||||||
type = "backendScript";
|
type = "backendScript";
|
||||||
for (const backendLabel of [ "run", "customRequestHandler", "customResourceProvider" ]) {
|
for (const backendLabel of [ "run", "customRequestHandler", "customResourceProvider" ]) {
|
||||||
isEnabled ||= note.hasLabel(backendLabel);
|
isEnabled ||= note.hasLabel(backendLabel);
|
||||||
@ -239,11 +241,11 @@ function useActiveContentInfo(note: FNote | null | undefined) {
|
|||||||
canToggleEnabled = true;
|
canToggleEnabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (note.type === "code" && note.mime === "application/javascript;env=frontend") {
|
} else if (noteType === "code" && noteMime === "application/javascript;env=frontend") {
|
||||||
type = "frontendScript";
|
type = "frontendScript";
|
||||||
isEnabled = note.hasLabel("widget") || note.hasLabel("run");
|
isEnabled = note.hasLabel("widget") || note.hasLabel("run");
|
||||||
canToggleEnabled = note.hasLabelOrDisabled("widget") || note.hasLabelOrDisabled("run");
|
canToggleEnabled = note.hasLabelOrDisabled("widget") || note.hasLabelOrDisabled("run");
|
||||||
} else if (note.type === "code" && note.hasLabelOrDisabled("appTheme")) {
|
} else if (noteType === "code" && note.hasLabelOrDisabled("appTheme")) {
|
||||||
isEnabled = note.hasLabel("appTheme");
|
isEnabled = note.hasLabel("appTheme");
|
||||||
canToggleEnabled = true;
|
canToggleEnabled = true;
|
||||||
}
|
}
|
||||||
@ -270,7 +272,7 @@ function useActiveContentInfo(note: FNote | null | undefined) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Refresh on note change.
|
// Refresh on note change.
|
||||||
useEffect(refresh, [ note ]);
|
useEffect(refresh, [ note, noteType, noteMime ]);
|
||||||
|
|
||||||
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
|
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
|
||||||
if (loadResults.getAttributeRows().some(attr => attributes.isAffecting(attr, note))) {
|
if (loadResults.getAttributeRows().some(attr => attributes.isAffecting(attr, note))) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user