migrate: fix reactivity issues in data lists

This commit is contained in:
James Xylight committed 2025-02-02 17:41:46 -08:00
1 parent 104a99f394
commit 87fba8af04
4 files changed
+22 -13

No files matched your search

@@ -53,11 +53,7 @@
let { url, type = 'embed', target, ...rest }: Props = $props() let { url, type = 'embed', target, ...rest }: Props = $props()
</script> </script>
<Menu {...rest}> <Menu {target} {...rest}>
{#snippet target()}
{@render target?.()}
{/snippet}
<MenuDivider>{$t('post.actions.link.title')}</MenuDivider> <MenuDivider>{$t('post.actions.link.title')}</MenuDivider>
{#each sources as source} {#each sources as source}
{#if source.type == type} {#if source.type == type}
+11 -6
View File
@@ -34,6 +34,11 @@
let { data } = $props() let { data } = $props()
let communities = $state(data.communities)
$effect(() => {
communities = data.communities
})
let search = $state(data.query || '') let search = $state(data.query || '')
let searchElement: HTMLInputElement | undefined = $state() let searchElement: HTMLInputElement | undefined = $state()
let instance = '' let instance = ''
@@ -99,7 +104,7 @@
<ul <ul
class="flex flex-col divide-y divide-slate-100 dark:divide-zinc-800 my-6 h-full" class="flex flex-col divide-y divide-slate-100 dark:divide-zinc-800 my-6 h-full"
> >
{#if data.communities.length == 0} {#if communities.length == 0}
<Placeholder <Placeholder
icon={QuestionMarkCircle} icon={QuestionMarkCircle}
title={$t('routes.search.noResults.title')} title={$t('routes.search.noResults.title')}
@@ -114,7 +119,7 @@
<div <div
class="grid md:grid-cols-2 lg:grid-cols-3 gap-4 items-center mb-6 !border-0" class="grid md:grid-cols-2 lg:grid-cols-3 gap-4 items-center mb-6 !border-0"
> >
{#each data.communities.slice(0, 3) as community, index (community.community.id)} {#each communities.slice(0, 3) as community, index (community.community.id)}
<div <div
class="h-full" class="h-full"
in:fly|global={{ in:fly|global={{
@@ -142,13 +147,13 @@
</div> </div>
{/if} {/if}
{#if data.communities.slice(showTop ? 3 : 0).length > 0} {#if communities.slice(showTop ? 3 : 0).length > 0}
<SectionTitle class="!border-0 pb-2"> <SectionTitle class="!border-0 pb-2">
{$t('routes.search.other')} {$t('routes.search.other')}
</SectionTitle> </SectionTitle>
{/if} {/if}
{#if data.communities} {#if communities}
{@const sliced = data.communities.slice(showTop ? 3 : 0)} {@const sliced = communities.slice(showTop ? 3 : 0)}
<div class="-mx-4 sm:-mx-6 h-full"> <div class="-mx-4 sm:-mx-6 h-full">
{#each sliced as community, index (community.community.id)} {#each sliced as community, index (community.community.id)}
<div <div
@@ -167,7 +172,7 @@
</div> </div>
{/if} {/if}
</ul> </ul>
{#if data.communities.length > 0} {#if communities.length > 0}
<div <div
class="sticky z-30 mx-auto max-w-full" class="sticky z-30 mx-auto max-w-full"
style="bottom: max(1.5rem, {$contentPadding.bottom}px);" style="bottom: max(1.5rem, {$contentPadding.bottom}px);"
+4 -1
View File
@@ -28,6 +28,9 @@
let { data } = $props() let { data } = $props()
let inbox = $state(data.data) let inbox = $state(data.data)
$effect(() => {
inbox = data.data
})
let markingAsRead = $state(false) let markingAsRead = $state(false)
@@ -196,7 +199,7 @@ items-center px-2 w-max"
> >
<Tabs routes={[]} class="mx-auto"> <Tabs routes={[]} class="mx-auto">
<Pageination <Pageination
hasMore={!(!data.data || (inbox?.length ?? 0) < data.limit)} hasMore={!(!inbox || (inbox?.length ?? 0) < (data?.limit ?? 0))}
page={data.page} page={data.page}
on:change={(p) => searchParam($page.url, 'page', p.detail.toString())} on:change={(p) => searchParam($page.url, 'page', p.detail.toString())}
/> />
+6 -1
View File
@@ -20,6 +20,9 @@
let { data = $bindable() } = $props() let { data = $bindable() } = $props()
let reports = $state(data.items) let reports = $state(data.items)
$effect(() => {
reports = data.items
})
</script> </script>
<div class="mb-4 flex flex-col gap-4"> <div class="mb-4 flex flex-col gap-4">
@@ -49,7 +52,9 @@
</Header> </Header>
</div> </div>
{#if reports && reports.length > 0} {#if reports && reports.length > 0}
<div class="flex flex-col gap-4"> <div
class="flex flex-col *:py-4 divide-y divide-slate-200 dark:divide-zinc-800"
>
{#each reports as item} {#each reports as item}
<div <div
in:fly={{ y: -6, opacity: 0, duration: 500 }} in:fly={{ y: -6, opacity: 0, duration: 500 }}