remember and re-open last used board

This commit is contained in:
marlon-erler
2024-07-23 18:51:41 +02:00
parent 10db75df41
commit a043233709
4 changed files with 103 additions and 21 deletions
+44 -8
View File
@@ -573,6 +573,7 @@
storageModel;
chatModel;
fileModel;
// data
boardHandlerManager = new HandlerManager();
// paths
getBasePath = () => {
@@ -1501,6 +1502,20 @@
boardIndexManager = new IndexManager(
(boardViewModel) => boardViewModel.name.value
);
// paths
getBasePath = () => {
return [...this.taskModel.getBasePath(), "view" /* View */];
};
getLastUsedBoardPath = () => {
return [...this.getBasePath(), "last-used-board" /* ViewLastUsedBoard */];
};
getLastUsedViewPath = (boardId) => {
return [
...this.getBasePath(),
boardId,
"last-used-view" /* BoardLastUsedView */
];
};
// state
newBoardNameInput = new State("");
boardViewModels = new MapState();
@@ -1541,10 +1556,12 @@
selectBoard = (boardViewModel) => {
this.selectedBoardId.value = boardViewModel.boardInfo.fileId;
this.chatViewModel.displayedColor.value = boardViewModel.color.value;
this.storeLastUsedBoard();
};
closeBoard = () => {
this.selectedBoardId.value = void 0;
this.chatViewModel.resetColor();
this.storeLastUsedBoard();
};
updateIndices = () => {
this.boardIndexManager.update([...this.boardViewModels.value.values()]);
@@ -1552,6 +1569,20 @@
boardViewModel.updateIndex();
}
};
// storage
storeLastUsedBoard = () => {
const path = this.getLastUsedBoardPath();
const lastUsedBoardId = this.selectedBoardId.value ?? "";
this.storageModel.write(path, lastUsedBoardId);
};
openLastUsedBoard = () => {
const path = this.getLastUsedBoardPath();
const lastUsedBoardId = this.storageModel.read(path);
if (lastUsedBoardId == null) return;
const boardViewModel = this.boardViewModels.value.get(lastUsedBoardId);
if (boardViewModel == void 0) return;
this.selectBoard(boardViewModel);
};
// load
loadData = () => {
this.boardViewModels.clear();
@@ -1562,6 +1593,7 @@
this.showBoardInList(boardInfo);
}
this.updateIndices();
this.openLastUsedBoard();
};
// init
constructor(taskModel, storageModel2, chatViewModel) {
@@ -1600,7 +1632,6 @@
this.chatListViewModel.closeChat();
};
closeSubPages = () => {
this.taskPageViewModel.closeBoard();
};
setColor = (color) => {
this.setDisplayedColor(color);
@@ -1628,6 +1659,7 @@
}
this.selectedPage.subscribeSilent((newPage) => {
this.storageModel.write(path, newPage);
this.resetColor();
});
};
// init
@@ -2278,14 +2310,18 @@
)))
);
const mainPageWrapper = /* @__PURE__ */ createElement("div", { class: "pane-wrapper", "children:set": paneContent });
bulkSubscribe([taskPageViewModel.selectedBoardId], () => {
const selectedBoard = taskPageViewModel.selectedBoardId.value;
if (selectedBoard == void 0) {
listPaneWrapper.scrollIntoView();
} else {
mainPageWrapper.scrollIntoView();
function scroll() {
{
const selectedBoard = taskPageViewModel.selectedBoardId.value;
if (selectedBoard == void 0) {
listPaneWrapper.scrollIntoView();
} else {
mainPageWrapper.scrollIntoView();
}
}
});
}
bulkSubscribe([taskPageViewModel.selectedBoardId], scroll);
setTimeout(() => scroll(), 400);
return /* @__PURE__ */ createElement("div", { id: "task-page" }, listPaneWrapper, mainPageWrapper);
}
+11 -7
View File
@@ -80,14 +80,18 @@ export function TaskPage(taskPageViewModel: TaskPageViewModel) {
<div class="pane-wrapper" children:set={paneContent}></div>
);
React.bulkSubscribe([taskPageViewModel.selectedBoardId], () => {
const selectedBoard = taskPageViewModel.selectedBoardId.value;
if (selectedBoard == undefined) {
listPaneWrapper.scrollIntoView();
} else {
mainPageWrapper.scrollIntoView();
function scroll() {
{
const selectedBoard = taskPageViewModel.selectedBoardId.value;
if (selectedBoard == undefined) {
listPaneWrapper.scrollIntoView();
} else {
mainPageWrapper.scrollIntoView();
}
}
});
}
React.bulkSubscribe([taskPageViewModel.selectedBoardId], scroll);
setTimeout(() => scroll(), 400)
return (
<div id="task-page">
+4 -4
View File
@@ -37,9 +37,7 @@ export default class ChatViewModel {
this.chatListViewModel.closeChat();
};
closeSubPages = (): void => {
this.taskPageViewModel.closeBoard();
};
closeSubPages = (): void => {};
setColor = (color: Color): void => {
this.setDisplayedColor(color);
@@ -55,7 +53,8 @@ export default class ChatViewModel {
};
updateIndex = (): void => {
const index: number = this.chatListViewModel.chatIndexManager.getIndex(this);
const index: number =
this.chatListViewModel.chatIndexManager.getIndex(this);
this.index.value = index;
};
@@ -72,6 +71,7 @@ export default class ChatViewModel {
this.selectedPage.subscribeSilent((newPage) => {
this.storageModel.write(path, newPage);
this.resetColor();
});
};
+44 -2
View File
@@ -23,6 +23,23 @@ export default class TaskPageViewModel {
(boardViewModel: BoardViewModel) => boardViewModel.name.value
);
// paths
getBasePath = (): string[] => {
return [...this.taskModel.getBasePath(), TaskPageViewModelSubPaths.View];
};
getLastUsedBoardPath = (): string[] => {
return [...this.getBasePath(), TaskPageViewModelSubPaths.ViewLastUsedBoard];
};
getLastUsedViewPath = (boardId: string): string[] => {
return [
...this.getBasePath(),
boardId,
TaskPageViewModelSubPaths.BoardLastUsedView,
];
};
// state
newBoardNameInput: React.State<string> = new React.State("");
@@ -80,11 +97,15 @@ export default class TaskPageViewModel {
selectBoard = (boardViewModel: BoardViewModel): void => {
this.selectedBoardId.value = boardViewModel.boardInfo.fileId;
this.chatViewModel.displayedColor.value = boardViewModel.color.value;
this.storeLastUsedBoard();
};
closeBoard = (): void => {
this.selectedBoardId.value = undefined;
this.chatViewModel.resetColor();
this.storeLastUsedBoard();
};
updateIndices = (): void => {
@@ -94,6 +115,25 @@ export default class TaskPageViewModel {
}
};
// storage
storeLastUsedBoard = (): void => {
const path: string[] = this.getLastUsedBoardPath();
const lastUsedBoardId: string = this.selectedBoardId.value ?? "";
this.storageModel.write(path, lastUsedBoardId);
};
openLastUsedBoard = (): void => {
const path: string[] = this.getLastUsedBoardPath();
const lastUsedBoardId: string | null = this.storageModel.read(path);
if (lastUsedBoardId == null) return;
const boardViewModel: BoardViewModel | undefined =
this.boardViewModels.value.get(lastUsedBoardId);
if (boardViewModel == undefined) return;
this.selectBoard(boardViewModel);
};
// load
loadData = (): void => {
this.boardViewModels.clear();
@@ -108,6 +148,7 @@ export default class TaskPageViewModel {
}
this.updateIndices();
this.openLastUsedBoard();
};
// init
@@ -132,6 +173,7 @@ export default class TaskPageViewModel {
}
export enum TaskPageViewModelSubPaths {
LastUsedBoard = "last-used-board",
View = "view",
ViewLastUsedBoard = "last-used-board",
BoardLastUsedView = "last-used-view",
};
}