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
+22 -7
View File
@@ -352,6 +352,7 @@
// chat etc // chat etc
chats: [DATA_VERSION, "chat"], chats: [DATA_VERSION, "chat"],
chatInfo: (id) => [DATA_VERSION, "chat", id, "info"], chatInfo: (id) => [DATA_VERSION, "chat", id, "info"],
chatLastUsedPage: (id) => [DATA_VERSION, "chat", id, "last-used-page"],
chatMessages: (id) => [DATA_VERSION, "chat", id, "messages"], chatMessages: (id) => [DATA_VERSION, "chat", id, "messages"],
chatObjects: (id) => [DATA_VERSION, "chat", id, "objects"], chatObjects: (id) => [DATA_VERSION, "chat", id, "objects"],
chatOutbox: (id) => [DATA_VERSION, "chat", id, "outbox"] chatOutbox: (id) => [DATA_VERSION, "chat", id, "outbox"]
@@ -513,11 +514,12 @@
var ChatViewModel = class { var ChatViewModel = class {
chatModel; chatModel;
chatListViewModel; chatListViewModel;
storageModel;
// state // state
primaryChannel = new State(""); primaryChannel = new State("");
primaryChannelInput = new State(""); primaryChannelInput = new State("");
selectedPage = new State( selectedPage = new State(
1 /* Messages */ "messages" /* Messages */
); );
// guards // guards
cannotSetPrimaryChannel = createProxyState( cannotSetPrimaryChannel = createProxyState(
@@ -531,12 +533,25 @@
close = () => { close = () => {
this.chatListViewModel.closeChat(); this.chatListViewModel.closeChat();
}; };
// restore
restorePageSelection = () => {
const path = storageKeys.chatLastUsedPage(this.chatModel.id);
const lastUsedPage = this.storageModel.restore(path);
if (lastUsedPage != null) {
this.selectedPage.value = lastUsedPage;
}
this.selectedPage.subscribeSilent((newPage) => {
this.storageModel.store(path, newPage);
});
};
// init // init
constructor(chatListViewModel2, chatModel) { constructor(chatListViewModel2, chatModel) {
this.chatModel = chatModel; this.chatModel = chatModel;
this.storageModel = chatModel.storageModel;
this.chatListViewModel = chatListViewModel2; this.chatListViewModel = chatListViewModel2;
this.primaryChannel.value = chatModel.info.primaryChannel; this.primaryChannel.value = chatModel.info.primaryChannel;
this.primaryChannelInput.value = chatModel.info.primaryChannel; this.primaryChannelInput.value = chatModel.info.primaryChannel;
this.restorePageSelection();
} }
}; };
@@ -692,32 +707,32 @@
)), /* @__PURE__ */ createElement("span", null, ChatViewToggleButton( )), /* @__PURE__ */ createElement("span", null, ChatViewToggleButton(
translations.chatPage.pages.calendar, translations.chatPage.pages.calendar,
"calendar_month", "calendar_month",
4 /* Calendar */, "calendar" /* Calendar */,
chatViewModel chatViewModel
), ChatViewToggleButton( ), ChatViewToggleButton(
translations.chatPage.pages.progress, translations.chatPage.pages.progress,
"window", "window",
5 /* Progress */, "progress" /* Progress */,
chatViewModel chatViewModel
), ChatViewToggleButton( ), ChatViewToggleButton(
translations.chatPage.pages.kanban, translations.chatPage.pages.kanban,
"view_kanban", "view_kanban",
3 /* Kanban */, "kanban" /* Kanban */,
chatViewModel chatViewModel
), ChatViewToggleButton( ), ChatViewToggleButton(
translations.chatPage.pages.allObjects, translations.chatPage.pages.allObjects,
"deployed_code", "deployed_code",
2 /* AllObjects */, "all" /* AllObjects */,
chatViewModel chatViewModel
), ChatViewToggleButton( ), ChatViewToggleButton(
translations.chatPage.pages.messages, translations.chatPage.pages.messages,
"forum", "forum",
1 /* Messages */, "messages" /* Messages */,
chatViewModel chatViewModel
), ChatViewToggleButton( ), ChatViewToggleButton(
translations.chatPage.pages.settings, translations.chatPage.pages.settings,
"settings", "settings",
0 /* Settings */, "settings" /* Settings */,
chatViewModel chatViewModel
))), /* @__PURE__ */ createElement("div", { id: "toolbar" }), /* @__PURE__ */ createElement("div", { id: "main" }))); ))), /* @__PURE__ */ createElement("div", { id: "toolbar" }), /* @__PURE__ */ createElement("div", { id: "main" })));
} }
+1
View File
@@ -145,6 +145,7 @@ export const storageKeys = {
// chat etc // chat etc
chats: [DATA_VERSION, "chat"], chats: [DATA_VERSION, "chat"],
chatInfo: (id: string) => [DATA_VERSION, "chat", id, "info"], 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"], chatMessages: (id: string) => [DATA_VERSION, "chat", id, "messages"],
chatObjects: (id: string) => [DATA_VERSION, "chat", id, "objects"], chatObjects: (id: string) => [DATA_VERSION, "chat", id, "objects"],
chatOutbox: (id: string) => [DATA_VERSION, "chat", id, "outbox"], chatOutbox: (id: string) => [DATA_VERSION, "chat", id, "outbox"],
+27 -9
View File
@@ -1,12 +1,14 @@
import * as React from "bloatless-react"; import * as React from "bloatless-react";
import StorageModel, { storageKeys } from "../Model/storageModel";
import ChatListViewModel from "./chatListViewModel"; import ChatListViewModel from "./chatListViewModel";
import { ChatModel } from "../Model/chatModel"; import { ChatModel } from "../Model/chatModel";
import StorageModel from "../Model/storageModel";
export default class ChatViewModel { export default class ChatViewModel {
chatModel: ChatModel; chatModel: ChatModel;
chatListViewModel: ChatListViewModel; chatListViewModel: ChatListViewModel;
storageModel: StorageModel;
// state // state
primaryChannel: React.State<string> = new React.State(""); primaryChannel: React.State<string> = new React.State("");
@@ -25,30 +27,46 @@ export default class ChatViewModel {
); );
// methods // methods
open = () => { open = (): void => {
this.chatListViewModel.openChat(this); this.chatListViewModel.openChat(this);
}; };
close = () => { close = (): void => {
this.chatListViewModel.closeChat(); 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 // init
constructor(chatListViewModel: ChatListViewModel, chatModel: ChatModel) { constructor(chatListViewModel: ChatListViewModel, chatModel: ChatModel) {
this.chatModel = chatModel; this.chatModel = chatModel;
this.storageModel = chatModel.storageModel;
this.chatListViewModel = chatListViewModel; this.chatListViewModel = chatListViewModel;
this.primaryChannel.value = chatModel.info.primaryChannel; this.primaryChannel.value = chatModel.info.primaryChannel;
this.primaryChannelInput.value = chatModel.info.primaryChannel; this.primaryChannelInput.value = chatModel.info.primaryChannel;
this.restorePageSelection();
} }
} }
// types // types
export enum ChatPageType { export enum ChatPageType {
Settings, Settings = "settings",
Messages, Messages = "messages",
AllObjects, AllObjects = "all",
Kanban, Kanban = "kanban",
Calendar, Calendar = "calendar",
Progress, Progress = "progress",
} }