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: refactor
Adorian Dorane6e9362c4b86
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.tsindex d35c57157a..7cf58bc8fb 100644--- a/apps/client/src/widgets/collections/board/api.ts+++ b/apps/client/src/widgets/collections/board/api.ts@@ -15,8 +15,9 @@ import ws from "../../../services/ws";import toast from "../../../services/toast";import { BoardColumnData, BoardViewData } from ".";import {- type BoardStatusDefinition, canStoreColumnsInDefinition, DEFAULT_COLUMN_ICON, DEFAULT_GROUP_BY-, INBOX_COLUMN, INBOX_COLUMN_ICON } from "./columns";+ type BoardStatusDefinition, canStoreColumnsInDefinition, DEFAULT_COLUMN_ICON,+ DEFAULT_GROUP_BY, INBOX_COLUMN, INBOX_COLUMN_ICON+} from "./columns";import { ColumnMap } from "./data";/** One write's claim on a column, held until that write lands or is taken back. */diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsxindex bdd539877a..a1b425db7b 100644--- a/apps/client/src/widgets/collections/board/column.tsx+++ b/apps/client/src/widgets/collections/board/column.tsx@@ -274,48 +274,6 @@ export default function Column({* The editor a new card is named in, opened by the button below the column or by its menu. The* state is the column's rather than this component's, since the menu is raised from the header.*/-/**- * How many cards a column holds, with a breakdown on hover.- *- * Archived cards are only included while the board is showing archived notes. Otherwise there are- * none to count and the badge reports the total alone.- */-function CountBadge({ items, limit, isOver }: {- items?: { note: FNote }[],- limit?: number,- /** Whether the column is over its limit. The column body is outlined as well. */- isOver?: boolean-}) {- const badgeRef = useRef<HTMLSpanElement>(null);- const archived = items?.filter(({ note }) => note.isArchived).length ?? 0;- const total = items?.length ?? 0;-- const counts = archived- ? t("board_view.card-count-with-archived", { count: total - archived, archived })- : t("board_view.card-count", { count: total });- const warning = t("board_view.card-count-over-limit");-- // The tooltip gets its own markup, since a title attribute cannot show a bold line. The- // attribute keeps a plain version as a fallback. Memoised because `useStaticTooltip`- // rebuilds the tooltip whenever the config changes identity.- const tooltip = useMemo(() => ({- html: true,- title: isOver ? `${counts}<br><strong>${warning}</strong>` : counts- }), [ counts, warning, isOver ]);- useStaticTooltip(badgeRef, tooltip);-- return (- <span- ref={badgeRef}- className={clsx("counter-badge", { "over-limit": isOver })}- title={isOver ? `${counts}-${warning}` : counts}- >- {limit === undefined ? total : `${total}/${limit}`}- </span>- );-}-function AddNewItem({ column, api, itemCount, isCreating, setIsCreating }: {column: string,api: BoardApi,@@ -395,6 +353,48 @@ function AddNewItem({ column, api, itemCount, isCreating, setIsCreating }: {);}+/**+ * How many cards a column holds, with a breakdown on hover.+ *+ * Archived cards are only included while the board is showing archived notes. Otherwise there are+ * none to count and the badge reports the total alone.+ */+function CountBadge({ items, limit, isOver }: {+ items?: { note: FNote }[],+ limit?: number,+ /** Whether the column is over its limit. The column body is outlined as well. */+ isOver?: boolean+}) {+ const badgeRef = useRef<HTMLSpanElement>(null);+ const archived = items?.filter(({ note }) => note.isArchived).length ?? 0;+ const total = items?.length ?? 0;++ const counts = archived+ ? t("board_view.card-count-with-archived", { count: total - archived, archived })+ : t("board_view.card-count", { count: total });+ const warning = t("board_view.card-count-over-limit");++ // The tooltip gets its own markup, since a title attribute cannot show a bold line. The+ // attribute keeps a plain version as a fallback. Memoised because `useStaticTooltip`+ // rebuilds the tooltip whenever the config changes identity.+ const tooltip = useMemo(() => ({+ html: true,+ title: isOver ? `${counts}<br><strong>${warning}</strong>` : counts+ }), [ counts, warning, isOver ]);+ useStaticTooltip(badgeRef, tooltip);++ return (+ <span+ ref={badgeRef}+ className={clsx("counter-badge", { "over-limit": isOver })}+ title={isOver ? `${counts}+${warning}` : counts}+ >+ {limit === undefined ? total : `${total}/${limit}`}+ </span>+ );+}+function useDragging({ column, columnIndex, columnItems, isEditing, api, parentNote }: DragContext & { isEditing: boolean, api: BoardApi, parentNote: FNote }) {const { setDraggedColumn, setDropTarget, setDropPosition } = useContext(BoardActionsContext);const { draggedColumn, dropPosition } = useContext(BoardDragStateContext);diff --git a/apps/client/src/widgets/collections/board/columns.ts b/apps/client/src/widgets/collections/board/columns.tsindex 2b2b7d2c65..57c72a0315 100644--- a/apps/client/src/widgets/collections/board/columns.ts+++ b/apps/client/src/widgets/collections/board/columns.ts@@ -85,11 +85,6 @@ export function getStatusDefinition(parentNote: FNote, groupBy: string): BoardSt* Having none at all is the ordinary case for a board created now, and the answer is yes: the* definition the board writes is its own from the start.*/-/** Whether a value identifies a column of its own, rather than the absence of one. */-function named(value: string) {- return value.trim() !== INBOX_COLUMN;-}-export function canStoreColumnsInDefinition(statusDefinition: BoardStatusDefinition | undefined): boolean {if (!statusDefinition) {// Nothing defines the label yet, so a definition the board creates is its own.@@ -168,3 +163,8 @@ export function resolveBoardColumns(// and reorder. Equal lengths are enough to tell, the attachment being one of the sources above.return persisted.length === columns.length ? persisted : columns;}++/** Whether a value identifies a column of its own, rather than the absence of one. */+function named(value: string) {+ return value.trim() !== INBOX_COLUMN;+}