-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexpandedWidget.jsx
More file actions
68 lines (60 loc) · 2.33 KB
/
Copy pathexpandedWidget.jsx
File metadata and controls
68 lines (60 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Imports -----------------------------------------------------------------------------------
import {
RightPanelWidget,
defineWidget,
ActionButton,
useActiveNoteContext,
useNoteLabelBoolean,
useNoteRelationTarget,
useState,
useEffect,
} from "trilium:preact"
import {
startNote
} from "trilium:api"
import { loadSettings } from "libSettingsUI.jsx"
// Main Widget ---------------------------------------------------------------------------
// Rendered once the configured label name is loaded; a pin toggle lives in the panel
// header (the `buttons` slot) rather than the body.
function ExpandedPanel({ note, labelName }) {
const [expanded, setExpanded] = useNoteLabelBoolean(note, labelName)
const [scriptNote] = useNoteRelationTarget(startNote, "scriptNote")
return (
<RightPanelWidget
title="Always Expanded"
buttons={
<ActionButton
icon={expanded ? "bx bxs-pin" : "bx bx-pin"}
text={expanded ? "Unpin (stop keeping expanded)" : "Pin (keep always expanded)"}
titlePosition="top"
onClick={() => {
setExpanded(expanded ? null : true)
if (scriptNote) { scriptNote.executeScript() }
}}
/>
}
/>
)
}
export default defineWidget({
parent: "right-pane",
position: 5,
render() {
const { note } = useActiveNoteContext()
const [labelName, setLabelName] = useState(null)
// The label name is an addon-wide setting, not per-note — load once.
useEffect(() => {
(async () => {
const schemaNoteId = await api.currentNote.getRelationValue("schemaNote")
const settingsNoteId = await api.currentNote.getRelationValue("settingsNote")
const configNoteId = await api.runOnBackend((settingsNoteId) => {
return api.getNote(settingsNoteId).getRelationValue("configNote")
}, [settingsNoteId])
const { labelName } = await loadSettings(schemaNoteId, configNoteId)
setLabelName(labelName)
})()
}, [])
if (!labelName || !note) return null
return <ExpandedPanel note={note} labelName={labelName} />
}
})