diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index 48f5707563..8717ecac23 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -2291,6 +2291,7 @@ }, "active_content_badges": { "type_icon_pack": "Icon pack", + "type_backend_script": "Backend script", "toggle_tooltip_enable_tooltip": "Click to enable this {{type}}.", "toggle_tooltip_disable_tooltip": "Click to disable this {{type}}." } diff --git a/apps/client/src/widgets/layout/ActiveContentBadges.tsx b/apps/client/src/widgets/layout/ActiveContentBadges.tsx index 6f93ada5cb..dc867d8828 100644 --- a/apps/client/src/widgets/layout/ActiveContentBadges.tsx +++ b/apps/client/src/widgets/layout/ActiveContentBadges.tsx @@ -11,34 +11,50 @@ import { useNoteContext, useTriliumEvent } from "../react/hooks"; const DANGEROUS_ATTRIBUTES = BUILTIN_ATTRIBUTES.filter(a => a.isDangerous); const activeContentLabels = [ "iconPack" ] as const; +const typeIconMappings: Record = { + iconPack: "bx bx-package", + backendScript: "bx bx-server" +}; + export function ActiveContentBadges() { const { note } = useNoteContext(); const info = useActiveContentInfo(note); return (note && info && <> - {info.type === "iconPack" && } + ); } -function IconPackBadge() { +function ActiveContentBadge({ info }: { note: FNote, info: ActiveContentInfo }) { return ( ); } +function getTranslationForType(type: ActiveContentInfo["type"]) { + switch (type) { + case "iconPack": + return t("active_content_badges.type_icon_pack"); + case "backendScript": + return t("active_content_badges.type_backend_script"); + } +} + function ActiveContentToggle({ note, info }: { note: FNote, info: ActiveContentInfo }) { + const typeTranslation = getTranslationForType(info.type); + return info && { const attrs = note.getOwnedAttributes() .filter(attr => { @@ -65,7 +81,7 @@ function getNameWithoutPrefix(name: string) { } interface ActiveContentInfo { - type: "iconPack"; + type: "iconPack" | "backendScript"; isEnabled: boolean; } @@ -81,6 +97,10 @@ function useActiveContentInfo(note: FNote | null | undefined) { return; } + if (note.type === "code" && note.mime === "application/javascript;env=backend") { + type = "backendScript"; + } + for (const labelToCheck of activeContentLabels ) { if (note.hasLabel(labelToCheck)) { type = labelToCheck;