feat(views/board): keep empty columns

This commit is contained in:
Elian Doran 2025-07-20 10:50:26 +03:00
parent e1a8f4f5db
commit 37c9260dca
No known key found for this signature in database
2 changed files with 23 additions and 17 deletions

View File

@ -10,28 +10,31 @@ type ColumnMap = Map<string, {
export async function getBoardData(parentNote: FNote, groupByColumn: string, persistedData: BoardData) { export async function getBoardData(parentNote: FNote, groupByColumn: string, persistedData: BoardData) {
const byColumn: ColumnMap = new Map(); const byColumn: ColumnMap = new Map();
// Add back existing columns.
for (const column of persistedData.columns || []) {
byColumn.set(column.value, []);
}
await recursiveGroupBy(parentNote.getChildBranches(), byColumn, groupByColumn); await recursiveGroupBy(parentNote.getChildBranches(), byColumn, groupByColumn);
let newPersistedData: BoardData | undefined; let newPersistedData: BoardData | undefined;
if (persistedData) { // Check if we have new columns.
// Check if we have new columns. const existingColumns = persistedData.columns?.map(c => c.value) || [];
const existingColumns = persistedData.columns?.map(c => c.value) || []; for (const column of existingColumns) {
for (const column of existingColumns) { if (!byColumn.has(column)) {
if (!byColumn.has(column)) { byColumn.set(column, []);
byColumn.set(column, []);
}
} }
}
const newColumns = [...byColumn.keys()] const newColumns = [...byColumn.keys()]
.filter(column => !existingColumns.includes(column)) .filter(column => !existingColumns.includes(column))
.map(column => ({ value: column })); .map(column => ({ value: column }));
if (newColumns.length > 0) { if (newColumns.length > 0) {
newPersistedData = { newPersistedData = {
...persistedData, ...persistedData,
columns: [...(persistedData.columns || []), ...newColumns] columns: [...(persistedData.columns || []), ...newColumns]
}; };
}
} }
return { return {

View File

@ -149,7 +149,10 @@ export default class BoardView extends ViewMode<BoardData> {
} }
private async renderBoard(el: HTMLElement) { private async renderBoard(el: HTMLElement) {
const data = await getBoardData(this.parentNote, "status", this.persistentData); const persistedData = await this.viewStorage.restore() ?? this.persistentData;
this.persistentData = persistedData;
const data = await getBoardData(this.parentNote, "status", persistedData);
if (data.newPersistedData) { if (data.newPersistedData) {
this.persistentData = data.newPersistedData; this.persistentData = data.newPersistedData;