fix: reactivity for badges
This commit is contained in:
4 files changed
+26
-22
No files matched your search
@@ -47,21 +47,26 @@
|
||||
view?: View
|
||||
style?: string
|
||||
class?: ClassValue
|
||||
badges?: import('svelte').Snippet
|
||||
extraBadges?: import('svelte').Snippet
|
||||
onhide?: (hide: boolean) => void
|
||||
}
|
||||
|
||||
let {
|
||||
post,
|
||||
post: passedPost = $bindable(),
|
||||
actions = true,
|
||||
hideCommunity = false,
|
||||
view = settings.view,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
badges,
|
||||
extraBadges,
|
||||
onhide,
|
||||
}: Props = $props()
|
||||
|
||||
let post = $state(passedPost)
|
||||
$effect(() => {
|
||||
passedPost = post
|
||||
})
|
||||
|
||||
let tags = $derived(parseTags(post.post.name))
|
||||
let type = $derived(mediaType(post.post.url, view))
|
||||
let rule = $derived(getTagRule(tags.tags))
|
||||
@@ -76,6 +81,17 @@
|
||||
post.post.embed_description == post.post.body &&
|
||||
view != 'compact',
|
||||
)
|
||||
|
||||
let badges = $derived({
|
||||
deleted: post.post.deleted,
|
||||
removed: post.post.removed,
|
||||
locked: post.post.locked,
|
||||
featured: post.post.featured_local || post.post.featured_community,
|
||||
nsfw: post.post.nsfw || post.community.nsfw,
|
||||
saved: post.saved,
|
||||
admin: post.creator_is_admin,
|
||||
moderator: post.creator_is_moderator,
|
||||
})
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -110,16 +126,7 @@
|
||||
showCommunity={!hideCommunity}
|
||||
user={post.creator}
|
||||
published={publishedToDate(post.post.published)}
|
||||
badges={{
|
||||
deleted: post.post.deleted,
|
||||
removed: post.post.removed,
|
||||
locked: post.post.locked,
|
||||
featured: post.post.featured_local || post.post.featured_community,
|
||||
nsfw: post.post.nsfw || post.community.nsfw,
|
||||
saved: post.saved,
|
||||
admin: post.creator_is_admin,
|
||||
moderator: post.creator_is_moderator,
|
||||
}}
|
||||
{badges}
|
||||
subscribed={profile.data?.user?.follows
|
||||
.map((c) => c.community.id)
|
||||
.includes(post.community.id)
|
||||
@@ -132,13 +139,10 @@
|
||||
edited={post.post.updated}
|
||||
tags={tags?.tags}
|
||||
{view}
|
||||
>
|
||||
{#snippet extraBadges()}
|
||||
{@render badges?.()}
|
||||
{/snippet}
|
||||
</PostMeta>
|
||||
{extraBadges}
|
||||
/>
|
||||
{#key post.post.url}
|
||||
<div style="grid-area:embed;" class={view == 'compact' ? '' : 'contents'}>
|
||||
<div style="grid-area:embed;" class={{ contents: view == 'cozy' }}>
|
||||
{#if rule != 'hide'}
|
||||
<PostMedia
|
||||
post={post.post}
|
||||
|
||||
@@ -133,7 +133,7 @@
|
||||
url={community?.icon}
|
||||
width={view == 'compact' ? 24 : 32}
|
||||
alt={community?.name}
|
||||
class="row-span-2 flex-shrink-0 mr-2"
|
||||
class="row-span-2 flex-shrink-0 mr-2 self-center"
|
||||
/>
|
||||
{/if}
|
||||
{#if showCommunity && community}
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
posts = posts.toSpliced(index, 1)
|
||||
}}
|
||||
>
|
||||
{#snippet badges()}
|
||||
{#snippet extraBadges()}
|
||||
{#if post.withCrossposts}
|
||||
<button
|
||||
onclick={() => {
|
||||
|
||||
@@ -234,13 +234,13 @@
|
||||
: ''} -mx-4 sm:-mx-6 px-4 sm:px-6"
|
||||
>
|
||||
<Post
|
||||
bind:post={posts[row.index]}
|
||||
hideCommunity={community}
|
||||
view={(posts[row.index]?.post.featured_community ||
|
||||
posts[row.index]?.post.featured_local) &&
|
||||
settings.posts.compactFeatured
|
||||
? 'compact'
|
||||
: settings.view}
|
||||
{post}
|
||||
class="transition-all duration-250"
|
||||
onhide={() => {
|
||||
posts = posts.toSpliced(row.index, 1)
|
||||
|
||||
Reference in new issue
Block a user