fix: PostFeed.svelte not updating
This commit is contained in:
5 files changed
+40
-85
No files matched your search
@@ -5,9 +5,6 @@
|
|||||||
import type { PostView } from 'lemmy-js-client'
|
import type { PostView } from 'lemmy-js-client'
|
||||||
import { Badge, Button } from 'mono-svelte'
|
import { Badge, Button } from 'mono-svelte'
|
||||||
import { ArchiveBox, Icon, Minus, Plus } from 'svelte-hero-icons'
|
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 {
|
interface Props {
|
||||||
posts: PostView[]
|
posts: PostView[]
|
||||||
@@ -24,11 +21,6 @@
|
|||||||
children,
|
children,
|
||||||
...rest
|
...rest
|
||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
let etc = rest
|
|
||||||
|
|
||||||
let combinedPosts = $derived(combineCrossposts(posts))
|
|
||||||
|
|
||||||
let viewPost: number = $state(-1)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ul
|
<ul
|
||||||
@@ -50,67 +42,21 @@
|
|||||||
</Placeholder>
|
</Placeholder>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
{#each combinedPosts as post, index}
|
{#each posts as post, index (post.post.id)}
|
||||||
{#if !(settings.hidePosts.deleted && post.post.deleted) && !(settings.hidePosts.removed && post.post.removed)}
|
<li class="relative post-container">
|
||||||
<li class="relative post-container">
|
<Post
|
||||||
<Post
|
hideCommunity={community}
|
||||||
hideCommunity={community}
|
view={(post.post.featured_community || post.post.featured_local) &&
|
||||||
view={(post.post.featured_community || post.post.featured_local) &&
|
settings.posts.compactFeatured
|
||||||
settings.posts.compactFeatured
|
? 'compact'
|
||||||
? 'compact'
|
: settings.view}
|
||||||
: settings.view}
|
{post}
|
||||||
{post}
|
class="transition-all duration-250"
|
||||||
class="transition-all duration-250"
|
onhide={() => {
|
||||||
onhide={() => {
|
posts = posts.toSpliced(index, 1)
|
||||||
posts = posts.toSpliced(index, 1)
|
}}
|
||||||
}}
|
/>
|
||||||
>
|
</li>
|
||||||
{#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}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
onchange?: (page: number) => void
|
onchange?: (page: number) => void
|
||||||
onchangecursor?: (cursor: string) => void
|
onchangecursor?: (cursor: string) => void
|
||||||
href?: (current: number | string) => string
|
href?: (current: number | string) => string
|
||||||
|
back?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -25,6 +26,7 @@
|
|||||||
onchange,
|
onchange,
|
||||||
onchangecursor,
|
onchangecursor,
|
||||||
href,
|
href,
|
||||||
|
back = true,
|
||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
|
|
||||||
let customHref = (href?: string) => {
|
let customHref = (href?: string) => {
|
||||||
@@ -53,21 +55,24 @@
|
|||||||
</span>
|
</span>
|
||||||
<hr class="border-slate-200 dark:border-zinc-800 flex-1" />
|
<hr class="border-slate-200 dark:border-zinc-800 flex-1" />
|
||||||
{/if}
|
{/if}
|
||||||
<Button
|
{#if back}
|
||||||
href={customHref(href?.(cursor?.back ?? page - 1))}
|
<Button
|
||||||
color="ghost"
|
href={customHref(href?.(cursor?.back ?? page - 1))}
|
||||||
onclick={() => invalidate(pageData.url)}
|
color="ghost"
|
||||||
title={$t('common.back')}
|
onclick={() => invalidate(pageData.url)}
|
||||||
size="square-md"
|
title={$t('common.back')}
|
||||||
rounding="pill"
|
size="square-md"
|
||||||
class="text-inherit dark:text-inherit disabled:!opacity-20 disabled:!bg-transparent"
|
rounding="pill"
|
||||||
disabled={!!((!cursor?.back && cursor?.next) || page <= 1)}
|
class="text-inherit dark:text-inherit disabled:!opacity-20 disabled:!bg-transparent"
|
||||||
data-sveltekit-preload-data="off"
|
disabled={(cursor?.back == undefined && cursor?.next != undefined) ||
|
||||||
>
|
page <= 0}
|
||||||
{#snippet suffix()}
|
data-sveltekit-preload-data="off"
|
||||||
<Icon src={ChevronLeft} size="24" mini />
|
>
|
||||||
{/snippet}
|
{#snippet suffix()}
|
||||||
</Button>
|
<Icon src={ChevronLeft} size="24" mini />
|
||||||
|
{/snippet}
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if page}
|
{#if page}
|
||||||
<div style="display: grid;">
|
<div style="display: grid;">
|
||||||
|
|||||||
@@ -152,6 +152,7 @@
|
|||||||
scale: false,
|
scale: false,
|
||||||
large: false,
|
large: false,
|
||||||
},
|
},
|
||||||
|
disabled,
|
||||||
loaderWidth = undefined,
|
loaderWidth = undefined,
|
||||||
href = undefined,
|
href = undefined,
|
||||||
class: clazz = '',
|
class: clazz = '',
|
||||||
@@ -167,12 +168,14 @@
|
|||||||
role={href ? 'link' : 'button'}
|
role={href ? 'link' : 'button'}
|
||||||
{href}
|
{href}
|
||||||
{...rest}
|
{...rest}
|
||||||
|
tabindex={disabled ? -1 : undefined}
|
||||||
class={[
|
class={[
|
||||||
loading ? buttonColor.secondary : buttonColor[color],
|
loading ? buttonColor.secondary : buttonColor[color],
|
||||||
buttonSize[size],
|
buttonSize[size],
|
||||||
buttonRounding[rounding][roundingSide],
|
buttonRounding[rounding][roundingSide],
|
||||||
buttonShadow[shadow],
|
buttonShadow[shadow],
|
||||||
'text-sm transition-all font-medium cursor-pointer duration-75 disabled:opacity-50 disabled:pointer-events-none',
|
'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'
|
alignment == 'center'
|
||||||
? 'origin-center'
|
? 'origin-center'
|
||||||
: alignment == 'left'
|
: alignment == 'left'
|
||||||
|
|||||||
@@ -76,6 +76,7 @@
|
|||||||
cursor={{ next: data.feed.value.cursor.next }}
|
cursor={{ next: data.feed.value.cursor.next }}
|
||||||
href={(page) =>
|
href={(page) =>
|
||||||
typeof page == 'number' ? `?page=${page}` : `?cursor=${page}`}
|
typeof page == 'number' ? `?page=${page}` : `?cursor=${page}`}
|
||||||
|
back={false}
|
||||||
>
|
>
|
||||||
<span class="flex flex-row items-center gap-1">
|
<span class="flex flex-row items-center gap-1">
|
||||||
<Icon src={ChartBar} size="16" mini />
|
<Icon src={ChartBar} size="16" mini />
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import { ReactiveState } from '$lib/promise.svelte.js'
|
|||||||
|
|
||||||
export async function load({ url, fetch }) {
|
export async function load({ url, fetch }) {
|
||||||
const cursor = url.searchParams.get('cursor') as string | undefined
|
const cursor = url.searchParams.get('cursor') as string | undefined
|
||||||
const prevCursor = url.searchParams.get('prevCursor') as string | undefined
|
const prevCursor = url.searchParams.get('cursorPrev') as string | undefined
|
||||||
|
|
||||||
const sort: SortType =
|
const sort: SortType =
|
||||||
(url.searchParams.get('sort') as SortType) || settings.defaultSort.sort
|
(url.searchParams.get('sort') as SortType) || settings.defaultSort.sort
|
||||||
|
|||||||
Reference in new issue
Block a user