mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 11:56:01 +01:00
refactor(views/board): delegate storage to API
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user