From 43af74832f9a2fa7f40dc71985eec9b0ada087dd Mon Sep 17 00:00:00 2001 From: Kit La Touche Date: Tue, 11 Feb 2025 23:16:16 -0500 Subject: Merge local channel data and remote to maintain state When we hit the boot endpoint, we get the server's view of things. If we just setChannels with that, we overwrite all our locally-stored info in on things like lastReadAt. So we need to merge data. Eventually, this might militate for a `meta` key containing an object of locally stored data, rather than having to handle each key specially. --- ui/lib/store.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ui/lib/store.js') diff --git a/ui/lib/store.js b/ui/lib/store.js index 47ebbc2..f408c0c 100644 --- a/ui/lib/store.js +++ b/ui/lib/store.js @@ -1,9 +1,13 @@ import { writable } from 'svelte/store'; +import { browser } from '$app/environment'; import { Channels } from '$lib/store/channels.svelte.js'; import { Messages } from '$lib/store/messages.svelte.js'; import { Logins } from '$lib/store/logins'; +// Get channelsList content from the local storage +const channelsData = (browser && JSON.parse(localStorage.getItem('pilcrow:channelsData'))) || {}; + export const currentUser = writable(null); export const logins = writable(new Logins()); -export const channelsList = writable(new Channels()); +export const channelsList = writable(new Channels({ channelsData })); export const messages = writable(new Messages()); -- cgit v1.2.3