mirror of
https://github.com/zadam/trilium.git
synced 2025-10-29 18:49:00 +01:00
refactor(views/board): delegate storage to API
This commit is contained in:
parent
3e5c91415d
commit
977fbf54ee
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ import FBranch from "../../../entities/fbranch";
|
||||
import FNote from "../../../entities/fnote";
|
||||
import { BoardData } from "./config";
|
||||
|
||||
type ColumnMap = Map<string, {
|
||||
export type ColumnMap = Map<string, {
|
||||
branch: FBranch;
|
||||
note: FNote;
|
||||
}[]>;
|
||||
|
||||
@ -200,27 +200,14 @@ export default class BoardView extends ViewMode<BoardData> {
|
||||
}
|
||||
|
||||
private async renderBoard(el: HTMLElement) {
|
||||
const persistedData = await this.viewStorage.restore() ?? this.persistentData;
|
||||
this.persistentData = persistedData;
|
||||
|
||||
const data = await getBoardData(this.parentNote, "status", persistedData);
|
||||
const columns = Array.from(data.byColumn.keys()) || [];
|
||||
this.api = new BoardApi(
|
||||
columns,
|
||||
this.parentNote.noteId
|
||||
);
|
||||
this.api = await BoardApi.build(this.parentNote, this.viewStorage);
|
||||
showNoteContextMenu({
|
||||
$container: this.$container,
|
||||
api: this.api
|
||||
});
|
||||
|
||||
if (data.newPersistedData) {
|
||||
this.persistentData = data.newPersistedData;
|
||||
this.viewStorage.store(this.persistentData);
|
||||
}
|
||||
|
||||
for (const column of data.byColumn.keys()) {
|
||||
const columnItems = data.byColumn.get(column);
|
||||
for (const column of this.api.columns) {
|
||||
const columnItems = this.api.getColumn(column);
|
||||
if (!columnItems) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user