remember what view was used for chat objects

This commit is contained in:
marlon-erler
2024-07-12 02:30:50 +02:00
parent 4a36bbcc2d
commit e059427f86
4 changed files with 26 additions and 8 deletions
+8
View File
@@ -16,6 +16,7 @@ import { decryptString, encryptString } from "../cryptUtility";
import { Message } from "udn-frontend";
import { storageKeys } from "../utility";
import { translation } from "../translations";
import { viewTypes } from "../Views/Objects/objectPane";
// TYPES
// message
@@ -50,6 +51,8 @@ export interface MessageObjectContent {
export class Chat {
id: string;
viewType: React.State<keyof typeof viewTypes>;
isSubscribed = new React.State(false);
primaryChannel = new React.State("");
hasUnreadMessages: React.State<boolean>;
@@ -78,6 +81,11 @@ export class Chat {
constructor(id: string = React.UUID()) {
this.id = id;
this.viewType = React.restoreState<keyof typeof viewTypes>(
storageKeys.viewType(id),
"all"
);
// channels
this.primaryChannel = React.restoreState(
storageKeys.primaryChannel(id),
+3 -4
View File
@@ -33,10 +33,9 @@ export function ObjectPane(chat: Chat) {
);
// view type
const selectedViewType = new React.State<keyof typeof viewTypes>("all");
const mainView = React.createProxyState([selectedViewType], () => {
const mainView = React.createProxyState([chat.viewType], () => {
function getViewFunction() {
switch (selectedViewType.value) {
switch (chat.viewType.value) {
case "notes":
return NoteObjectsView;
case "kanban":
@@ -70,7 +69,7 @@ export function ObjectPane(chat: Chat) {
<div class="padding-sm flex flex-row gap justify-center scroll-h width-100">
{...Object.keys(viewTypes).map((key: any) =>
ViewTypeToggle(key, selectedViewType)
ViewTypeToggle(key, chat.viewType)
)}
</div>
+4
View File
@@ -1,6 +1,10 @@
import * as React from "bloatless-react";
export const storageKeys = {
viewType(id: string): string {
return id + "view-type";
},
hasUnread(id: string): string {
return id + "has-unread-messages";
},