fix bug where board viewmodels where re-created

This commit is contained in:
marlon-erler
2026-04-14 09:20:44 +00:00
parent 3a0278884d
commit 0c525de404
14 changed files with 109 additions and 62 deletions
+4 -2
View File
@@ -173,7 +173,8 @@ export default class ChatViewModel extends ContextHost<ChatPageTypes> {
);
// handlers
chatModel.chatMessageHandlerManager.setHandler(this.chatModel.id,
chatModel.chatMessageHandlerManager.setHandler(
this.chatModel.id,
(chatMessage: ChatMessage) => {
this.messagePageViewModel.showChatMessage(chatMessage);
this.updateReadStatus();
@@ -181,7 +182,8 @@ export default class ChatViewModel extends ContextHost<ChatPageTypes> {
this.notificationViewModel.showNotification(chatMessage);
},
);
chatModel.reactionHandlerManager.setHandler(this.chatModel.id,
chatModel.reactionHandlerManager.setHandler(
this.chatModel.id,
(reaction: ChatMessageReaction) => {
this.messagePageViewModel.handleReaction(reaction);
},
+1 -1
View File
@@ -8,7 +8,7 @@ import FileTransferModel from "../../Model/Global/fileTransferModel";
import { v4 } from "uuid";
export default class CoreViewModel {
readonly BUILD = "Build 26.04.14.A";
readonly BUILD = "Build 26.04.14.B";
translations: Translations;
@@ -173,11 +173,13 @@ export default class FileTransferViewModel extends Context {
constructor(public readonly coreViewModel: CoreViewModel) {
super("file-transfer");
this.coreViewModel.fileTransferModel.fileHandlerManager.setHandler("file-transfer-view-model",
this.coreViewModel.fileTransferModel.fileHandlerManager.setHandler(
"file-transfer-view-model",
this.handleReceivedFile,
);
this.coreViewModel.fileTransferModel.readyToSendHandlerManager.setHandler("file-transfer-view-model",
this.coreViewModel.fileTransferModel.readyToSendHandlerManager.setHandler(
"file-transfer-view-model",
() => this.initiateTransfer(),
);
+9 -1
View File
@@ -62,6 +62,7 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
this.name.value,
this.color.value,
);
this.taskPageViewModel.updateBoard(newBoardInfoFileContent);
this.taskPageViewModel.selectBoard(this);
@@ -254,6 +255,7 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
public readonly boardInfo: BoardInfoFileContent,
) {
super(coreViewModel, chatViewModel, boardsAndTasksModel, "board");
console.log("NEW BOARD VM")
// load
this.loadListRelevantData();
@@ -275,10 +277,16 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
this.selectedPage.subscribeSilent(() => {
this.storeLastUsedView();
console.log(
"SELECTED PAGE",
this.selectedPage.value,
this.contextId,
);
});
// handlers
boardsAndTasksModel.taskHandlerManager.setHandler(this.boardInfo.fileId,
boardsAndTasksModel.taskHandlerManager.setHandler(
this.boardInfo.fileId,
(taskFileContent: TaskFileContent) => {
if (taskFileContent.boardId != this.boardInfo.fileId) return;
this.showTask(taskFileContent);
+2 -1
View File
@@ -200,7 +200,8 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
});
// handlers
boardsAndTasksModel.taskHandlerManager.setHandler("calendar" + this.chatViewModel.chatModel.id,
boardsAndTasksModel.taskHandlerManager.setHandler(
"calendar" + this.chatViewModel.chatModel.id,
(taskFileContent: TaskFileContent) => {
this.showTask(taskFileContent);
},
+11 -3
View File
@@ -83,6 +83,8 @@ export default class TaskPageViewModel extends ContextHost<string> {
};
showBoardInList = (boardInfo: BoardInfoFileContent): void => {
if (this.boardViewModels.value.has(boardInfo.fileId)) return;
const boardViewModel: BoardViewModel = new BoardViewModel(
this.coreViewModel,
this.chatViewModel,
@@ -99,9 +101,13 @@ export default class TaskPageViewModel extends ContextHost<string> {
};
selectBoard = (boardViewModel: BoardViewModel): void => {
this.selectedBoardId.value = boardViewModel.boardInfo.fileId;
this.chatViewModel.displayedColor.value = boardViewModel.color.value;
if (this.selectedBoardId.value == boardViewModel.boardInfo.fileId) {
return this.updateContexts();
}
this.selectedBoardId.value = boardViewModel.boardInfo.fileId;
this.storeLastUsedBoard();
};
@@ -144,10 +150,11 @@ export default class TaskPageViewModel extends ContextHost<string> {
// load
loadData = (): void => {
this.closeContext();
this.boardViewModels.clear();
const boardIds: string[] = this.boardsAndTasksModel.listBoardIds();
for (const boardId of boardIds) {
if (this.boardViewModels.value.has(boardId)) continue;
const boardInfo: BoardInfoFileContent | null =
this.boardsAndTasksModel.getBoardInfo(boardId);
if (boardInfo == null) continue;
@@ -174,7 +181,8 @@ export default class TaskPageViewModel extends ContextHost<string> {
this.selectedBoardId.subscribeSilent(this.updateContexts);
// handlers
boardsAndTasksModel.boardHandlerManager.setHandler("task-page" + this.chatViewModel.chatModel.id,
boardsAndTasksModel.boardHandlerManager.setHandler(
"task-page" + this.chatViewModel.chatModel.id,
(boardInfoFileContent: BoardInfoFileContent) => {
this.showBoardInList(boardInfoFileContent);
this.updateBoardIndices();
+7 -7
View File
@@ -86,12 +86,12 @@ export default class TaskViewModel extends Context {
// view
open = (): void => {
this.coreViewModel.context = this;
this.containingModel.selectTask(this);
this.containingViewModel.selectTask(this);
};
close = (): void => {
this.coreViewModel.closeContext(this.contextId);
this.containingModel.closeTask();
this.containingViewModel.closeTask();
};
closeAndDiscard = (): void => {
@@ -106,7 +106,7 @@ export default class TaskViewModel extends Context {
updateIndex = (): void => {
const index: number =
this.containingModel.taskIndexManager.getIndex(this);
this.containingViewModel.taskIndexManager.getIndex(this);
this.index.value = index;
};
@@ -147,8 +147,8 @@ export default class TaskViewModel extends Context {
this.boardsAndTasksModel.updateTaskAndSend(newTaskFileContent);
this.containingModel.showTask(newTaskFileContent);
this.containingModel.updateTaskIndices();
this.containingViewModel.showTask(newTaskFileContent);
this.containingViewModel.updateTaskIndices();
this.updateSuggestions();
};
@@ -159,7 +159,7 @@ export default class TaskViewModel extends Context {
this.task.boardId,
this.task.fileId,
);
this.containingModel.removeTaskFromView(this.task);
this.containingViewModel.removeTaskFromView(this.task);
};
// load
@@ -213,7 +213,7 @@ export default class TaskViewModel extends Context {
public readonly coreViewModel: CoreViewModel,
public readonly chatViewModel: ChatViewModel,
public readonly boardsAndTasksModel: BoardsAndTasksModel,
public readonly containingModel: TaskContainingPageViewModel,
public readonly containingViewModel: TaskContainingPageViewModel,
public task: TaskFileContent,
) {
super("task");