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

65 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-07-26 06:20:16 +02:00
import * as React from "bloatless-react";
2026-04-18 11:55:01 +00:00
import TaskViewModel from "./taskViewModel";
import CoreViewModel, { Context } from "../Global/coreViewModel";
import ChatViewModel from "../Chat/chatViewModel";
import { IndexManager } from "../../Model/Utility/utility";
2024-07-26 06:20:16 +02:00
import BoardsAndTasksModel, {
2026-04-01 08:29:39 +00:00
TaskFileContent,
2024-07-26 06:20:16 +02:00
} from "../../Model/Files/boardsAndTasksModel";
2026-04-12 19:20:37 +00:00
export default class TaskContainingPageViewModel extends Context {
2026-04-01 08:29:39 +00:00
// state
2026-04-13 10:58:21 +00:00
readonly taskIndexManager = new IndexManager<TaskViewModel>(
2026-04-01 08:29:39 +00:00
(taskViewModel: TaskViewModel) => taskViewModel.sortingString,
);
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
selectedTaskViewModel: React.State<TaskViewModel | undefined> =
new React.State<any>(undefined);
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
taskViewModels: React.MapState<TaskViewModel> = new React.MapState();
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
// methods
createTaskFromBoardId = (boardId: string): void => {
const taskFileContent: TaskFileContent =
this.boardsAndTasksModel.createTask(boardId);
const taskViewModel: TaskViewModel = new TaskViewModel(
this.coreViewModel,
this.chatViewModel,
this.boardsAndTasksModel,
this,
taskFileContent,
);
taskViewModel.open();
2026-04-01 08:29:39 +00:00
this.updateTaskIndices();
};
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
// view
showTask = (taskFileContent: TaskFileContent): void => {};
removeTaskFromView = (taskFileContent: TaskFileContent): void => {};
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
selectTask = (selectedTask: TaskViewModel): void => {
this.selectedTaskViewModel.value = selectedTask;
};
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
closeTask = () => {
this.selectedTaskViewModel.value = undefined;
};
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
updateTaskIndices = (): void => {
this.taskIndexManager.update([...this.taskViewModels.value.values()]);
for (const taskViewModel of this.taskViewModels.value.values()) {
taskViewModel.updateIndex();
2026-04-01 08:29:39 +00:00
}
};
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
// init
constructor(
2026-04-13 10:58:21 +00:00
public readonly coreViewModel: CoreViewModel,
public readonly chatViewModel: ChatViewModel,
public readonly boardsAndTasksModel: BoardsAndTasksModel,
2026-04-13 19:45:52 +00:00
contextDebugDescription: string,
2026-04-12 19:20:37 +00:00
) {
2026-04-13 19:45:52 +00:00
super(contextDebugDescription);
2026-04-12 19:20:37 +00:00
}
2024-07-26 06:20:16 +02:00
}