Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix an issue

Adorian Dorane87de67d7707
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index cfe3a175e7..2a225805e3 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -95,13 +95,13 @@ export default function Column({
const [ isCreatingNewItem, setIsCreatingNewItem ] = useState(false);
const [ created, setCreated ] = useState<{ noteId?: string, takesFocus: boolean }>();
/**
- * The cards this column has opened out, each of which it opens out once.
+ * The cards this column has drawn since making them, each of which arrives once.
*
* `created` names the card until another is made, and the card itself is marked in no way, so
- * a card dragged out of the column and back would arrive as the one just made and open out
- * again on the drop.
+ * a card dragged out of the column and back would arrive as the one just made. Recorded
+ * whether or not it opens out: the footer's card is one the column has drawn as well.
*/
- const grown = useRef(new Set<string>());
+ const arrived = useRef(new Set<string>());
// `isNew` stays true until another column is added, so the reveal is recorded here rather than
// replayed on every redraw of the board.
const [ isRevealed, setIsRevealed ] = useState(false);
@@ -142,13 +142,12 @@ export default function Column({
selector: ".board-note",
grow: (card) => {
const noteId = card.getAttribute("data-note-id");
- if (!noteId || noteId !== created?.noteId || grown.current.has(noteId)
- || Date.now() <= footerQuietUntil.current) {
+ if (!noteId || noteId !== created?.noteId || arrived.current.has(noteId)) {
return false;
}
- grown.current.add(noteId);
- return true;
+ arrived.current.add(noteId);
+ return Date.now() > footerQuietUntil.current;
}
});
const { handleDragOver, handleDragLeave, handleDrop } = useDragging({
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index 0249dd4e87..561cc8e980 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -20,6 +20,7 @@ import { buildNote } from "../../../test/easy-froca";
import { ParentComponent } from "../../react/react_utils";
import BoardView, { BoardViewData } from ".";
import { collectShortcutHints } from "../../../services/shortcut_hints";
+import { FLIP_SETTLE_MS } from "../../react/flip";
import BoardApi, { getPendingWrites } from "./api";
import { DEFAULT_COLUMN_ICON } from "./columns";
@@ -1483,6 +1484,53 @@ describe("Board column rename", () => {
}
});
+ /**
+ * The footer's own card never opens out, the scroll to the end and the fade standing for it, so
+ * its arrival is recorded rather than its growth: otherwise it is the one card the column has
+ * made that opens out when it comes back.
+ */
+ it("leaves a card the footer made alone when it comes back", async () => {
+ const { note, container } = await setup();
+ withBoxes();
+
+ try {
+ const card = buildNote({ title: "Footed", "#status": "Doing" });
+ vi.spyOn(BoardApi.prototype, "createNewItem").mockResolvedValue(card.noteId);
+
+ const slot = container.querySelectorAll<HTMLElement>(".board-column")[1]
+ .querySelector<HTMLElement>(".board-new-item");
+ await act(async () => {
+ slot?.click();
+ await flush();
+ });
+
+ const editor = slot?.querySelector<HTMLTextAreaElement>("textarea");
+ if (!editor) throw new Error("expected the new-item editor to be open");
+ editor.value = "Footed";
+ await act(async () => {
+ editor.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
+ await flush();
+ });
+
+ fileCard(note, card);
+ await redraw(note, container);
+ expect(drawn(container, card.noteId).style.height).toBe("");
+
+ // Once the quiet window the footer opened has passed, and back on the column.
+ await act(async () => {
+ await new Promise((resolve) => setTimeout(resolve, FLIP_SETTLE_MS + 100));
+ });
+ unfileCard(note, card);
+ await redraw(note, container);
+ fileCard(note, card);
+ await redraw(note, container);
+
+ expect(drawn(container, card.noteId).style.height).toBe("");
+ } finally {
+ dropBoxes();
+ }
+ });
+
/** The element standing for a note, which a move draws afresh. */
function drawn(container: HTMLElement, noteId: string) {
const element = [ ...container.querySelectorAll<HTMLElement>(".board-note") ]