Files
CT/src/ViewModel/Pages/taskPageViewModel.ts
T

50 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-07-22 19:54:39 +02:00
import * as React from "bloatless-react";
2024-07-23 00:05:48 +02:00
import TaskModel, { BoardInfoFileContent } from "../../Model/Files/taskModel";
2024-07-22 20:02:13 +02:00
import StorageModel from "../../Model/Global/storageModel";
2024-07-22 21:07:44 +02:00
export default class TaskPageViewModel {
2024-07-22 20:02:13 +02:00
taskModel: TaskModel;
// state
newBoardNameInput: React.State<string> = new React.State("");
boards: React.ListState<BoardInfoFileContent> = new React.ListState();
// guards
cannotCreateBoard: React.State<boolean> = React.createProxyState(
[this.newBoardNameInput],
() => this.newBoardNameInput.value == ""
);
// methods
createBoard = (): void => {
if (this.cannotCreateBoard.value == true) return;
this.taskModel.createBoard(this.newBoardNameInput.value);
this.newBoardNameInput.value = "";
2024-07-23 00:05:48 +02:00
this.loadData();
};
// load
loadData = (): void => {
this.boards.clear();
const boardIds: string[] = this.taskModel.listBoardIds();
for (const boardId of boardIds) {
const boardInfo: BoardInfoFileContent | null =
this.taskModel.getBoardInfo(boardId);
if (boardInfo == null) continue;
this.boards.add(boardInfo);
}
2024-07-22 20:02:13 +02:00
};
// init
constructor(taskModel: TaskModel, storageModel: StorageModel) {
this.taskModel = taskModel;
}
}