update paths, persist selected view in board

This commit is contained in:
marlon-erler
2024-07-23 21:33:22 +02:00
parent c49b16449b
commit 7543090c38
6 changed files with 96 additions and 8 deletions
+39 -3
View File
@@ -579,6 +579,9 @@
getBasePath = () => { getBasePath = () => {
return this.fileModel.getModelContainerPath("tasks" /* ModelTask */); return this.fileModel.getModelContainerPath("tasks" /* ModelTask */);
}; };
getViewPath = () => {
return [...this.getBasePath(), "view" /* ModelView */];
};
getBoardFilePath = (boardId) => { getBoardFilePath = (boardId) => {
return [...this.fileModel.getFilePath(boardId)]; return [...this.fileModel.getFilePath(boardId)];
}; };
@@ -1411,6 +1414,7 @@
// src/ViewModel/Pages/boardViewModel.ts // src/ViewModel/Pages/boardViewModel.ts
var BoardViewModel = class { var BoardViewModel = class {
storageModel;
taskPageViewModel; taskPageViewModel;
// state // state
boardInfo; boardInfo;
@@ -1424,6 +1428,13 @@
"list" /* List */ "list" /* List */
); );
index = new State(0); index = new State(0);
// paths
getBasePath = () => {
return [...this.taskPageViewModel.getBoardViewPath(this.boardInfo.fileId)];
};
getLastUsedBoardPath = () => {
return [...this.getBasePath(), "last-used-view" /* LastUsedView */];
};
// view // view
select = () => { select = () => {
this.taskPageViewModel.selectBoard(this); this.taskPageViewModel.selectBoard(this);
@@ -1470,15 +1481,29 @@
this.taskPageViewModel.deleteBoard(this.boardInfo); this.taskPageViewModel.deleteBoard(this.boardInfo);
this.close(); this.close();
}; };
// store
storeLastUsedView = () => {
const path = this.getLastUsedBoardPath();
const lastUsedView = this.selectedPage.value;
this.storageModel.write(path, lastUsedView);
};
restoreLastUsedView = () => {
const path = this.getLastUsedBoardPath();
const lastUsedView = this.storageModel.read(path);
if (lastUsedView == null) return;
this.selectedPage.value = lastUsedView;
};
// load // load
loadListRelevantData = () => { loadListRelevantData = () => {
this.name.value = this.boardInfo.name; this.name.value = this.boardInfo.name;
this.color.value = this.boardInfo.color; this.color.value = this.boardInfo.color;
}; };
loadData = () => { loadData = () => {
this.restoreLastUsedView();
}; };
// init // init
constructor(taskPageViewModel, boardInfo) { constructor(taskPageViewModel, boardInfo, storageModel2) {
this.storageModel = storageModel2;
this.taskPageViewModel = taskPageViewModel; this.taskPageViewModel = taskPageViewModel;
this.boardInfo = boardInfo; this.boardInfo = boardInfo;
this.loadListRelevantData(); this.loadListRelevantData();
@@ -1490,6 +1515,9 @@
if (this.isSelected.value == false) return; if (this.isSelected.value == false) return;
this.applyColor(); this.applyColor();
}); });
this.selectedPage.subscribeSilent(() => {
this.storeLastUsedView();
});
} }
}; };
@@ -1504,7 +1532,10 @@
); );
// paths // paths
getBasePath = () => { getBasePath = () => {
return [...this.taskModel.getBasePath()]; return [...this.taskModel.getViewPath()];
};
getBoardViewPath = (boardId) => {
return [...this.getBasePath(), boardId];
}; };
getLastUsedBoardPath = () => { getLastUsedBoardPath = () => {
return [...this.getBasePath(), "last-used-board" /* LastUsedBoard */]; return [...this.getBasePath(), "last-used-board" /* LastUsedBoard */];
@@ -1543,7 +1574,11 @@
}; };
// view // view
showBoardInList = (boardInfo) => { showBoardInList = (boardInfo) => {
const boardViewModel = new BoardViewModel(this, boardInfo); const boardViewModel = new BoardViewModel(
this,
boardInfo,
this.storageModel
);
this.boardViewModels.set(boardInfo.fileId, boardViewModel); this.boardViewModels.set(boardInfo.fileId, boardViewModel);
}; };
selectBoard = (boardViewModel) => { selectBoard = (boardViewModel) => {
@@ -2201,6 +2236,7 @@
// src/View/ChatPages/boardPage.tsx // src/View/ChatPages/boardPage.tsx
function BoardPage(boardViewModel) { function BoardPage(boardViewModel) {
boardViewModel.loadData();
return /* @__PURE__ */ createElement("div", { class: "pane" }, /* @__PURE__ */ createElement("div", { class: "toolbar" }, /* @__PURE__ */ createElement("span", null, /* @__PURE__ */ createElement( return /* @__PURE__ */ createElement("div", { class: "pane" }, /* @__PURE__ */ createElement("div", { class: "toolbar" }, /* @__PURE__ */ createElement("span", null, /* @__PURE__ */ createElement(
"button", "button",
{ {
+1
View File
@@ -170,6 +170,7 @@ export default class FileModel {
export enum FileModelSubPath { export enum FileModelSubPath {
Data = "data", Data = "data",
Model = "model", Model = "model",
ModelView = "view",
ModelTask = "tasks", ModelTask = "tasks",
}; };
+5 -1
View File
@@ -26,6 +26,10 @@ export default class TaskModel {
return this.fileModel.getModelContainerPath(FileModelSubPath.ModelTask); return this.fileModel.getModelContainerPath(FileModelSubPath.ModelTask);
}; };
getViewPath = (): string[] => {
return [...this.getBasePath(), FileModelSubPath.ModelView];
};
getBoardFilePath = (boardId: string): string[] => { getBoardFilePath = (boardId: string): string[] => {
return [...this.fileModel.getFilePath(boardId)]; return [...this.fileModel.getFilePath(boardId)];
}; };
@@ -222,7 +226,7 @@ export default class TaskModel {
export enum TaskModelSubPaths { export enum TaskModelSubPaths {
Boards = "boards", Boards = "boards",
BoardTasks = "tasks", BoardTasks = "tasks",
}; }
// types // types
export interface BoardInfoFileContent extends FileContent<"board-info"> { export interface BoardInfoFileContent extends FileContent<"board-info"> {
+2
View File
@@ -9,6 +9,8 @@ import { BoardViewToggleButton } from "../Components/boardViewToggleButton";
import { translations } from "../translations"; import { translations } from "../translations";
export function BoardPage(boardViewModel: BoardViewModel) { export function BoardPage(boardViewModel: BoardViewModel) {
boardViewModel.loadData();
return ( return (
<div class="pane"> <div class="pane">
<div class="toolbar"> <div class="toolbar">
+39 -2
View File
@@ -3,9 +3,11 @@ import * as React from "bloatless-react";
import TaskModel, { BoardInfoFileContent } from "../../Model/Files/taskModel"; import TaskModel, { BoardInfoFileContent } from "../../Model/Files/taskModel";
import { Color } from "../../colors"; import { Color } from "../../colors";
import StorageModel from "../../Model/Global/storageModel";
import TaskPageViewModel from "./taskPageViewModel"; import TaskPageViewModel from "./taskPageViewModel";
export default class BoardViewModel { export default class BoardViewModel {
storageModel: StorageModel;
taskPageViewModel: TaskPageViewModel; taskPageViewModel: TaskPageViewModel;
// state // state
@@ -25,6 +27,15 @@ export default class BoardViewModel {
index: React.State<number> = new React.State(0); index: React.State<number> = new React.State(0);
// paths
getBasePath = (): string[] => {
return [...this.taskPageViewModel.getBoardViewPath(this.boardInfo.fileId)];
};
getLastUsedBoardPath = (): string[] => {
return [...this.getBasePath(), BoardViewModelSubPaths.LastUsedView];
};
// view // view
select = (): void => { select = (): void => {
this.taskPageViewModel.selectBoard(this); this.taskPageViewModel.selectBoard(this);
@@ -85,19 +96,38 @@ export default class BoardViewModel {
this.close(); this.close();
}; };
// store
storeLastUsedView = (): void => {
const path: string[] = this.getLastUsedBoardPath();
const lastUsedView: string = this.selectedPage.value;
this.storageModel.write(path, lastUsedView);
};
restoreLastUsedView = (): void => {
const path: string[] = this.getLastUsedBoardPath();
const lastUsedView: string | null = this.storageModel.read(path);
if (lastUsedView == null) return;
this.selectedPage.value = lastUsedView as BoardPageType;
};
// load // load
loadListRelevantData = (): void => { loadListRelevantData = (): void => {
this.name.value = this.boardInfo.name; this.name.value = this.boardInfo.name;
this.color.value = this.boardInfo.color; this.color.value = this.boardInfo.color;
}; };
loadData = (): void => {}; loadData = (): void => {
this.restoreLastUsedView();
};
// init // init
constructor( constructor(
taskPageViewModel: TaskPageViewModel, taskPageViewModel: TaskPageViewModel,
boardInfo: BoardInfoFileContent boardInfo: BoardInfoFileContent,
storageModel: StorageModel
) { ) {
this.storageModel = storageModel;
this.taskPageViewModel = taskPageViewModel; this.taskPageViewModel = taskPageViewModel;
this.boardInfo = boardInfo; this.boardInfo = boardInfo;
@@ -113,9 +143,16 @@ export default class BoardViewModel {
if (this.isSelected.value == false) return; if (this.isSelected.value == false) return;
this.applyColor(); this.applyColor();
}); });
this.selectedPage.subscribeSilent(() => {
this.storeLastUsedView();
});
} }
} }
export enum BoardViewModelSubPaths {
LastUsedView = "last-used-view",
}
// types // types
export enum BoardPageType { export enum BoardPageType {
List = "list", List = "list",
+10 -2
View File
@@ -25,7 +25,11 @@ export default class TaskPageViewModel {
// paths // paths
getBasePath = (): string[] => { getBasePath = (): string[] => {
return [...this.taskModel.getBasePath()]; return [...this.taskModel.getViewPath()];
};
getBoardViewPath = (boardId): string[] => {
return [...this.getBasePath(), boardId];
}; };
getLastUsedBoardPath = (): string[] => { getLastUsedBoardPath = (): string[] => {
@@ -82,7 +86,11 @@ export default class TaskPageViewModel {
// view // view
showBoardInList = (boardInfo: BoardInfoFileContent): void => { showBoardInList = (boardInfo: BoardInfoFileContent): void => {
const boardViewModel: BoardViewModel = new BoardViewModel(this, boardInfo); const boardViewModel: BoardViewModel = new BoardViewModel(
this,
boardInfo,
this.storageModel
);
this.boardViewModels.set(boardInfo.fileId, boardViewModel); this.boardViewModels.set(boardInfo.fileId, boardViewModel);
}; };