diff --git a/src/lib/components/ui/navbar/commands/Commands.svelte b/src/lib/components/ui/navbar/commands/Commands.svelte
index 0b42e314..9ac9c186 100644
--- a/src/lib/components/ui/navbar/commands/Commands.svelte
+++ b/src/lib/components/ui/navbar/commands/Commands.svelte
@@ -303,7 +303,7 @@
diff --git a/src/lib/lemmy/item.ts b/src/lib/lemmy/item.ts
index e6932203..6a1c1361 100644
--- a/src/lib/lemmy/item.ts
+++ b/src/lib/lemmy/item.ts
@@ -72,7 +72,7 @@ export const isPrivateMessageReport = (
export interface ResumableItem {
url: string
- id: number
+ id?: number
name: string
avatar?: string
type: 'community' | 'post'
@@ -82,7 +82,23 @@ export interface ResumableItem {
}
}
-export let resumables = writable([])
+function resumableStore(limit: number = 10) {
+ const { subscribe, set, update } = writable([])
+
+ return {
+ subscribe, set, update,
+ add: (item: ResumableItem) => {
+ update(resumables => {
+ if (resumables.find(i => JSON.stringify(i) == JSON.stringify(item))) return resumables
+ resumables.unshift(item)
+ if (resumables.length > limit) resumables.pop()
+ return resumables
+ })
+ }
+ }
+}
+
+export let resumables = resumableStore()
export function addFavorite(item: Community, add: boolean = true) {
const pd = get(profileData)
diff --git a/src/routes/c/[name]/+page.svelte b/src/routes/c/[name]/+page.svelte
index e6928815..0ab14a10 100644
--- a/src/routes/c/[name]/+page.svelte
+++ b/src/routes/c/[name]/+page.svelte
@@ -32,6 +32,7 @@
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
import Subscribe from '../../communities/Subscribe.svelte'
+ import { resumables } from '$lib/lemmy/item'
export let data
@@ -45,6 +46,13 @@
'lastSeenCommunity',
data.community.community_view.community,
)
+
+ resumables.add({
+ name: community.community.title,
+ type: 'community',
+ url: $page.url.toString(),
+ avatar: community.community.icon,
+ })
})
onDestroy(() => {
diff --git a/src/routes/post/[instance]/[id=integer]/+page.svelte b/src/routes/post/[instance]/[id=integer]/+page.svelte
index c113a7e8..ac948d75 100644
--- a/src/routes/post/[instance]/[id=integer]/+page.svelte
+++ b/src/routes/post/[instance]/[id=integer]/+page.svelte
@@ -64,17 +64,12 @@
})
}
- if (!$resumables.find((r) => r.url == $page.url.toString()))
- $resumables = [
- {
- id: Math.floor(Math.random() * 1000000),
- name: post.post_view.post.name,
- type: 'post',
- url: $page.url.toString(),
- avatar: post.post_view.post.thumbnail_url,
- },
- ...$resumables,
- ]
+ resumables.add({
+ name: post.post_view.post.name,
+ type: 'post',
+ url: $page.url.toString(),
+ avatar: post.post_view.post.thumbnail_url,
+ })
})
afterNavigate(async () => {