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

82 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-07-23 00:57:40 +02:00
import * as React from "bloatless-react";
import TaskModel, { BoardInfoFileContent } from "../../Model/Files/taskModel";
2024-07-23 00:57:40 +02:00
import { Color } from "../../colors";
import TaskPageViewModel from "./taskPageViewModel";
export default class BoardViewModel {
taskPageViewModel: TaskPageViewModel;
2024-07-23 13:09:46 +02:00
// state
2024-07-23 00:57:40 +02:00
boardInfo: BoardInfoFileContent;
name: React.State<string> = new React.State("");
color: React.State<Color> = new React.State<Color>(Color.Standard);
2024-07-23 02:40:11 +02:00
isSelected: React.State<boolean>;
2024-07-23 13:09:46 +02:00
isPresentingSettingsModal: React.State<boolean> = new React.State(false);
2024-07-23 02:40:11 +02:00
// view
select = (): void => {
this.taskPageViewModel.selectBoard(this);
};
close = (): void => {
this.taskPageViewModel.closeBoard();
};
2024-07-23 13:09:46 +02:00
showSettings = (): void => {
this.isPresentingSettingsModal.value = true;
};
hideSettings = (): void => {
this.saveSettings();
2024-07-23 13:09:46 +02:00
this.isPresentingSettingsModal.value = false;
};
// methods
saveSettings = (): void => {
const newBoardInfoFileContent: BoardInfoFileContent =
TaskModel.createBoardInfoFileContent(
this.boardInfo.fileId,
this.name.value,
this.color.value
);
this.taskPageViewModel.updateBoard(newBoardInfoFileContent);
};
2024-07-23 13:48:17 +02:00
applyColor = (newColor: Color): void => {
this.taskPageViewModel.chatViewModel.setDisplayedColor(newColor);
};
2024-07-23 00:57:40 +02:00
// load
loadListRelevantData = (): void => {
this.name.value = this.boardInfo.name;
this.color.value = this.boardInfo.color;
2024-07-23 02:40:11 +02:00
};
2024-07-23 00:57:40 +02:00
2024-07-23 02:40:11 +02:00
loadData = (): void => {};
2024-07-23 00:57:40 +02:00
// init
2024-07-23 02:40:11 +02:00
constructor(
taskPageViewModel: TaskPageViewModel,
boardInfo: BoardInfoFileContent
) {
2024-07-23 00:57:40 +02:00
this.taskPageViewModel = taskPageViewModel;
this.boardInfo = boardInfo;
this.loadListRelevantData();
2024-07-23 02:40:11 +02:00
this.isSelected = React.createProxyState(
2024-07-23 13:51:27 +02:00
[this.taskPageViewModel.selectedBoardId],
() =>
this.taskPageViewModel.selectedBoardId.value == this.boardInfo.fileId
2024-07-23 02:40:11 +02:00
);
2024-07-23 13:48:17 +02:00
this.color.subscribeSilent((newColor) => {
this.applyColor(newColor);
});
2024-07-23 00:57:40 +02:00
}
}