fix bug where board viewmodels where re-created
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user