frontend: add generic StorageItemStore

This commit is contained in:
hippoz 2022-05-07 03:36:27 +03:00
parent 704b35ae2b
commit a725e46ff0
Signed by: hippoz
GPG key ID: 7C52899193467641

View file

@ -45,6 +45,13 @@ class Store {
} }
} }
class StorageItemStore extends Store {
constructor(key) {
super(getItem(key), `StorageItemStore[key=${key}]`);
this.watch(e => setItem(key, e));
}
}
class ChannelsStore extends Store { class ChannelsStore extends Store {
constructor() { constructor() {
super(gateway.channels || [], "ChannelsStore"); super(gateway.channels || [], "ChannelsStore");
@ -309,7 +316,7 @@ export const selectedChannel = new Store({ id: getItem("app:cache:openChannelId"
export const showSidebar = new Store(false, "showSidebar"); export const showSidebar = new Store(false, "showSidebar");
export const showChannelView = new Store(true, "showChannelView"); export const showChannelView = new Store(true, "showChannelView");
export const smallViewport = new Store(false, "smallViewport"); export const smallViewport = new Store(false, "smallViewport");
export const theme = new Store(getItem("app:visual:theme"), "theme"); export const theme = new StorageItemStore("app:visual:theme");
export const channels = new ChannelsStore(); export const channels = new ChannelsStore();
export const gatewayStatus = new GatewayStatusStore(); export const gatewayStatus = new GatewayStatusStore();
export const messagesStoreProvider = new MessagesStoreProvider(); export const messagesStoreProvider = new MessagesStoreProvider();
@ -332,7 +339,3 @@ export const allStores = {
selectedChannel.watch((newSelectedChannel) => { selectedChannel.watch((newSelectedChannel) => {
setItem("app:cache:openChannelId", newSelectedChannel.id); setItem("app:cache:openChannelId", newSelectedChannel.id);
}); });
theme.watch((newTheme) => {
setItem("app:visual:theme", newTheme);
});