fix bug where board viewmodels where re-created
This commit is contained in:
Vendored
+42
-25
@@ -1616,7 +1616,10 @@
|
||||
this.settingsModel = settingsModel2;
|
||||
this.connectionModel = connectionModel2;
|
||||
this.loadChats();
|
||||
connectionModel2.messageHandlerManager.setHandler("chat-list", this.messageHandler);
|
||||
connectionModel2.messageHandlerManager.setHandler(
|
||||
"chat-list",
|
||||
this.messageHandler
|
||||
);
|
||||
connectionModel2.messageSentHandlerManager.setHandler(
|
||||
"chat-list",
|
||||
this.messageSentHandler
|
||||
@@ -2254,7 +2257,7 @@
|
||||
this.connectionModel = connectionModel2;
|
||||
this.chatListModel = chatListModel2;
|
||||
this.fileTransferModel = fileTransferModel2;
|
||||
this.BUILD = "Build 26.04.13.E";
|
||||
this.BUILD = "Build 26.04.14.A";
|
||||
// CONTEXT
|
||||
this.contextStack = /* @__PURE__ */ new Map();
|
||||
this.closeContext = (contextId) => {
|
||||
@@ -2381,12 +2384,12 @@
|
||||
// src/ViewModel/Pages/taskViewModel.ts
|
||||
var TaskViewModel = class extends Context {
|
||||
// init
|
||||
constructor(coreViewModel2, chatViewModel, boardsAndTasksModel, containingModel, task) {
|
||||
constructor(coreViewModel2, chatViewModel, boardsAndTasksModel, containingViewModel, task) {
|
||||
super("task");
|
||||
this.coreViewModel = coreViewModel2;
|
||||
this.chatViewModel = chatViewModel;
|
||||
this.boardsAndTasksModel = boardsAndTasksModel;
|
||||
this.containingModel = containingModel;
|
||||
this.containingViewModel = containingViewModel;
|
||||
this.task = task;
|
||||
// paths
|
||||
this.getFilePath = () => {
|
||||
@@ -2425,11 +2428,11 @@
|
||||
// view
|
||||
this.open = () => {
|
||||
this.coreViewModel.context = this;
|
||||
this.containingModel.selectTask(this);
|
||||
this.containingViewModel.selectTask(this);
|
||||
};
|
||||
this.close = () => {
|
||||
this.coreViewModel.closeContext(this.contextId);
|
||||
this.containingModel.closeTask();
|
||||
this.containingViewModel.closeTask();
|
||||
};
|
||||
this.closeAndDiscard = () => {
|
||||
this.close();
|
||||
@@ -2440,7 +2443,7 @@
|
||||
this.save();
|
||||
};
|
||||
this.updateIndex = () => {
|
||||
const index = this.containingModel.taskIndexManager.getIndex(this);
|
||||
const index = this.containingViewModel.taskIndexManager.getIndex(this);
|
||||
this.index.value = index;
|
||||
};
|
||||
this.updateSuggestions = () => {
|
||||
@@ -2470,8 +2473,8 @@
|
||||
newTaskFileContent.date = this.date.value;
|
||||
newTaskFileContent.time = this.time.value;
|
||||
this.boardsAndTasksModel.updateTaskAndSend(newTaskFileContent);
|
||||
this.containingModel.showTask(newTaskFileContent);
|
||||
this.containingModel.updateTaskIndices();
|
||||
this.containingViewModel.showTask(newTaskFileContent);
|
||||
this.containingViewModel.updateTaskIndices();
|
||||
this.updateSuggestions();
|
||||
};
|
||||
this.deleteTask = () => {
|
||||
@@ -2480,7 +2483,7 @@
|
||||
this.task.boardId,
|
||||
this.task.fileId
|
||||
);
|
||||
this.containingModel.removeTaskFromView(this.task);
|
||||
this.containingViewModel.removeTaskFromView(this.task);
|
||||
};
|
||||
// load
|
||||
this.loadVersionIds = () => {
|
||||
@@ -3331,6 +3334,7 @@
|
||||
this.loadTasks();
|
||||
this.loadSearchSuggestions();
|
||||
};
|
||||
console.log("NEW BOARD VM");
|
||||
this.loadListRelevantData();
|
||||
this.isSelected = createProxyState(
|
||||
[this.taskPageViewModel.selectedBoardId],
|
||||
@@ -3344,6 +3348,11 @@
|
||||
});
|
||||
this.selectedPage.subscribeSilent(() => {
|
||||
this.storeLastUsedView();
|
||||
console.log(
|
||||
"SELECTED PAGE",
|
||||
this.selectedPage.value,
|
||||
this.contextId
|
||||
);
|
||||
});
|
||||
boardsAndTasksModel.taskHandlerManager.setHandler(
|
||||
this.boardInfo.fileId,
|
||||
@@ -3434,6 +3443,7 @@
|
||||
this.isShowingBoadList.value = !this.isShowingBoadList.value;
|
||||
};
|
||||
this.showBoardInList = (boardInfo) => {
|
||||
if (this.boardViewModels.value.has(boardInfo.fileId)) return;
|
||||
const boardViewModel = new BoardViewModel(
|
||||
this.coreViewModel,
|
||||
this.chatViewModel,
|
||||
@@ -3448,8 +3458,11 @@
|
||||
]);
|
||||
};
|
||||
this.selectBoard = (boardViewModel) => {
|
||||
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();
|
||||
};
|
||||
this.closeBoard = () => {
|
||||
@@ -3481,9 +3494,9 @@
|
||||
// load
|
||||
this.loadData = () => {
|
||||
this.closeContext();
|
||||
this.boardViewModels.clear();
|
||||
const boardIds = this.boardsAndTasksModel.listBoardIds();
|
||||
for (const boardId of boardIds) {
|
||||
if (this.boardViewModels.value.has(boardId)) continue;
|
||||
const boardInfo = this.boardsAndTasksModel.getBoardInfo(boardId);
|
||||
if (boardInfo == null) continue;
|
||||
this.showBoardInList(boardInfo);
|
||||
@@ -5197,7 +5210,6 @@
|
||||
if (this.trackers.has(key)) {
|
||||
return this.trackers.get(key);
|
||||
}
|
||||
;
|
||||
const tracker = new PageTracker();
|
||||
this.trackers.set(key, tracker);
|
||||
return tracker;
|
||||
@@ -5229,9 +5241,9 @@
|
||||
function BoardPage(coreViewModel2, boardViewModel) {
|
||||
boardViewModel.loadData();
|
||||
const persistenceId = boardViewModel.boardInfo.fileId;
|
||||
const pages = ViewPersistence.boardPages.setPages(persistenceId, () => createProxyState(
|
||||
[boardViewModel.selectedPage],
|
||||
() => {
|
||||
const pages = ViewPersistence.boardPages.setPages(
|
||||
persistenceId,
|
||||
() => createProxyState([boardViewModel.selectedPage], () => {
|
||||
switch (boardViewModel.selectedPage.value) {
|
||||
case "kanban" /* Kanban */: {
|
||||
return BoardKanbanPage(coreViewModel2, boardViewModel);
|
||||
@@ -5252,8 +5264,8 @@
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
));
|
||||
})
|
||||
);
|
||||
const taskSettingsModal = createProxyState(
|
||||
[boardViewModel.selectedTaskViewModel],
|
||||
() => {
|
||||
@@ -5372,9 +5384,9 @@
|
||||
() => taskPageViewModel.selectedBoardId.value != void 0
|
||||
);
|
||||
const persistenceId = taskPageViewModel.chatViewModel.chatModel.id;
|
||||
const pages = ViewPersistence.taskPages.setPages(persistenceId, () => createProxyState(
|
||||
[taskPageViewModel.selectedBoardId],
|
||||
() => {
|
||||
const pages = ViewPersistence.taskPages.setPages(
|
||||
persistenceId,
|
||||
() => createProxyState([taskPageViewModel.selectedBoardId], () => {
|
||||
const selectedBoardId = taskPageViewModel.selectedBoardId.value;
|
||||
if (selectedBoardId == void 0) {
|
||||
return PlaceholderView(
|
||||
@@ -5385,10 +5397,9 @@
|
||||
if (selectedBoard == void 0) {
|
||||
return /* @__PURE__ */ createElement("div", { class: "pane align-center justify-center" }, /* @__PURE__ */ createElement("span", { class: "secondary" }, coreViewModel2.translations.chatPage.task.boardNotFound));
|
||||
}
|
||||
console.log("BOARD PAGE");
|
||||
return BoardPage(coreViewModel2, selectedBoard);
|
||||
}
|
||||
));
|
||||
})
|
||||
);
|
||||
return /* @__PURE__ */ createElement(
|
||||
"div",
|
||||
{
|
||||
@@ -5536,7 +5547,13 @@
|
||||
"settings",
|
||||
"settings" /* Settings */,
|
||||
chatViewModel
|
||||
))), /* @__PURE__ */ createElement("div", { id: "main", "children:set": ViewPersistence.chatPages.pages }))
|
||||
))), /* @__PURE__ */ createElement(
|
||||
"div",
|
||||
{
|
||||
id: "main",
|
||||
"children:set": ViewPersistence.chatPages.pages
|
||||
}
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,8 +108,12 @@ export default class ChatListModel {
|
||||
this.connectionModel = connectionModel;
|
||||
this.loadChats();
|
||||
|
||||
connectionModel.messageHandlerManager.setHandler("chat-list", this.messageHandler);
|
||||
connectionModel.messageSentHandlerManager.setHandler("chat-list",
|
||||
connectionModel.messageHandlerManager.setHandler(
|
||||
"chat-list",
|
||||
this.messageHandler,
|
||||
);
|
||||
connectionModel.messageSentHandlerManager.setHandler(
|
||||
"chat-list",
|
||||
this.messageSentHandler,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,8 @@ export default class FileTransferModel {
|
||||
this.storageModel = storageModel;
|
||||
this.connectionModel = connectionModel;
|
||||
|
||||
this.connectionModel.messageHandlerManager.setHandler("file-transfer",
|
||||
this.connectionModel.messageHandlerManager.setHandler(
|
||||
"file-transfer",
|
||||
this.handleMessage,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,9 +23,8 @@ export function BoardPage(
|
||||
|
||||
// main content
|
||||
const persistenceId = boardViewModel.boardInfo.fileId;
|
||||
const pages = ViewPersistence.boardPages.setPages(persistenceId, ()=>React.createProxyState(
|
||||
[boardViewModel.selectedPage],
|
||||
() => {
|
||||
const pages = ViewPersistence.boardPages.setPages(persistenceId, () =>
|
||||
React.createProxyState([boardViewModel.selectedPage], () => {
|
||||
switch (boardViewModel.selectedPage.value) {
|
||||
case BoardPageTypes.Kanban: {
|
||||
return BoardKanbanPage(coreViewModel, boardViewModel);
|
||||
@@ -45,8 +44,8 @@ export function BoardPage(
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
));
|
||||
}),
|
||||
);
|
||||
|
||||
// task modal
|
||||
const taskSettingsModal = React.createProxyState(
|
||||
|
||||
@@ -22,9 +22,8 @@ export function TaskPage(
|
||||
);
|
||||
|
||||
const persistenceId = taskPageViewModel.chatViewModel.chatModel.id;
|
||||
const pages = ViewPersistence.taskPages.setPages(persistenceId, ()=>React.createProxyState(
|
||||
[taskPageViewModel.selectedBoardId],
|
||||
() => {
|
||||
const pages = ViewPersistence.taskPages.setPages(persistenceId, () =>
|
||||
React.createProxyState([taskPageViewModel.selectedBoardId], () => {
|
||||
const selectedBoardId = taskPageViewModel.selectedBoardId.value;
|
||||
if (selectedBoardId == undefined) {
|
||||
return PlaceholderView(
|
||||
@@ -47,8 +46,8 @@ export function TaskPage(
|
||||
}
|
||||
|
||||
return BoardPage(coreViewModel, selectedBoard);
|
||||
},
|
||||
));
|
||||
}),
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
@@ -130,7 +130,10 @@ export function ChatPage(
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
<div id="main" children:set={ViewPersistence.chatPages.pages}></div>
|
||||
<div
|
||||
id="main"
|
||||
children:set={ViewPersistence.chatPages.pages}
|
||||
></div>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
|
||||
@@ -10,13 +10,16 @@ class PageTrackerMap {
|
||||
private register = (key: string): PageTracker => {
|
||||
if (this.trackers.has(key)) {
|
||||
return this.trackers.get(key);
|
||||
};
|
||||
}
|
||||
const tracker = new PageTracker();
|
||||
this.trackers.set(key, tracker);
|
||||
return tracker
|
||||
}
|
||||
return tracker;
|
||||
};
|
||||
|
||||
setPages = (key: string, pages: () => React.State<HTMLElement>): React.State<HTMLElement | undefined> | undefined => {
|
||||
setPages = (
|
||||
key: string,
|
||||
pages: () => React.State<HTMLElement>,
|
||||
): React.State<HTMLElement | undefined> | undefined => {
|
||||
const tracker: PageTracker = this.register(key);
|
||||
|
||||
if (tracker.pages != undefined) {
|
||||
@@ -25,11 +28,11 @@ class PageTrackerMap {
|
||||
tracker.pages = pages();
|
||||
return tracker.pages;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export class ViewPersistence {
|
||||
static readonly chatPages = new PageTracker();
|
||||
static readonly taskPages = new PageTrackerMap();
|
||||
static readonly boardPages = new PageTrackerMap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
|
||||
@@ -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(),
|
||||
);
|
||||
|
||||
|
||||
@@ -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