remember last used chat page

This commit is contained in:
marlon-erler
2024-07-20 16:34:16 +02:00
parent e27c360395
commit 5dedd9fb23
3 changed files with 50 additions and 16 deletions
+1
View File
@@ -145,6 +145,7 @@ export const storageKeys = {
// chat etc
chats: [DATA_VERSION, "chat"],
chatInfo: (id: string) => [DATA_VERSION, "chat", id, "info"],
chatLastUsedPage: (id: string) => [DATA_VERSION, "chat", id, "last-used-page"],
chatMessages: (id: string) => [DATA_VERSION, "chat", id, "messages"],
chatObjects: (id: string) => [DATA_VERSION, "chat", id, "objects"],
chatOutbox: (id: string) => [DATA_VERSION, "chat", id, "outbox"],
+27 -9
View File
@@ -1,12 +1,14 @@
import * as React from "bloatless-react";
import StorageModel, { storageKeys } from "../Model/storageModel";
import ChatListViewModel from "./chatListViewModel";
import { ChatModel } from "../Model/chatModel";
import StorageModel from "../Model/storageModel";
export default class ChatViewModel {
chatModel: ChatModel;
chatListViewModel: ChatListViewModel;
storageModel: StorageModel;
// state
primaryChannel: React.State<string> = new React.State("");
@@ -25,30 +27,46 @@ export default class ChatViewModel {
);
// methods
open = () => {
open = (): void => {
this.chatListViewModel.openChat(this);
};
close = () => {
close = (): void => {
this.chatListViewModel.closeChat();
};
// restore
restorePageSelection = (): void => {
const path: string[] = storageKeys.chatLastUsedPage(this.chatModel.id);
const lastUsedPage: string | null = this.storageModel.restore(path);
if (lastUsedPage != null) {
this.selectedPage.value = lastUsedPage as any;
}
this.selectedPage.subscribeSilent((newPage) => {
this.storageModel.store(path, newPage);
});
};
// init
constructor(chatListViewModel: ChatListViewModel, chatModel: ChatModel) {
this.chatModel = chatModel;
this.storageModel = chatModel.storageModel;
this.chatListViewModel = chatListViewModel;
this.primaryChannel.value = chatModel.info.primaryChannel;
this.primaryChannelInput.value = chatModel.info.primaryChannel;
this.restorePageSelection();
}
}
// types
export enum ChatPageType {
Settings,
Messages,
AllObjects,
Kanban,
Calendar,
Progress,
Settings = "settings",
Messages = "messages",
AllObjects = "all",
Kanban = "kanban",
Calendar = "calendar",
Progress = "progress",
}