remember last used chat page
This commit is contained in:
Vendored
+22
-7
@@ -352,6 +352,7 @@
|
||||
// chat etc
|
||||
chats: [DATA_VERSION, "chat"],
|
||||
chatInfo: (id) => [DATA_VERSION, "chat", id, "info"],
|
||||
chatLastUsedPage: (id) => [DATA_VERSION, "chat", id, "last-used-page"],
|
||||
chatMessages: (id) => [DATA_VERSION, "chat", id, "messages"],
|
||||
chatObjects: (id) => [DATA_VERSION, "chat", id, "objects"],
|
||||
chatOutbox: (id) => [DATA_VERSION, "chat", id, "outbox"]
|
||||
@@ -513,11 +514,12 @@
|
||||
var ChatViewModel = class {
|
||||
chatModel;
|
||||
chatListViewModel;
|
||||
storageModel;
|
||||
// state
|
||||
primaryChannel = new State("");
|
||||
primaryChannelInput = new State("");
|
||||
selectedPage = new State(
|
||||
1 /* Messages */
|
||||
"messages" /* Messages */
|
||||
);
|
||||
// guards
|
||||
cannotSetPrimaryChannel = createProxyState(
|
||||
@@ -531,12 +533,25 @@
|
||||
close = () => {
|
||||
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
|
||||
constructor(chatListViewModel2, chatModel) {
|
||||
this.chatModel = chatModel;
|
||||
this.storageModel = chatModel.storageModel;
|
||||
this.chatListViewModel = chatListViewModel2;
|
||||
this.primaryChannel.value = chatModel.info.primaryChannel;
|
||||
this.primaryChannelInput.value = chatModel.info.primaryChannel;
|
||||
this.restorePageSelection();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -692,32 +707,32 @@
|
||||
)), /* @__PURE__ */ createElement("span", null, ChatViewToggleButton(
|
||||
translations.chatPage.pages.calendar,
|
||||
"calendar_month",
|
||||
4 /* Calendar */,
|
||||
"calendar" /* Calendar */,
|
||||
chatViewModel
|
||||
), ChatViewToggleButton(
|
||||
translations.chatPage.pages.progress,
|
||||
"window",
|
||||
5 /* Progress */,
|
||||
"progress" /* Progress */,
|
||||
chatViewModel
|
||||
), ChatViewToggleButton(
|
||||
translations.chatPage.pages.kanban,
|
||||
"view_kanban",
|
||||
3 /* Kanban */,
|
||||
"kanban" /* Kanban */,
|
||||
chatViewModel
|
||||
), ChatViewToggleButton(
|
||||
translations.chatPage.pages.allObjects,
|
||||
"deployed_code",
|
||||
2 /* AllObjects */,
|
||||
"all" /* AllObjects */,
|
||||
chatViewModel
|
||||
), ChatViewToggleButton(
|
||||
translations.chatPage.pages.messages,
|
||||
"forum",
|
||||
1 /* Messages */,
|
||||
"messages" /* Messages */,
|
||||
chatViewModel
|
||||
), ChatViewToggleButton(
|
||||
translations.chatPage.pages.settings,
|
||||
"settings",
|
||||
0 /* Settings */,
|
||||
"settings" /* Settings */,
|
||||
chatViewModel
|
||||
))), /* @__PURE__ */ createElement("div", { id: "toolbar" }), /* @__PURE__ */ createElement("div", { id: "main" })));
|
||||
}
|
||||
|
||||
@@ -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"],
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user