handle new items through ViewModels

This commit is contained in:
marlon-erler
2024-07-23 01:40:30 +02:00
parent bd3ea5cc07
commit 6d4f54aaa0
5 changed files with 35 additions and 17 deletions
+14 -8
View File
@@ -531,6 +531,8 @@
storageModel; storageModel;
chatModel; chatModel;
fileModel; fileModel;
boardHandler = () => {
};
// paths // paths
getBasePath = () => { getBasePath = () => {
return this.fileModel.getModelContainerPath("taskModel"); return this.fileModel.getModelContainerPath("taskModel");
@@ -562,7 +564,7 @@
} }
}; };
handleBoard = (boardInfoFileContent) => { handleBoard = (boardInfoFileContent) => {
this.storeBoard(boardInfoFileContent); this.updateBoard(boardInfoFileContent);
}; };
handleTask = (taskFileContent) => { handleTask = (taskFileContent) => {
this.storeTask(taskFileContent); this.storeTask(taskFileContent);
@@ -574,6 +576,7 @@
return boardInfoFileContent; return boardInfoFileContent;
}; };
updateBoard = (boardInfoFileContent) => { updateBoard = (boardInfoFileContent) => {
this.boardHandler(boardInfoFileContent);
this.storeBoard(boardInfoFileContent); this.storeBoard(boardInfoFileContent);
this.chatModel.sendMessage("", boardInfoFileContent); this.chatModel.sendMessage("", boardInfoFileContent);
}; };
@@ -639,11 +642,16 @@
this.storageModel.removeRecursively(taskFilePath); this.storageModel.removeRecursively(taskFilePath);
this.storageModel.removeRecursively(taskReferencePath); this.storageModel.removeRecursively(taskReferencePath);
}; };
// other
setBoardHandler = (handler) => {
this.boardHandler = handler;
};
// init // init
constructor(storageModel2, chatModel, fileModel) { constructor(storageModel2, chatModel, fileModel) {
this.chatModel = chatModel; this.chatModel = chatModel;
this.fileModel = fileModel; this.fileModel = fileModel;
this.storageModel = storageModel2; this.storageModel = storageModel2;
fileModel.setFileContentHandler(this.handleFileContent);
} }
// utility // utility
static createBoardInfoFileContent = (fileId, name, color) => { static createBoardInfoFileContent = (fileId, name, color) => {
@@ -1394,7 +1402,7 @@
taskModel; taskModel;
// state // state
newBoardNameInput = new State(""); newBoardNameInput = new State("");
boardViewModels = new ListState(); boardViewModels = new MapState();
// guards // guards
cannotCreateBoard = createProxyState( cannotCreateBoard = createProxyState(
[this.newBoardNameInput], [this.newBoardNameInput],
@@ -1416,7 +1424,7 @@
// view // view
showBoard = (boardInfo) => { showBoard = (boardInfo) => {
const boardViewModel = new BoardViewModel(this, boardInfo); const boardViewModel = new BoardViewModel(this, boardInfo);
this.boardViewModels.add(boardViewModel); this.boardViewModels.set(boardInfo.fileId, boardViewModel);
}; };
// load // load
loadData = () => { loadData = () => {
@@ -1431,6 +1439,9 @@
// init // init
constructor(taskModel, storageModel2) { constructor(taskModel, storageModel2) {
this.taskModel = taskModel; this.taskModel = taskModel;
taskModel.setBoardHandler((boardInfoFileContent) => {
this.showBoard(boardInfoFileContent);
});
} }
}; };
@@ -1484,11 +1495,6 @@
chatModel.setMessageHandler((chatMessage) => { chatModel.setMessageHandler((chatMessage) => {
this.messagePageViewModel.showChatMessage(chatMessage); this.messagePageViewModel.showChatMessage(chatMessage);
}); });
chatModel.fileModel.setFileContentHandler(
(fileContent) => {
this.taskPageViewModel.handleFileContent(fileContent);
}
);
this.loadPageSelection(); this.loadPageSelection();
} }
}; };
-1
View File
@@ -20,7 +20,6 @@ export default class FileModel {
fileContentHandler: (fileContent: FileContent<string>) => void = () => {}; fileContentHandler: (fileContent: FileContent<string>) => void = () => {};
// paths // paths
getBasePath = (): string[] => { getBasePath = (): string[] => {
return StorageModel.getPath( return StorageModel.getPath(
+14 -1
View File
@@ -16,6 +16,8 @@ export default class TaskModel {
chatModel: ChatModel; chatModel: ChatModel;
fileModel: FileModel; fileModel: FileModel;
boardHandler: (boardInfoFileContent: BoardInfoFileContent) => void = () => {};
// paths // paths
getBasePath = (): string[] => { getBasePath = (): string[] => {
return this.fileModel.getModelContainerPath("taskModel"); return this.fileModel.getModelContainerPath("taskModel");
@@ -60,7 +62,7 @@ export default class TaskModel {
}; };
handleBoard = (boardInfoFileContent: BoardInfoFileContent) => { handleBoard = (boardInfoFileContent: BoardInfoFileContent) => {
this.storeBoard(boardInfoFileContent); this.updateBoard(boardInfoFileContent);
}; };
handleTask = (taskFileContent: TaskFileContent) => { handleTask = (taskFileContent: TaskFileContent) => {
@@ -76,6 +78,7 @@ export default class TaskModel {
}; };
updateBoard = (boardInfoFileContent: BoardInfoFileContent): void => { updateBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
this.boardHandler(boardInfoFileContent);
this.storeBoard(boardInfoFileContent); this.storeBoard(boardInfoFileContent);
this.chatModel.sendMessage("", boardInfoFileContent); this.chatModel.sendMessage("", boardInfoFileContent);
}; };
@@ -160,6 +163,13 @@ export default class TaskModel {
this.storageModel.removeRecursively(taskReferencePath); this.storageModel.removeRecursively(taskReferencePath);
}; };
// other
setBoardHandler = (
handler: (boardInfoFileContent: BoardInfoFileContent) => void
): void => {
this.boardHandler = handler;
};
// init // init
constructor( constructor(
storageModel: StorageModel, storageModel: StorageModel,
@@ -169,6 +179,9 @@ export default class TaskModel {
this.chatModel = chatModel; this.chatModel = chatModel;
this.fileModel = fileModel; this.fileModel = fileModel;
this.storageModel = storageModel; this.storageModel = storageModel;
// handlers
fileModel.setFileContentHandler(this.handleFileContent);
} }
// utility // utility
-5
View File
@@ -77,11 +77,6 @@ export default class ChatViewModel {
chatModel.setMessageHandler((chatMessage: ChatMessage) => { chatModel.setMessageHandler((chatMessage: ChatMessage) => {
this.messagePageViewModel.showChatMessage(chatMessage); this.messagePageViewModel.showChatMessage(chatMessage);
}); });
chatModel.fileModel.setFileContentHandler(
(fileContent: FileContent<string>) => {
this.taskPageViewModel.handleFileContent(fileContent);
}
);
// load // load
this.loadPageSelection(); this.loadPageSelection();
+7 -2
View File
@@ -16,7 +16,7 @@ export default class TaskPageViewModel {
// state // state
newBoardNameInput: React.State<string> = new React.State(""); newBoardNameInput: React.State<string> = new React.State("");
boardViewModels: React.ListState<BoardViewModel> = new React.ListState(); boardViewModels: React.MapState<BoardViewModel> = new React.MapState();
// guards // guards
cannotCreateBoard: React.State<boolean> = React.createProxyState( cannotCreateBoard: React.State<boolean> = React.createProxyState(
@@ -48,7 +48,7 @@ export default class TaskPageViewModel {
// view // view
showBoard = (boardInfo: BoardInfoFileContent): void => { showBoard = (boardInfo: BoardInfoFileContent): void => {
const boardViewModel: BoardViewModel = new BoardViewModel(this, boardInfo); const boardViewModel: BoardViewModel = new BoardViewModel(this, boardInfo);
this.boardViewModels.add(boardViewModel); this.boardViewModels.set(boardInfo.fileId, boardViewModel);
}; };
// load // load
@@ -68,5 +68,10 @@ export default class TaskPageViewModel {
// init // init
constructor(taskModel: TaskModel, storageModel: StorageModel) { constructor(taskModel: TaskModel, storageModel: StorageModel) {
this.taskModel = taskModel; this.taskModel = taskModel;
// handlers
taskModel.setBoardHandler((boardInfoFileContent: BoardInfoFileContent) => {
this.showBoard(boardInfoFileContent);
});
} }
} }