2026-02-03 19:00:13 +00:00
|
|
|
<script lang="ts">
|
2026-08-29 16:19:01 +00:00
|
|
|
import {onDestroy, onMount} from "svelte"
|
2026-02-03 19:00:13 +00:00
|
|
|
import {readable} from "svelte/store"
|
|
|
|
|
import type {Readable} from "svelte/store"
|
|
|
|
|
import {page} from "$app/stores"
|
|
|
|
|
import {sortBy, partition, spec, max, pushToMapKey} from "@welshman/lib"
|
2026-08-30 00:42:07 +00:00
|
|
|
import type {Maybe} from "@welshman/lib"
|
2026-02-03 19:00:13 +00:00
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {CLASSIFIED, tagSpec, tagValue} from "@welshman/util"
|
2026-02-03 19:00:13 +00:00
|
|
|
import {fly} from "@lib/transition"
|
2026-03-12 23:41:07 +00:00
|
|
|
import CaseMinimalistic from "@assets/icons/case-minimalistic.svg?dataurl"
|
|
|
|
|
import Add from "@assets/icons/add.svg?dataurl"
|
2026-02-03 19:00:13 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import PageContent from "@lib/components/PageContent.svelte"
|
|
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
2026-03-12 23:41:07 +00:00
|
|
|
import SpaceBar from "@app/components/SpaceBar.svelte"
|
2026-02-03 19:00:13 +00:00
|
|
|
import ClassifiedItem from "@app/components/ClassifiedItem.svelte"
|
|
|
|
|
import ClassifiedCreate from "@app/components/ClassifiedCreate.svelte"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {decodeRelay} from "@app/relays"
|
|
|
|
|
import {makeCommentFilter} from "@app/content"
|
2026-08-30 00:42:07 +00:00
|
|
|
import {isFeedLoading, makeFeed, makeFeedContext, makeScrollLoader} from "@app/feeds"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushModal} from "@app/modal"
|
2026-02-03 19:00:13 +00:00
|
|
|
|
|
|
|
|
const url = decodeRelay($page.params.relay!)
|
2026-08-29 16:19:01 +00:00
|
|
|
const context = makeFeedContext({relays: [url]})
|
|
|
|
|
|
|
|
|
|
onDestroy(context.cleanup)
|
2026-02-03 19:00:13 +00:00
|
|
|
|
2026-08-30 00:42:07 +00:00
|
|
|
let older: Maybe<ReturnType<typeof makeScrollLoader>> = $state()
|
|
|
|
|
|
|
|
|
|
const loading = $derived(isFeedLoading($older))
|
|
|
|
|
const exhausted = $derived($older?.status === "exhausted")
|
2026-02-03 19:00:13 +00:00
|
|
|
let element: HTMLElement | undefined = $state()
|
|
|
|
|
let events: Readable<TrustedEvent[]> = $state(readable([]))
|
|
|
|
|
|
|
|
|
|
const createClassified = () => pushModal(ClassifiedCreate, {url})
|
|
|
|
|
|
|
|
|
|
const items = $derived.by(() => {
|
|
|
|
|
const scores = new Map<string, number[]>()
|
|
|
|
|
const [goals, comments] = partition(spec({kind: CLASSIFIED}), $events)
|
|
|
|
|
|
|
|
|
|
for (const comment of comments) {
|
2026-07-28 16:16:26 +00:00
|
|
|
const id = tagValue(tagSpec("E"), comment.tags)
|
2026-02-03 19:00:13 +00:00
|
|
|
|
|
|
|
|
if (id) {
|
|
|
|
|
pushToMapKey(scores, id, comment.created_at)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sortBy(e => -max([...(scores.get(e.id) || []), e.created_at]), goals)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
const feed = makeFeed({
|
2026-06-29 23:28:11 +00:00
|
|
|
relays: [url],
|
2026-08-29 16:19:01 +00:00
|
|
|
onEvent: context.add,
|
2026-02-03 19:00:13 +00:00
|
|
|
filters: [{kinds: [CLASSIFIED]}, makeCommentFilter([CLASSIFIED])],
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
events = feed.events
|
|
|
|
|
|
2026-08-30 00:42:07 +00:00
|
|
|
// These lists are sorted newest first, so reaching the bottom is reaching the oldest thing
|
|
|
|
|
// loaded.
|
|
|
|
|
older = makeScrollLoader(element!, feed.loadOlder)
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
older?.stop()
|
|
|
|
|
feed.cleanup()
|
|
|
|
|
}
|
2026-02-03 19:00:13 +00:00
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
2026-03-12 23:41:07 +00:00
|
|
|
<SpaceBar>
|
2026-05-25 19:18:51 +00:00
|
|
|
{#snippet leading()}
|
2026-03-12 23:41:07 +00:00
|
|
|
<Icon icon={CaseMinimalistic} />
|
2026-05-25 19:18:51 +00:00
|
|
|
{/snippet}
|
|
|
|
|
{#snippet title()}
|
2026-03-12 23:41:07 +00:00
|
|
|
<strong>Classifieds</strong>
|
2026-02-03 19:00:13 +00:00
|
|
|
{/snippet}
|
|
|
|
|
{#snippet action()}
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-primary button-sm" onclick={createClassified}>
|
2026-03-12 23:41:07 +00:00
|
|
|
<Icon icon={Add} />
|
|
|
|
|
Create
|
|
|
|
|
</Button>
|
2026-02-03 19:00:13 +00:00
|
|
|
{/snippet}
|
2026-03-12 23:41:07 +00:00
|
|
|
</SpaceBar>
|
2026-02-03 19:00:13 +00:00
|
|
|
|
2026-06-22 20:36:57 +00:00
|
|
|
<PageContent bind:element class="flex flex-col gap-2 p-2 sm:gap-4 sm:p-4">
|
2026-02-03 19:00:13 +00:00
|
|
|
{#each items as event (event.id)}
|
|
|
|
|
<div in:fly>
|
2026-08-29 16:19:01 +00:00
|
|
|
<ClassifiedItem {url} {context} event={$state.snapshot(event)} />
|
2026-02-03 19:00:13 +00:00
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
<p class="flex h-10 items-center justify-center py-20">
|
|
|
|
|
<Spinner {loading}>
|
|
|
|
|
{#if loading}
|
2026-02-03 21:21:21 +00:00
|
|
|
Looking for listings...
|
2026-08-30 00:42:07 +00:00
|
|
|
{:else if exhausted && items.length === 0}
|
2026-02-03 19:00:13 +00:00
|
|
|
No classified listings found.
|
2026-08-30 00:42:07 +00:00
|
|
|
{:else if exhausted}
|
2026-02-03 19:00:13 +00:00
|
|
|
That's all!
|
|
|
|
|
{/if}
|
|
|
|
|
</Spinner>
|
|
|
|
|
</p>
|
|
|
|
|
</PageContent>
|