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

-2
View File
@@ -172,8 +172,6 @@ $effect.root(() => {
}
})
$effect(() => {})
$effect(() => {
if (profile.data.id || profileData) fetchUserData(profile).then((res) => {})
})
@@ -5,10 +5,14 @@
import {
ChatBubbleOvalLeftEllipsis,
Check,
ExclamationTriangle,
Icon,
InformationCircle,
MapPin,
NoSymbol,
PencilSquare,
Plus,
Trash,
UserGroup,
} from 'svelte-hero-icons'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
@@ -78,7 +82,43 @@
class="flex flex-col overflow-hidden whitespace-nowrap flex-1 min-w-0 flex-shrink"
>
<div class="font-medium text-base overflow-hidden overflow-ellipsis">
{community.community.title}
<span>{community.community.title}</span>
{#if community.community.deleted}
<Icon
src={Trash}
class="text-red-500"
micro
size="14"
title={$t('post.badges.deleted')}
/>
{/if}
{#if community.community.nsfw}
<Icon
src={ExclamationTriangle}
class="text-red-500"
micro
size="14"
title={$t('post.badges.nsfw')}
/>
{/if}
{#if community.banned_from_community}
<Icon
src={NoSymbol}
class="text-red-500"
micro
size="14"
title={$t('comment.banned')}
/>
{/if}
{#if community.community.visibility == 'LocalOnly'}
<Icon
src={MapPin}
class="text-green-500"
micro
size="14"
title={$t('routes.admin.config.listingType.local')}
/>
{/if}
</div>
<div
class="text-sm text-slate-600 dark:text-zinc-400 flex gap-0.5"
@@ -47,11 +47,9 @@
Spinner,
toast,
} from 'mono-svelte'
import { fediseer, type Data } from '$lib/fediseer/fediseer'
import { t } from '$lib/translations'
import { hidePost, postLink } from './helpers'
import { feature } from '$lib/version'
import Switch from '$lib/components/input/Switch.svelte'
import { instanceId, instanceToURL } from '$lib/util.svelte'
import { publishedToDate } from '$lib/components/util/date'
import TextProps from '$lib/components/ui/text/TextProps.svelte'
@@ -0,0 +1,11 @@
<div class="skeleton animate-pulse flex flex-col gap-2 w-full">
<div
class="w-2/3 h-6 bg-slate-300 dark:bg-zinc-700 animate-pulse rounded-md"
></div>
<div
class="w-full h-20 bg-slate-300 dark:bg-zinc-700 animate-pulse rounded-md"
></div>
<div
class="w-32 h-6 bg-slate-300 dark:bg-zinc-700 animate-pulse rounded-md"
></div>
</div>
-105
View File
@@ -1,105 +0,0 @@
<script lang="ts">
import { Badge, Modal } from 'mono-svelte'
import type { Data } from './fediseer'
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import Expandable from '$lib/components/ui/Expandable.svelte'
interface Props {
open?: boolean
data: Data
}
let { open = $bindable(false), data }: Props = $props()
</script>
<Modal bind:open title="Fediseer">
<div
class="flex flex-col [&>*]:py-2 divide-y divide-slate-300 dark:divide-zinc-800"
>
<Expandable class="flex flex-col gap-4">
{#snippet title()}
<SectionTitle class="flex gap-2 items-center flex-row">
Endorsements <Badge class="w-max h-max" color="green-subtle">
{data.endorsements.instances.length}
</Badge>
</SectionTitle>
{/snippet}
<div class="flex flex-row gap-6 flex-wrap">
{#each data.endorsements.instances as instance}
<div class="flex flex-col">
<LabelStat
labelClass="!text-sm"
label={instance.domain}
formatted={false}
content={instance.endorsement_reasons?.[0] || '👍'}
></LabelStat>
</div>
{/each}
</div>
</Expandable>
<Expandable class="flex flex-col gap-4">
{#snippet title()}
<SectionTitle class="flex gap-2 items-center flex-row">
Guarantees <Badge class="w-max h-max" color="green-subtle">
{data.guarantees.instances.length}
</Badge>
</SectionTitle>
{/snippet}
<div class="flex flex-row gap-6 flex-wrap">
{#each data.guarantees.instances as instance}
<div class="flex flex-col">
<LabelStat
labelClass="!text-sm"
label={instance.domain}
formatted={false}
content={instance.guarantee_reasons?.[0] || '👍'}
></LabelStat>
</div>
{/each}
</div>
</Expandable>
<Expandable class="flex flex-col gap-4">
{#snippet title()}
<SectionTitle class="flex gap-2 items-center flex-row">
Censures <Badge class="w-max h-max" color="red-subtle">
{data.censures.instances.length}
</Badge>
</SectionTitle>
{/snippet}
<div class="flex flex-row gap-6 flex-wrap">
{#each data.censures.instances as instance}
<div class="flex flex-col">
<LabelStat
labelClass="!text-sm"
label={instance.domain}
formatted={false}
content={instance.censure_reasons?.[0] || '👎'}
></LabelStat>
</div>
{/each}
</div>
</Expandable>
<Expandable class="flex flex-col gap-4">
{#snippet title()}
<SectionTitle class="flex gap-2 items-center flex-row">
Hesitations <Badge class="w-max h-max" color="red-subtle">
{data.hesitations.instances.length}
</Badge>
</SectionTitle>
{/snippet}
<div class="flex flex-row gap-6 flex-wrap">
{#each data.hesitations.instances as instance}
<div class="flex flex-col">
<LabelStat
labelClass="!text-sm"
label={instance.domain}
formatted={false}
content={instance.hesitation_reasons?.[0] || '👎'}
></LabelStat>
</div>
{/each}
</div>
</Expandable>
</div>
</Modal>
-65
View File
@@ -1,65 +0,0 @@
export interface Endorsements {
instances: {
domain: string
endorsement_reasons: string[]
}[]
}
export interface Hesitations {
instances: {
domain: string
hesitation_reasons: string[]
}[]
}
export interface Censures {
instances: {
domain: string
censure_reasons: string[]
}[]
}
export interface Guarantees {
instances: {
domain: string
guarantee_reasons: string[]
}[]
}
export interface Data {
endorsements: Endorsements
hesitations: Hesitations
guarantees: Guarantees
censures: Censures
}
class Fediseer {
url: string
constructor(url: string) {
this.url = url
}
async getInstanceInfo(domain: string): Promise<Data> {
const [endorsements, hesitations, guarantees, censures] = await Promise.all(
[
fetch(`${this.url}/v1/endorsements/${domain}`).then((r) =>
r.json(),
) as Promise<Endorsements>,
fetch(`${this.url}/v1/hesitations/${domain}`).then((r) =>
r.json(),
) as Promise<Hesitations>,
fetch(`${this.url}/v1/guarantees/${domain}`).then((r) =>
r.json(),
) as Promise<Guarantees>,
fetch(`${this.url}/v1/censures/${domain}`).then((r) =>
r.json(),
) as Promise<Censures>,
],
)
return { endorsements, hesitations, guarantees, censures }
}
}
export const fediseer = new Fediseer('https://fediseer.com/api')
+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