Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix an issue

Adorian Doranc11a7e42ed2e
diff --git a/apps/client/src/widgets/collections/board/card.spec.tsx b/apps/client/src/widgets/collections/board/card.spec.tsx
index 52a2f7cc09..9b76b859fe 100644
--- a/apps/client/src/widgets/collections/board/card.spec.tsx
+++ b/apps/client/src/widgets/collections/board/card.spec.tsx
@@ -9,6 +9,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import appContext from "../../../components/app_context";
import Component from "../../../components/component";
import contextMenu from "../../../menus/context_menu";
+import cssClassManager from "../../../services/css_class_manager";
import FAttribute from "../../../entities/fattribute";
import froca from "../../../services/froca";
import LoadResults from "../../../services/load_results";
@@ -85,6 +86,22 @@ describe("Board card", () => {
expect(draws.get(second)).toBeGreaterThan(before ?? 0);
});
+ /**
+ * The board does not redraw a card for a colour, and a card whose props have not changed is
+ * skipped by the memo around it, so the card has to hear about the label itself.
+ */
+ it("follows its note's colour", async () => {
+ const { component, first, second } = await renderBoard();
+ const coloured = cssClassManager.createClassForColor("#ff0000");
+
+ expect(cardClasses(first)).not.toContain(coloured);
+
+ await addLabel(component, first, "color", "#ff0000");
+
+ expect(cardClasses(first)).toContain(coloured);
+ expect(cardClasses(second)).not.toContain(coloured);
+ });
+
it("follows its note's icon, which the quick edit popup sets as a label", async () => {
const { component, first } = await renderBoard();
diff --git a/apps/client/src/widgets/collections/board/card.tsx b/apps/client/src/widgets/collections/board/card.tsx
index 5f28850896..4159ffbe42 100644
--- a/apps/client/src/widgets/collections/board/card.tsx
+++ b/apps/client/src/widgets/collections/board/card.tsx
@@ -10,7 +10,9 @@ import { ContextMenuEvent } from "../../../menus/context_menu";
import { openNoteContextMenu } from "./context_menu";
import { t } from "../../../services/i18n";
import UserAttributesDisplay from "../../attribute_widgets/UserAttributesList";
-import { useNoteIcon, useNoteLabelBoolean, useTriliumEvent } from "../../react/hooks";
+import {
+ useNoteColorClass, useNoteIcon, useNoteLabelBoolean, useTriliumEvent
+} from "../../react/hooks";
function Card({
api,
@@ -52,7 +54,8 @@ function Card({
onCreated: (noteId: string | undefined) => void
}) {
const { setBranchIdToEdit } = useContext(BoardActionsContext);
- const colorClass = note.getColorClass() || '';
+ // Tracks the `color` label, which the board does not redraw a card for.
+ const colorClass = useNoteColorClass(note) || "";
const editorRef = useRef<HTMLInputElement>(null);
const cardRef = useRef<HTMLDivElement>(null);
const [ isArchived ] = useNoteLabelBoolean(note, "archived");