remember last used chat page
This commit is contained in:
@@ -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