refactor(views/board): delegate storage to API

This commit is contained in:
Elian Doran
2025-07-20 19:06:33 +03:00
parent 3e5c91415d
commit 977fbf54ee
3 changed files with 29 additions and 19 deletions

View File

@@ -1,17 +1,27 @@
import appContext from "../../../components/app_context";
import FNote from "../../../entities/fnote";
import attributes from "../../../services/attributes";
import note_create from "../../../services/note_create";
import ViewModeStorage from "../view_mode_storage";
import { BoardData } from "./config";
import { ColumnMap, getBoardData } from "./data";
export default class BoardApi {
constructor(
private constructor(
private _columns: string[],
private _parentNoteId: string) {}
private _parentNoteId: string,
private viewStorage: ViewModeStorage<BoardData>,
private byColumn: ColumnMap) {}
get columns() {
return this._columns;
}
getColumn(column: string) {
return this.byColumn.get(column);
}
async changeColumn(noteId: string, newColumn: string) {
await attributes.setLabel(noteId, "status", newColumn);
}
@@ -49,4 +59,17 @@ export default class BoardApi {
}
}
static async build(parentNote: FNote, viewStorage: ViewModeStorage<BoardData>) {
let persistedData = await viewStorage.restore() ?? {};
const { byColumn, newPersistedData } = await getBoardData(parentNote, "status", persistedData);
const columns = Array.from(byColumn.keys()) || [];
if (newPersistedData) {
persistedData = newPersistedData;
viewStorage.store(persistedData);
}
return new BoardApi(columns, parentNote.noteId, viewStorage, byColumn);
}
}