fix: PostFeed.svelte not updating

This commit is contained in:
James Xylight committed 2025-03-14 14:15:03 -07:00
1 parent ced6d62934
commit 5acab260a8
5 files changed
+40 -85

No files matched your search

@@ -5,9 +5,6 @@
import type { PostView } from 'lemmy-js-client'
import { Badge, Button } from 'mono-svelte'
import { ArchiveBox, Icon, Minus, Plus } from 'svelte-hero-icons'
import { expoOut } from 'svelte/easing'
import { fly, slide } from 'svelte/transition'
import { combineCrossposts } from './crosspost.svelte'
interface Props {
posts: PostView[]
@@ -24,11 +21,6 @@
children,
...rest
}: Props = $props()
let etc = rest
let combinedPosts = $derived(combineCrossposts(posts))
let viewPost: number = $state(-1)
</script>
<ul
@@ -50,67 +42,21 @@
</Placeholder>
</div>
{:else}
{#each combinedPosts as post, index}
{#if !(settings.hidePosts.deleted && post.post.deleted) && !(settings.hidePosts.removed && post.post.removed)}
<li class="relative post-container">
<Post
hideCommunity={community}
view={(post.post.featured_community || post.post.featured_local) &&
settings.posts.compactFeatured
? 'compact'
: settings.view}
{post}
class="transition-all duration-250"
onhide={() => {
posts = posts.toSpliced(index, 1)
}}
>
{#snippet extraBadges()}
{#if post.withCrossposts}
<button
onclick={() => {
if (viewPost == post.post.id) viewPost = -1
else viewPost = post.post.id
}}
>
<Badge
class="z-10 backdrop-blur-xl hover:brightness-110 cursor-pointer transition-all"
color="gray-subtle"
>
{#if viewPost == post.post.id}
<Icon mini src={Minus} size="14" />
{:else}
<Icon mini src={Plus} size="14" />
{/if}
{post.crossposts.length} crosspost{post.crossposts.length ==
1
? ''
: 's'}
</Badge>
</button>{/if}
{/snippet}
</Post>
{#if post.withCrossposts && viewPost == post.post.id}
<div
transition:slide|global={{
axis: 'y',
duration: 500,
easing: expoOut,
}}
>
<span class="text-sm flex flex-row gap-2 items-center">
Crossposts <hr class="w-full dark:border-zinc-800" />
{post.crossposts.length}
</span>
{#each post.crossposts as crosspost, index}
<div class="w-full transition-all mb-4">
<Post post={crosspost} view={settings.view} />
</div>
{/each}
</div>
{/if}
</li>
{/if}
{#each posts as post, index (post.post.id)}
<li class="relative post-container">
<Post
hideCommunity={community}
view={(post.post.featured_community || post.post.featured_local) &&
settings.posts.compactFeatured
? 'compact'
: settings.view}
{post}
class="transition-all duration-250"
onhide={() => {
posts = posts.toSpliced(index, 1)
}}
/>
</li>
{/each}
{/if}
{@render children?.()}
+20 -15
View File
@@ -15,6 +15,7 @@
onchange?: (page: number) => void
onchangecursor?: (cursor: string) => void
href?: (current: number | string) => string
back?: boolean
}
let {
@@ -25,6 +26,7 @@
onchange,
onchangecursor,
href,
back = true,
}: Props = $props()
let customHref = (href?: string) => {
@@ -53,21 +55,24 @@
</span>
<hr class="border-slate-200 dark:border-zinc-800 flex-1" />
{/if}
<Button
href={customHref(href?.(cursor?.back ?? page - 1))}
color="ghost"
onclick={() => invalidate(pageData.url)}
title={$t('common.back')}
size="square-md"
rounding="pill"
class="text-inherit dark:text-inherit disabled:!opacity-20 disabled:!bg-transparent"
disabled={!!((!cursor?.back && cursor?.next) || page <= 1)}
data-sveltekit-preload-data="off"
>
{#snippet suffix()}
<Icon src={ChevronLeft} size="24" mini />
{/snippet}
</Button>
{#if back}
<Button
href={customHref(href?.(cursor?.back ?? page - 1))}
color="ghost"
onclick={() => invalidate(pageData.url)}
title={$t('common.back')}
size="square-md"
rounding="pill"
class="text-inherit dark:text-inherit disabled:!opacity-20 disabled:!bg-transparent"
disabled={(cursor?.back == undefined && cursor?.next != undefined) ||
page <= 0}
data-sveltekit-preload-data="off"
>
{#snippet suffix()}
<Icon src={ChevronLeft} size="24" mini />
{/snippet}
</Button>
{/if}
{#if page}
<div style="display: grid;">
+3
View File
@@ -152,6 +152,7 @@
scale: false,
large: false,
},
disabled,
loaderWidth = undefined,
href = undefined,
class: clazz = '',
@@ -167,12 +168,14 @@
role={href ? 'link' : 'button'}
{href}
{...rest}
tabindex={disabled ? -1 : undefined}
class={[
loading ? buttonColor.secondary : buttonColor[color],
buttonSize[size],
buttonRounding[rounding][roundingSide],
buttonShadow[shadow],
'text-sm transition-all font-medium cursor-pointer duration-75 disabled:opacity-50 disabled:pointer-events-none',
disabled && 'pointer-events-none opacity-50',
alignment == 'center'
? 'origin-center'
: alignment == 'left'