feat: add community resumables
This commit is contained in:
1 parent
98a597c0d3
commit
47b8b21ede
4 files changed
+33
-14
No files matched your search
@@ -303,7 +303,7 @@
|
|||||||
<CommandItem
|
<CommandItem
|
||||||
{action}
|
{action}
|
||||||
class="{globalIndex == selectedIndex
|
class="{globalIndex == selectedIndex
|
||||||
? 'bg-slate-200 dark:bg-zinc-800 text-inherit'
|
? '!bg-slate-100 dark:!bg-zinc-800 text-inherit'
|
||||||
: 'text-slate-600 dark:text-zinc-400'} block"
|
: 'text-slate-600 dark:text-zinc-400'} block"
|
||||||
/>
|
/>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
+18
-2
@@ -72,7 +72,7 @@ export const isPrivateMessageReport = (
|
|||||||
|
|
||||||
export interface ResumableItem {
|
export interface ResumableItem {
|
||||||
url: string
|
url: string
|
||||||
id: number
|
id?: number
|
||||||
name: string
|
name: string
|
||||||
avatar?: string
|
avatar?: string
|
||||||
type: 'community' | 'post'
|
type: 'community' | 'post'
|
||||||
@@ -82,7 +82,23 @@ export interface ResumableItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export let resumables = writable<ResumableItem[]>([])
|
function resumableStore(limit: number = 10) {
|
||||||
|
const { subscribe, set, update } = writable<ResumableItem[]>([])
|
||||||
|
|
||||||
|
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) {
|
export function addFavorite(item: Community, add: boolean = true) {
|
||||||
const pd = get(profileData)
|
const pd = get(profileData)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
||||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||||
import Subscribe from '../../communities/Subscribe.svelte'
|
import Subscribe from '../../communities/Subscribe.svelte'
|
||||||
|
import { resumables } from '$lib/lemmy/item'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -45,6 +46,13 @@
|
|||||||
'lastSeenCommunity',
|
'lastSeenCommunity',
|
||||||
data.community.community_view.community,
|
data.community.community_view.community,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
resumables.add({
|
||||||
|
name: community.community.title,
|
||||||
|
type: 'community',
|
||||||
|
url: $page.url.toString(),
|
||||||
|
avatar: community.community.icon,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
|
|||||||
@@ -64,17 +64,12 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$resumables.find((r) => r.url == $page.url.toString()))
|
resumables.add({
|
||||||
$resumables = [
|
name: post.post_view.post.name,
|
||||||
{
|
type: 'post',
|
||||||
id: Math.floor(Math.random() * 1000000),
|
url: $page.url.toString(),
|
||||||
name: post.post_view.post.name,
|
avatar: post.post_view.post.thumbnail_url,
|
||||||
type: 'post',
|
})
|
||||||
url: $page.url.toString(),
|
|
||||||
avatar: post.post_view.post.thumbnail_url,
|
|
||||||
},
|
|
||||||
...$resumables,
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
afterNavigate(async () => {
|
afterNavigate(async () => {
|
||||||
|
|||||||
Reference in new issue
Block a user