aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-03-01 21:59:08 -0800
committerAdam Soltys <[email protected]>2026-03-01 21:59:08 -0800
commit135cb1107c01cea692df7a6bba035f99dca9137d (patch)
treef3dd6414e5f54fe895c487f57a27b2a163883578 /src
parentc712523e8ce124973341c27ac8bc675fe42c20e0 (diff)
downloadcoinos-ui-135cb1107c01cea692df7a6bba035f99dca9137d.tar.gz
coinos-ui-135cb1107c01cea692df7a6bba035f99dca9137d.zip
cache chats in localstorage
Diffstat (limited to 'src')
-rw-r--r--src/routes/(app)/messages/+page.svelte17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/routes/(app)/messages/+page.svelte b/src/routes/(app)/messages/+page.svelte
index 6eb5a399..87198cb6 100644
--- a/src/routes/(app)/messages/+page.svelte
+++ b/src/routes/(app)/messages/+page.svelte
@@ -85,10 +85,14 @@
return latest?.content || "";
};
- // Initialize from cache immediately
+ // Restore from localStorage on hard refresh, or in-memory cache on SPA nav
+ const storageKey = `chatList:${data.user?.pubkey}`;
const cachedList = getCachedChatList(data.user?.pubkey);
- let chats: any[] = $state(cachedList?.chats ?? []);
- let allRumours: any[] = $state(cachedList?.rumours ?? []);
+ let stored: any = null;
+ try { stored = JSON.parse(localStorage.getItem(storageKey) || "null"); } catch {}
+ let chats: any[] = $state(cachedList?.chats ?? stored?.chats ?? []);
+ let allRumours: any[] = $state(cachedList?.rumours ?? stored?.rumours ?? []);
+ let loaded = $state(chats.length > 0);
const updateSendersRecipients = async (rumours: any[]) => {
allRumours = rumours;
@@ -114,9 +118,10 @@
(mostRecentCommunication(rumours, a.pubkey) ?? 0),
);
setCachedChatList(user.pubkey, chats, allRumours);
+ try { localStorage.setItem(storageKey, JSON.stringify({ chats, rumours })); } catch {}
};
- (() => getMessageRumours(data.user).then(updateSendersRecipients))();
+ (() => getMessageRumours(data.user).then(updateSendersRecipients).then(() => (loaded = true)))();
let closeSub: (() => void) | undefined;
@@ -134,7 +139,9 @@
</script>
<div class="container mx-auto max-w-xl px-4 space-y-4">
- {#if chats.length === 0}
+ {#if !loaded}
+ <div class="flex justify-center py-8"><div class="loading loading-spinner"></div></div>
+ {:else if chats.length === 0}
<p class="text-center text-secondary">{$t("dm.noChats")}</p>
{:else}
{#each chats as c}