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
+39 -3
View File
@@ -573,6 +573,7 @@
storageModel; storageModel;
chatModel; chatModel;
fileModel; fileModel;
// data
boardHandlerManager = new HandlerManager(); boardHandlerManager = new HandlerManager();
// paths // paths
getBasePath = () => { getBasePath = () => {
@@ -1501,6 +1502,20 @@
boardIndexManager = new IndexManager( boardIndexManager = new IndexManager(
(boardViewModel) => boardViewModel.name.value (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 // state
newBoardNameInput = new State(""); newBoardNameInput = new State("");
boardViewModels = new MapState(); boardViewModels = new MapState();
@@ -1541,10 +1556,12 @@
selectBoard = (boardViewModel) => { selectBoard = (boardViewModel) => {
this.selectedBoardId.value = boardViewModel.boardInfo.fileId; this.selectedBoardId.value = boardViewModel.boardInfo.fileId;
this.chatViewModel.displayedColor.value = boardViewModel.color.value; this.chatViewModel.displayedColor.value = boardViewModel.color.value;
this.storeLastUsedBoard();
}; };
closeBoard = () => { closeBoard = () => {
this.selectedBoardId.value = void 0; this.selectedBoardId.value = void 0;
this.chatViewModel.resetColor(); this.chatViewModel.resetColor();
this.storeLastUsedBoard();
}; };
updateIndices = () => { updateIndices = () => {
this.boardIndexManager.update([...this.boardViewModels.value.values()]); this.boardIndexManager.update([...this.boardViewModels.value.values()]);
@@ -1552,6 +1569,20 @@
boardViewModel.updateIndex(); 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 // load
loadData = () => { loadData = () => {
this.boardViewModels.clear(); this.boardViewModels.clear();
@@ -1562,6 +1593,7 @@
this.showBoardInList(boardInfo); this.showBoardInList(boardInfo);
} }
this.updateIndices(); this.updateIndices();
this.openLastUsedBoard();
}; };
// init // init
constructor(taskModel, storageModel2, chatViewModel) { constructor(taskModel, storageModel2, chatViewModel) {
@@ -1600,7 +1632,6 @@
this.chatListViewModel.closeChat(); this.chatListViewModel.closeChat();
}; };
closeSubPages = () => { closeSubPages = () => {
this.taskPageViewModel.closeBoard();
}; };
setColor = (color) => { setColor = (color) => {
this.setDisplayedColor(color); this.setDisplayedColor(color);
@@ -1628,6 +1659,7 @@
} }
this.selectedPage.subscribeSilent((newPage) => { this.selectedPage.subscribeSilent((newPage) => {
this.storageModel.write(path, newPage); this.storageModel.write(path, newPage);
this.resetColor();
}); });
}; };
// init // init
@@ -2278,14 +2310,18 @@
))) )))
); );
const mainPageWrapper = /* @__PURE__ */ createElement("div", { class: "pane-wrapper", "children:set": paneContent }); const mainPageWrapper = /* @__PURE__ */ createElement("div", { class: "pane-wrapper", "children:set": paneContent });
bulkSubscribe([taskPageViewModel.selectedBoardId], () => { function scroll() {
{
const selectedBoard = taskPageViewModel.selectedBoardId.value; const selectedBoard = taskPageViewModel.selectedBoardId.value;
if (selectedBoard == void 0) { if (selectedBoard == void 0) {
listPaneWrapper.scrollIntoView(); listPaneWrapper.scrollIntoView();
} else { } else {
mainPageWrapper.scrollIntoView(); mainPageWrapper.scrollIntoView();
} }
}); }
}
bulkSubscribe([taskPageViewModel.selectedBoardId], scroll);
setTimeout(() => scroll(), 400);
return /* @__PURE__ */ createElement("div", { id: "task-page" }, listPaneWrapper, mainPageWrapper); return /* @__PURE__ */ createElement("div", { id: "task-page" }, listPaneWrapper, mainPageWrapper);
} }
+6 -2
View File
@@ -80,14 +80,18 @@ export function TaskPage(taskPageViewModel: TaskPageViewModel) {
<div class="pane-wrapper" children:set={paneContent}></div> <div class="pane-wrapper" children:set={paneContent}></div>
); );
React.bulkSubscribe([taskPageViewModel.selectedBoardId], () => { function scroll() {
{
const selectedBoard = taskPageViewModel.selectedBoardId.value; const selectedBoard = taskPageViewModel.selectedBoardId.value;
if (selectedBoard == undefined) { if (selectedBoard == undefined) {
listPaneWrapper.scrollIntoView(); listPaneWrapper.scrollIntoView();
} else { } else {
mainPageWrapper.scrollIntoView(); mainPageWrapper.scrollIntoView();
} }
}); }
}
React.bulkSubscribe([taskPageViewModel.selectedBoardId], scroll);
setTimeout(() => scroll(), 400)
return ( return (
<div id="task-page"> <div id="task-page">
+4 -4
View File
@@ -37,9 +37,7 @@ export default class ChatViewModel {
this.chatListViewModel.closeChat(); this.chatListViewModel.closeChat();
}; };
closeSubPages = (): void => { closeSubPages = (): void => {};
this.taskPageViewModel.closeBoard();
};
setColor = (color: Color): void => { setColor = (color: Color): void => {
this.setDisplayedColor(color); this.setDisplayedColor(color);
@@ -55,7 +53,8 @@ export default class ChatViewModel {
}; };
updateIndex = (): void => { updateIndex = (): void => {
const index: number = this.chatListViewModel.chatIndexManager.getIndex(this); const index: number =
this.chatListViewModel.chatIndexManager.getIndex(this);
this.index.value = index; this.index.value = index;
}; };
@@ -72,6 +71,7 @@ export default class ChatViewModel {
this.selectedPage.subscribeSilent((newPage) => { this.selectedPage.subscribeSilent((newPage) => {
this.storageModel.write(path, 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 (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 // state
newBoardNameInput: React.State<string> = new React.State(""); newBoardNameInput: React.State<string> = new React.State("");
@@ -80,11 +97,15 @@ export default class TaskPageViewModel {
selectBoard = (boardViewModel: BoardViewModel): void => { selectBoard = (boardViewModel: BoardViewModel): void => {
this.selectedBoardId.value = boardViewModel.boardInfo.fileId; this.selectedBoardId.value = boardViewModel.boardInfo.fileId;
this.chatViewModel.displayedColor.value = boardViewModel.color.value; this.chatViewModel.displayedColor.value = boardViewModel.color.value;
this.storeLastUsedBoard();
}; };
closeBoard = (): void => { closeBoard = (): void => {
this.selectedBoardId.value = undefined; this.selectedBoardId.value = undefined;
this.chatViewModel.resetColor(); this.chatViewModel.resetColor();
this.storeLastUsedBoard();
}; };
updateIndices = (): void => { 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 // load
loadData = (): void => { loadData = (): void => {
this.boardViewModels.clear(); this.boardViewModels.clear();
@@ -108,6 +148,7 @@ export default class TaskPageViewModel {
} }
this.updateIndices(); this.updateIndices();
this.openLastUsedBoard();
}; };
// init // init
@@ -132,6 +173,7 @@ export default class TaskPageViewModel {
} }
export enum TaskPageViewModelSubPaths { export enum TaskPageViewModelSubPaths {
LastUsedBoard = "last-used-board", View = "view",
ViewLastUsedBoard = "last-used-board",
BoardLastUsedView = "last-used-view", BoardLastUsedView = "last-used-view",
}; }