feat: add loading animation to search/community pages

This commit is contained in:
James Xylight committed 2025-02-09 15:06:02 -08:00
1 parent d8e916d526
commit 9e1db2ea83
9 files changed
+169 -253

No files matched your search

+86 -67
View File
@@ -31,6 +31,7 @@
import { fly } from 'svelte/transition'
import { backOut, expoOut } from 'svelte/easing'
import { goto } from '$app/navigation'
import Skeleton from '$lib/components/ui/generic/Skeleton.svelte'
let { data } = $props()
@@ -107,77 +108,95 @@
/>
</div>
</form>
<ul
class="flex flex-col divide-y divide-slate-100 dark:divide-zinc-800 my-6 h-full"
>
{#if communities.length == 0}
<Placeholder
icon={QuestionMarkCircle}
title={$t('routes.search.noResults.title')}
description={$t('routes.search.noResults.description')}
/>
{/if}
{#if navigating.to?.route.id == '/communities'}
<div class="flex flex-col gap-3 mt-6">
{#each new Array(5) as _, index}
<div
in:fly|global={{
duration: 800,
easing: expoOut,
y: 12,
delay: index * 100,
}}
style="width: {(1 / ((index + 1) % 3)) * 100}%"
>
<Skeleton />
</div>
{/each}
</div>
{:else}
<ul
class="flex flex-col divide-y divide-slate-100 dark:divide-zinc-800 my-6 h-full"
>
{#if communities.length == 0}
<Placeholder
icon={QuestionMarkCircle}
title={$t('routes.search.noResults.title')}
description={$t('routes.search.noResults.description')}
/>
{/if}
{#if showTop}
<SectionTitle class="!border-0 pb-2">
{$t('routes.search.top')}
</SectionTitle>
<div
class="grid md:grid-cols-2 lg:grid-cols-3 gap-4 items-center mb-6 !border-0"
>
{#each communities.slice(0, 3) as community, index (community.community.id)}
<div
class="h-full"
in:fly|global={{
duration: 1000,
easing: expoOut,
delay: index < 20 ? index * 100 : 0,
y: 16,
}}
>
<Material
color="distinct"
padding="none"
rounding="xl"
class="dark:border-t-zinc-800 h-full"
{#if showTop}
<SectionTitle class="!border-0 pb-2">
{$t('routes.search.top')}
</SectionTitle>
<div
class="grid md:grid-cols-2 lg:grid-cols-3 gap-4 items-center mb-6 !border-0"
>
{#each communities.slice(0, 3) as community, index (community.community.id)}
<div
class="h-full"
in:fly|global={{
duration: 1000,
easing: expoOut,
delay: index < 20 ? index * 100 : 0,
y: 16,
}}
>
<CommunityItem
{community}
showCounts={false}
class="w-full p-4 text-center"
view="cozy"
/>
</Material>
</div>
{/each}
</div>
{/if}
<Material
color="distinct"
padding="none"
rounding="xl"
class="dark:border-t-zinc-800 h-full"
>
<CommunityItem
{community}
showCounts={false}
class="w-full p-4 text-center"
view="cozy"
/>
</Material>
</div>
{/each}
</div>
{/if}
{#if communities.slice(showTop ? 3 : 0).length > 0}
<SectionTitle class="!border-0 pb-2">
{$t('routes.search.other')}
</SectionTitle>
{/if}
{#if communities}
{@const sliced = communities.slice(showTop ? 3 : 0)}
<div class="-mx-4 sm:-mx-6 h-full">
{#each sliced as community, index (community.community.id)}
<div
class="px-6 hover:bg-slate-50 hover:dark:bg-zinc-900 transition-colors @container
{#if communities.slice(showTop ? 3 : 0).length > 0}
<SectionTitle class="!border-0 pb-2">
{$t('routes.search.other')}
</SectionTitle>
{/if}
{#if communities}
{@const sliced = communities.slice(showTop ? 3 : 0)}
<div class="-mx-4 sm:-mx-6 h-full">
{#each sliced as community, index (community.community.id)}
<div
class="px-6 hover:bg-slate-50 hover:dark:bg-zinc-900 transition-colors @container
border-b border-slate-100 dark:border-zinc-900"
in:fly|global={{
duration: 1000,
easing: expoOut,
delay: index < 20 ? index * 35 : 0,
y: 16,
}}
>
<CommunityItem {community} showCounts={false} class="py-3" />
</div>
{/each}
</div>
{/if}
</ul>
in:fly|global={{
duration: 1000,
easing: expoOut,
delay: index < 20 ? index * 35 : 0,
y: 16,
}}
>
<CommunityItem {community} showCounts={false} class="py-3" />
</div>
{/each}
</div>
{/if}
</ul>
{/if}
{#if communities.length > 0}
<div
class="sticky z-30 mx-auto max-w-full"
+1
View File
@@ -31,6 +31,7 @@ export async function load({ url, fetch }) {
page: page,
sort: sort,
type_: type,
show_nsfw: true,
})
return {
+30 -11
View File
@@ -34,13 +34,14 @@
MagnifyingGlass,
} from 'svelte-hero-icons'
import { expoOut } from 'svelte/easing'
import { slide } from 'svelte/transition'
import { fly, slide } from 'svelte/transition'
import { t } from '$lib/translations.js'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
import { contentPadding } from '$lib/components/ui/layout/Shell.svelte'
import { goto } from '$app/navigation'
import Option from 'mono-svelte/forms/select/Option.svelte'
import Skeleton from '$lib/components/ui/generic/Skeleton.svelte'
type Result = PostView | CommentView | PersonView | CommunityView
@@ -90,7 +91,7 @@
class="flex-shrink-0 h-full aspect-square"
title="Search"
rounding="pill"
loading={navigating.to != null}
loading={navigating.to?.route.id == '/search'}
>
{#snippet prefix()}
<Icon src={MagnifyingGlass} size="16" micro />
@@ -145,15 +146,33 @@
</div>
{/if}
{#if !data.results}
<div class="my-auto">
<Placeholder
icon={MagnifyingGlass}
title={$t('routes.search.noResults.title')}
description={query == ''
? $t('routes.search.noResults.alt')
: $t('routes.search.noResults.description')}
/>
</div>
{#if navigating.to?.route.id == '/search'}
<div class="flex flex-col gap-3 mt-6">
{#each new Array(5) as _, index}
<div
in:fly|global={{
duration: 800,
easing: expoOut,
y: 12,
delay: index * 100,
}}
style="width: {(1 / ((index + 1) % 3)) * 100}%"
>
<Skeleton />
</div>
{/each}
</div>
{:else}
<div class="my-auto">
<Placeholder
icon={MagnifyingGlass}
title={$t('routes.search.noResults.title')}
description={query == ''
? $t('routes.search.noResults.alt')
: $t('routes.search.noResults.description')}
/>
</div>
{/if}
{:else}
{#await data.streamed.object}
<div