Step 2 - core board
1 min read
Kanban data model and service
Create the kanban data layer. Firestore collection kanbanProjects/{projectId} with fields: id, code (random 6-character share code), workspaceId, ownerId, name (max 120 chars), columns: {id, title}[] (embedded array - array order IS the left-to-right column order), tags?: {id, name, color}[] (board-wide labels), publicEdit?: boolean, lastActivityAt?: number, isDeleted, createdAt, updatedAt. Cards live in subcollection kanbanProjects/{projectId}/tasks/{taskId}: id, projectId, columnId, text (markdown - the first non-blank line is the card title), authorId?, authorName?, color? (palette key), tagIds?: string[], assignees?: {uid, name}[] (names only, never emails), attachments?: {url, path, name}[], dueDate? (epoch ms at local midnight), order: number (0..n within its column), lastCommentAt?, lastCommentBy?, isDeleted, createdAt, updatedAt.
Build a KanbanService with: createProject(name) seeding three default columns (To do / In progress / Done); watchProject(id) and watchTasks(id) as two realtime streams (fetch ALL tasks including deleted, split visible vs trash client-side; equality-only queries, no composite indexes); addTask (order = max existing order in column + 1); updateTask; soft delete and restore for projects and tasks (isDeleted flag, never hard-delete docs); persistOrder(columnId, orderedTaskIds) that reindexes order 0..n and writes all changes in ONE writeBatch; reorderColumns(columns) persisting the whole columns array.
Also add: a kanbanCardTitle(text) helper returning the first non-blank line of the markdown, and a KANBAN_TASK_COLORS palette of 9 named colors (red, orange, yellow, green, teal, blue, purple, pink, gray) with hex values that read well in both themes.
Discussion
0 commentsNo comments yet. Start the discussion.