Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/collections/board: fix an issue
Adorian Doranbd765b805ce0
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsxindex 2a225805e3..3bf379bf51 100644--- a/apps/client/src/widgets/collections/board/column.tsx+++ b/apps/client/src/widgets/collections/board/column.tsx@@ -95,11 +95,12 @@ export default function Column({const [ isCreatingNewItem, setIsCreatingNewItem ] = useState(false);const [ created, setCreated ] = useState<{ noteId?: string, takesFocus: boolean }>();/**- * The cards this column has drawn since making them, each of which arrives once.+ * Every card this column has drawn, which is what tells one just made from one coming back.*- * `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. Recorded- * whether or not it opens out: the footer's card is one the column has drawn as well.+ * `created` names a card until another is made, and the card itself is marked in no way, so a+ * card carried off the column and back would arrive under that name again. Every arrival is+ * recorded, whatever became of it: the card can be drawn before the write answers with its id,+ * and the footer's own card is never opened out at all.*/const arrived = useRef(new Set<string>());// `isNew` stays true until another column is added, so the reveal is recorded here rather than@@ -142,12 +143,15 @@ export default function Column({selector: ".board-note",grow: (card) => {const noteId = card.getAttribute("data-note-id");- if (!noteId || noteId !== created?.noteId || arrived.current.has(noteId)) {+ if (!noteId) {return false;}+ const isFirstArrival = !arrived.current.has(noteId);arrived.current.add(noteId);- return Date.now() > footerQuietUntil.current;++ return isFirstArrival && noteId === created?.noteId+ && 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.tsxindex 561cc8e980..3ad8aa88c2 100644--- a/apps/client/src/widgets/collections/board/index.spec.tsx+++ b/apps/client/src/widgets/collections/board/index.spec.tsx@@ -1531,6 +1531,58 @@ describe("Board column rename", () => {}});+ /**+ * The write answers with the card's id, and the refresh that draws the card can land first, so+ * the column draws it before it knows what it made. That arrival counts all the same, or the+ * card is the one the column would open out when it comes back.+ */+ it("leaves a card drawn before the write answered alone when it comes back", async () => {+ const { note, container } = await setup();+ withBoxes();++ try {+ const card = buildNote({ title: "Early", "#status": "Doing" });+ let answer: (noteId: string) => void = () => {};+ vi.spyOn(BoardApi.prototype, "createNewItem")+ .mockReturnValue(new Promise((resolve) => { answer = resolve; }));++ 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 = "Early";+ await act(async () => {+ editor.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));+ await flush();+ });++ // Drawn while the write is still in flight, and only then answered.+ fileCard(note, card);+ await redraw(note, container);+ await act(async () => {+ answer(card.noteId);+ await flush();+ });++ 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") ]