Skip to content

Build your personal knowledge base with Trilium Notes

fix(board): read no card templates for a read-only board

Elian Doran80a7a5e8d8a0
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index 704f54659f..82ad8cdaff 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -5646,7 +5646,10 @@ describe("BoardView, read-only", () => {
.map((item) => item.title);
it("offers no way to add a card or a column, nor to rename either", async () => {
+ vi.mocked(getNoteTypeOptions).mockClear();
const board = await setup();
+ // What a card can be made from is read for making one, which a read-only board never does.
+ expect(getNoteTypeOptions).not.toHaveBeenCalled();
const column = board.querySelector<HTMLElement>(".board-column");
const card = board.querySelector<HTMLElement>(".board-note");
expect(column === null || card === null).toBe(false);
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index b5b7d91fa1..97393e0854 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -457,7 +457,7 @@ export default function BoardView({
/** Whether the editor a column is named in is open, which the board's own menu also opens. */
const [ isCreatingColumn, setIsCreatingColumn ] = useState(false);
/** Everything a card could be made from: the note types and every template. */
- const availableTemplates = useNoteTypeOptions();
+ const availableTemplates = useNoteTypeOptions(!isReadOnly);
const [ isEditingProperties, setIsEditingProperties ] = useState(false);
/** Adds `frozen`, which takes `pointer-events` off the cards. Set once the backdrop has faded in. */
const [ isFrozen, setIsFrozen ] = useState(false);
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx
index 06e26f07af..9b24d9dd6f 100644
--- a/apps/client/src/widgets/react/hooks.tsx
+++ b/apps/client/src/widgets/react/hooks.tsx
@@ -2148,9 +2148,10 @@ export function useNoteColorClass(note: FNote | null | undefined) {
* reader's own.
*
* Read when the caller mounts and again whenever a template is made, deleted, renamed or given
- * another icon, so what is offered is what exists now.
+ * another icon, so what is offered is what exists now. Not read at all while `enabled` is off,
+ * for a caller that has nothing to create, such as a read-only board.
*/
-export function useNoteTypeOptions() {
+export function useNoteTypeOptions(enabled = true) {
const [ options, setOptions ] = useState<NoteTypeOption[]>([]);
/** How many reads were asked for, and the newest one answered. */
const asked = useRef(0);
@@ -2171,10 +2172,13 @@ export function useNoteTypeOptions() {
}, []);
useEffect(() => {
+ if (!enabled) {
+ return;
+ }
read();
// A read still in flight when the caller goes has nothing left to answer.
return () => { answered.current = asked.current + 1; };
- }, [ read ]);
+ }, [ read, enabled ]);
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
const offered = new Set(options
@@ -2191,7 +2195,7 @@ export function useNoteTypeOptions() {
option.options.templateNoteId
&& loadResults.isNoteReloaded(option.options.templateNoteId));
- if (templated || renamed) {
+ if (enabled && (templated || renamed)) {
read();
}
});