2024-07-22 19:54:39 +02:00
|
|
|
import * as React from "bloatless-react";
|
|
|
|
|
|
2024-07-23 00:25:28 +02:00
|
|
|
import TaskModel, {
|
|
|
|
|
BoardInfoFileContent,
|
|
|
|
|
BoardInfoFileContentReference,
|
|
|
|
|
} from "../../Model/Files/taskModel";
|
2024-07-22 20:02:13 +02:00
|
|
|
|
2024-07-23 00:25:28 +02:00
|
|
|
import { FileContent } from "../../Model/Files/fileModel";
|
2024-07-22 20:02:13 +02:00
|
|
|
import StorageModel from "../../Model/Global/storageModel";
|
2024-07-23 00:25:28 +02:00
|
|
|
import { checkMatchesObjectStructure } from "../../Model/Utility/typeSafety";
|
2024-07-22 20:02:13 +02:00
|
|
|
|
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 == ""
|
|
|
|
|
);
|
|
|
|
|
|
2024-07-23 00:25:28 +02:00
|
|
|
// handlers
|
|
|
|
|
handleFileContent = (fileContent: FileContent<string>): void => {
|
|
|
|
|
if (
|
|
|
|
|
checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) ==
|
|
|
|
|
false
|
|
|
|
|
)
|
|
|
|
|
return;
|
|
|
|
|
this.showBoard(fileContent as BoardInfoFileContent);
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-22 20:02:13 +02:00
|
|
|
// 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();
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-23 00:25:28 +02:00
|
|
|
// view
|
|
|
|
|
showBoard = (boardInfo: BoardInfoFileContent): void => {
|
|
|
|
|
this.boards.add(boardInfo);
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-23 00:05:48 +02:00
|
|
|
// 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);
|
2024-07-23 00:25:28 +02:00
|
|
|
if (boardInfo == null) continue;
|
|
|
|
|
|
|
|
|
|
this.showBoard(boardInfo);
|
2024-07-23 00:05:48 +02:00
|
|
|
}
|
2024-07-22 20:02:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// init
|
|
|
|
|
constructor(taskModel: TaskModel, storageModel: StorageModel) {
|
|
|
|
|
this.taskModel = taskModel;
|
|
|
|
|
}
|
|
|
|
|
}
|