feat [3/3]: add topic viewing
This commit is contained in:
1 parent
82a8747ad4
commit
a82d8c296d
14 files changed
+422
-319
No files matched your search
@@ -67,7 +67,7 @@
|
||||
/>
|
||||
{/each}
|
||||
<img
|
||||
src={bestImageURL(post, false, -1, null)}
|
||||
src={blur ? '' : bestImageURL(post, false, -1, null)}
|
||||
loading="lazy"
|
||||
class={[
|
||||
'max-w-full rounded-xl z-30 transition-all max-h-[60vh] duration-500 object-contain mx-auto group-hover:scale-98 group-active:scale-95',
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
/>
|
||||
{/each}
|
||||
<img
|
||||
src={bestImageURL(post, thumbnail, -1, null)}
|
||||
src={blur ? '' : bestImageURL(post, thumbnail, -1, null)}
|
||||
loading="lazy"
|
||||
class={[
|
||||
'object-cover relative overflow-hidden rounded-xl h-full',
|
||||
|
||||
@@ -4,3 +4,4 @@ export { default as CommonList } from './CommonList.svelte'
|
||||
export { default as SearchBar } from './SearchBar.svelte'
|
||||
export { default as Shell } from './Shell.svelte'
|
||||
export { default as Pageination } from './Pageination.svelte'
|
||||
export { default as PostListShell } from './pages/PostListShell.svelte'
|
||||
@@ -0,0 +1,113 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment'
|
||||
import { page } from '$app/state'
|
||||
import type { GetPosts, ListingType, PostView } from '$lib/client/types'
|
||||
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
|
||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||
import ViewSelect from '$lib/components/lemmy/dropdowns/ViewSelect.svelte'
|
||||
import { PostFeed, VirtualFeed } from '$lib/components/lemmy/post'
|
||||
import { Header } from '$lib/components/ui/layout'
|
||||
import Pageination from '$lib/components/ui/layout/Pageination.svelte'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import type { SortType } from 'lemmy-js-client'
|
||||
import Button from 'mono-svelte/button/Button.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { ArrowRight, Icon } from 'svelte-hero-icons'
|
||||
|
||||
interface Props {
|
||||
posts: PostView[]
|
||||
cursor?: string
|
||||
params: {
|
||||
location?: ListingType
|
||||
sort?: SortType
|
||||
}
|
||||
title?: string
|
||||
extended?: Snippet
|
||||
getParams: GetPosts
|
||||
client: {
|
||||
lastSeen?: number
|
||||
itemHeights?: (number | null)[]
|
||||
}
|
||||
header?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
params,
|
||||
posts = $bindable(),
|
||||
cursor = $bindable(),
|
||||
title,
|
||||
extended: passedExtended,
|
||||
getParams,
|
||||
client = $bindable(),
|
||||
header = true,
|
||||
}: Props = $props()
|
||||
|
||||
$effect(() => {
|
||||
if (params.sort) settings.defaultSort.sort = params.sort
|
||||
})
|
||||
|
||||
const FeedComponent = $derived(
|
||||
settings.infiniteScroll && browser && !settings.posts.noVirtualize
|
||||
? VirtualFeed
|
||||
: PostFeed,
|
||||
)
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-2 max-w-full w-full min-w-0">
|
||||
{#if header}
|
||||
<Header pageHeader>
|
||||
{#if title}
|
||||
{title}
|
||||
{/if}
|
||||
{#snippet extended()}
|
||||
{@render passedExtended?.()}
|
||||
<form class="" method="get" action={page.url.pathname}>
|
||||
<div class="flex flex-row gap-2">
|
||||
{#if params.location}
|
||||
<Location name="type" navigate bind:selected={params.location} />
|
||||
{/if}
|
||||
{#if params.sort}
|
||||
<Sort
|
||||
placement="bottom"
|
||||
name="sort"
|
||||
navigate
|
||||
bind:selected={params.sort}
|
||||
/>
|
||||
{/if}
|
||||
<ViewSelect placement="bottom" />
|
||||
|
||||
<noscript>
|
||||
<Button
|
||||
class="self-end h-[34px] aspect-square"
|
||||
size="custom"
|
||||
submit
|
||||
>
|
||||
<Icon src={ArrowRight} size="16" micro />
|
||||
</Button>
|
||||
</noscript>
|
||||
</div>
|
||||
</form>
|
||||
{/snippet}
|
||||
</Header>
|
||||
{/if}
|
||||
|
||||
<FeedComponent
|
||||
bind:posts
|
||||
bind:lastSeen={() => client.lastSeen ?? 0, (v) => (client.lastSeen = v)}
|
||||
bind:params={getParams}
|
||||
virtualList={{ itemHeights: client?.itemHeights ?? [] }}
|
||||
/>
|
||||
<svelte:element
|
||||
this={settings.infiniteScroll && !settings.posts.noVirtualize
|
||||
? 'noscript'
|
||||
: 'div'}
|
||||
class="mt-auto flex flex-col"
|
||||
>
|
||||
<Pageination
|
||||
cursor={{ next: cursor }}
|
||||
href={(page) =>
|
||||
typeof page == 'number' ? `?page=${page}` : `?cursor=${page}`}
|
||||
back={false}
|
||||
/>
|
||||
</svelte:element>
|
||||
</div>
|
||||
@@ -91,9 +91,10 @@
|
||||
/>
|
||||
{/if}
|
||||
<NavButton
|
||||
href="/communities"
|
||||
label={$t('nav.communities')}
|
||||
href="/explore/communities"
|
||||
label={$t('routes.explore.title')}
|
||||
icon={GlobeAlt}
|
||||
isSelectedFilter={(path) => path.startsWith('/explore')}
|
||||
/>
|
||||
<NavButton href="/search" label={$t('nav.search')} icon={MagnifyingGlass} />
|
||||
<NavButton
|
||||
|
||||
@@ -11,6 +11,7 @@ import type {
|
||||
GetPost,
|
||||
GetPosts,
|
||||
PostView,
|
||||
TopicView,
|
||||
} from '$lib/client/types'
|
||||
import { recursiveEqual } from '$lib/util.svelte'
|
||||
import { SvelteMap } from 'svelte/reactivity'
|
||||
@@ -109,6 +110,19 @@ export interface FeedTypes {
|
||||
}
|
||||
},
|
||||
]
|
||||
'/topic/[id]': [
|
||||
GetPosts,
|
||||
{
|
||||
posts: PostView[]
|
||||
next_page?: string
|
||||
params: GetPosts
|
||||
topic: Promise<TopicView | undefined>
|
||||
client: {
|
||||
itemHeights?: (number | null)[]
|
||||
lastSeen?: number
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
const feeds = new SvelteMap<keyof FeedTypes, Feed<any, any>>()
|
||||
|
||||
+57
-80
@@ -1,28 +1,20 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment'
|
||||
import { page } from '$app/state'
|
||||
import { site } from '$lib/client/lemmy.svelte'
|
||||
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
|
||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||
import ViewSelect from '$lib/components/lemmy/dropdowns/ViewSelect.svelte'
|
||||
import { PostFeed, VirtualFeed } from '$lib/components/lemmy/post'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
import Skeleton from '$lib/components/ui/generic/Skeleton.svelte'
|
||||
import { Header } from '$lib/components/ui/layout'
|
||||
import Pageination from '$lib/components/ui/layout/Pageination.svelte'
|
||||
import { Header, Pageination } from '$lib/components/ui/layout'
|
||||
import { t } from '$lib/i18n/translations.js'
|
||||
import { settings, SSR_ENABLED } from '$lib/settings.svelte.js'
|
||||
import Button from 'mono-svelte/button/Button.svelte'
|
||||
import { ArrowRight, ChartBar, Icon } from 'svelte-hero-icons'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { ArrowRight, Icon } from 'svelte-hero-icons'
|
||||
|
||||
let { data = $bindable() } = $props()
|
||||
|
||||
$effect(() => {
|
||||
if (data.filters.value.type_)
|
||||
settings.defaultSort.feed = data.filters.value.type_
|
||||
if (data.filters.value.sort)
|
||||
settings.defaultSort.sort = data.filters.value.sort
|
||||
})
|
||||
|
||||
const FeedComponent = $derived(
|
||||
settings.infiniteScroll && browser && !settings.posts.noVirtualize
|
||||
? VirtualFeed
|
||||
@@ -38,43 +30,36 @@
|
||||
</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="flex flex-col gap-2 max-w-full w-full min-w-0">
|
||||
<Header pageHeader>
|
||||
{$t('routes.frontpage.title')}
|
||||
<Header pageHeader>
|
||||
{$t('routes.frontpage.title')}
|
||||
{#snippet extended()}
|
||||
<form class="" method="get" action={page.url.pathname}>
|
||||
<div class="flex flex-row gap-2">
|
||||
<Location
|
||||
name="type"
|
||||
navigate
|
||||
bind:selected={data.filters.value.type_!}
|
||||
/>
|
||||
<Sort
|
||||
placement="bottom"
|
||||
name="sort"
|
||||
navigate
|
||||
bind:selected={data.filters.value.sort!}
|
||||
/>
|
||||
<ViewSelect placement="bottom" />
|
||||
|
||||
{#snippet extended()}
|
||||
<form class="" method="get" action="/">
|
||||
<div class="flex flex-row gap-2">
|
||||
{#if data.filters.value.type_}
|
||||
<Location
|
||||
name="type"
|
||||
navigate
|
||||
bind:selected={data.filters.value.type_}
|
||||
/>
|
||||
{/if}
|
||||
<Sort
|
||||
placement="bottom"
|
||||
name="sort"
|
||||
navigate
|
||||
bind:selected={data.filters.value.sort}
|
||||
/>
|
||||
<ViewSelect placement="bottom" />
|
||||
<noscript>
|
||||
<Button class="self-end h-[34px] aspect-square" size="custom" submit>
|
||||
<Icon src={ArrowRight} size="16" micro />
|
||||
</Button>
|
||||
</noscript>
|
||||
</div>
|
||||
</form>
|
||||
{/snippet}
|
||||
</Header>
|
||||
|
||||
<noscript>
|
||||
<Button
|
||||
class="self-end h-[34px] aspect-square"
|
||||
size="custom"
|
||||
submit
|
||||
>
|
||||
<Icon src={ArrowRight} size="16" micro />
|
||||
</Button>
|
||||
</noscript>
|
||||
</div>
|
||||
</form>
|
||||
{/snippet}
|
||||
</Header>
|
||||
|
||||
{#await data.feed.value}
|
||||
{#await data.feed.value}
|
||||
<div class="space-y-4">
|
||||
{#each new Array(5) as _, index}{_}
|
||||
<div
|
||||
class="animate-pop-in"
|
||||
@@ -83,37 +68,29 @@
|
||||
100}%"
|
||||
>
|
||||
<Skeleton />
|
||||
</div>{/each}
|
||||
{:then feed}
|
||||
<FeedComponent
|
||||
bind:posts={feed.posts}
|
||||
bind:lastSeen={
|
||||
() => feed.client.lastSeen ?? 0, (v) => (feed.client.lastSeen = v)
|
||||
}
|
||||
bind:params={feed.params}
|
||||
virtualList={{ itemHeights: feed.client?.itemHeights ?? [] }}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:then feed}
|
||||
<FeedComponent
|
||||
bind:posts={feed.posts}
|
||||
bind:lastSeen={
|
||||
() => feed.client.lastSeen ?? 0, (v) => (feed.client.lastSeen = v)
|
||||
}
|
||||
bind:params={feed.params}
|
||||
virtualList={{ itemHeights: feed.client?.itemHeights ?? [] }}
|
||||
/>
|
||||
<svelte:element
|
||||
this={settings.infiniteScroll && !settings.posts.noVirtualize
|
||||
? 'noscript'
|
||||
: 'div'}
|
||||
class="mt-auto flex flex-col"
|
||||
>
|
||||
<Pageination
|
||||
cursor={{ next: feed.next_page }}
|
||||
href={(page) =>
|
||||
typeof page == 'number' ? `?page=${page}` : `?cursor=${page}`}
|
||||
back={false}
|
||||
/>
|
||||
<svelte:element
|
||||
this={settings.infiniteScroll && !settings.posts.noVirtualize
|
||||
? 'noscript'
|
||||
: 'div'}
|
||||
class="mt-auto flex flex-col"
|
||||
>
|
||||
<EndPlaceholder>
|
||||
<Icon src={ChartBar} size="16" mini />
|
||||
|
||||
{$t('routes.frontpage.footer', {
|
||||
users: site.data?.site_view?.counts?.users_active_day ?? '??',
|
||||
})}
|
||||
{#snippet action()}
|
||||
<Pageination
|
||||
cursor={{ next: feed.next_page }}
|
||||
href={(page) =>
|
||||
typeof page == 'number' ? `?page=${page}` : `?cursor=${page}`}
|
||||
back={false}
|
||||
/>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</svelte:element>
|
||||
{/await}
|
||||
</div>
|
||||
</svelte:element>
|
||||
{/await}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { env } from '$env/dynamic/public'
|
||||
import { client } from '$lib/client/lemmy.svelte.js'
|
||||
import type { ListingType, SortType } from '$lib/client/types'
|
||||
import { t } from '$lib/i18n/translations.js'
|
||||
@@ -27,8 +26,6 @@ export async function load({ url, fetch, route }) {
|
||||
show_hidden: settings.posts.showHidden,
|
||||
})
|
||||
|
||||
if (env.PUBLIC_SSR_ENABLED?.toLowerCase() == 'true') await feedData
|
||||
|
||||
return {
|
||||
feed: new ReactiveState((await awaitIfServer(feedData)).data),
|
||||
filters: new ReactiveState({
|
||||
|
||||
@@ -3,26 +3,17 @@
|
||||
import { navigating, page } from '$app/state'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { site } from '$lib/client/lemmy.svelte'
|
||||
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
|
||||
import CommunityHeader from '$lib/components/lemmy/community/CommunityHeader.svelte'
|
||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||
import ViewSelect from '$lib/components/lemmy/dropdowns/ViewSelect.svelte'
|
||||
import { PostFeed, VirtualFeed } from '$lib/components/lemmy/post'
|
||||
import { Header } from '$lib/components/ui/layout'
|
||||
import Pageination from '$lib/components/ui/layout/Pageination.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { PostListShell } from '$lib/components/ui/layout'
|
||||
import { t } from '$lib/i18n/translations.js'
|
||||
import { resumables } from '$lib/lemmy/item'
|
||||
import { setSessionStorage } from '$lib/session.js'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { Badge, Button, Modal, Note } from 'mono-svelte'
|
||||
import { Badge, Button, Note } from 'mono-svelte'
|
||||
import { onDestroy, onMount } from 'svelte'
|
||||
import { ArrowRight, ChartBar, Icon, Plus, XMark } from 'svelte-hero-icons'
|
||||
import { ArrowRight, Icon, Plus } from 'svelte-hero-icons'
|
||||
|
||||
let { data } = $props()
|
||||
|
||||
let sidebar: boolean = $state(false)
|
||||
|
||||
onMount(() => {
|
||||
if (browser)
|
||||
setSessionStorage(
|
||||
@@ -62,22 +53,16 @@
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
{#if sidebar}
|
||||
<Modal bind:open={sidebar}>
|
||||
{#snippet customTitle()}
|
||||
<span>About</span>
|
||||
{/snippet}
|
||||
<div>
|
||||
<CommunityCard
|
||||
bind:community_view={data.community.community_view}
|
||||
moderators={data.community.moderators}
|
||||
/>
|
||||
</div>
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
<Header pageHeader>
|
||||
<div class="flex flex-col w-full">
|
||||
<PostListShell
|
||||
posts={data.posts}
|
||||
cursor={data.next_page}
|
||||
getParams={data.params}
|
||||
params={{
|
||||
sort: data.params.sort!,
|
||||
}}
|
||||
client={data.client}
|
||||
>
|
||||
{#snippet extended()}
|
||||
<CommunityHeader
|
||||
bind:community={data.community.community_view.community}
|
||||
bind:subscribed={data.community.community_view.subscribed}
|
||||
@@ -88,93 +73,43 @@
|
||||
compact="lg"
|
||||
avatarCircle={false}
|
||||
/>
|
||||
</div>
|
||||
{#snippet extended()}
|
||||
<div class="flex flex-row gap-2">
|
||||
<Sort selected={data.params.sort!} />
|
||||
<ViewSelect showLabel />
|
||||
</div>
|
||||
{/snippet}
|
||||
</Header>
|
||||
|
||||
{#if profile.current.user}
|
||||
{#if !data.community.discussion_languages.every( (l) => profile.current.user?.discussion_languages.includes(l), ) && profile.current.user.discussion_languages.length > 0}
|
||||
{@const missing = data.community.discussion_languages.filter(
|
||||
(i) => !profile.current.user?.discussion_languages.includes(i),
|
||||
)}
|
||||
<Note class="p-1! pl-3! flex-col md:flex-row">
|
||||
<div>{$t('routes.community.languageWarning')}</div>
|
||||
<Button
|
||||
class="inline-block ml-auto"
|
||||
href="/profile/settings"
|
||||
color="tertiary"
|
||||
rounding="pill"
|
||||
size="md"
|
||||
>
|
||||
{$t('profile.profile')}
|
||||
{#snippet suffix()}
|
||||
<Icon src={ArrowRight} size="16" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
</Note>
|
||||
<div class="flex flex-row gap-4 flex-wrap -mt-2">
|
||||
{#if site.data?.all_languages}
|
||||
{@const allLanguages = site.data.all_languages}
|
||||
{#each missing as language (language)}
|
||||
<a href="/profile/settings#languages" class="inline-block w-max">
|
||||
<Badge color="blue-subtle">
|
||||
<Icon src={Plus} size="16" micro />
|
||||
{allLanguages.find((i) => language == i.id)?.name}
|
||||
</Badge>
|
||||
</a>
|
||||
{/each}
|
||||
{#if data.community.community_view.blocked}
|
||||
<Note>You've blocked this community.</Note>
|
||||
{/if}
|
||||
{#if profile.current.user}
|
||||
{#if !data.community.discussion_languages.every( (l) => profile.current.user?.discussion_languages.includes(l), ) && profile.current.user.discussion_languages.length > 0}
|
||||
{@const missing = data.community.discussion_languages.filter(
|
||||
(i) => !profile.current.user?.discussion_languages.includes(i),
|
||||
)}
|
||||
<Note class="p-1! pl-3! flex-col md:flex-row">
|
||||
<div>{$t('routes.community.languageWarning')}</div>
|
||||
<Button
|
||||
class="inline-block ml-auto"
|
||||
href="/profile/settings"
|
||||
color="tertiary"
|
||||
rounding="pill"
|
||||
size="md"
|
||||
>
|
||||
{$t('profile.profile')}
|
||||
{#snippet suffix()}
|
||||
<Icon src={ArrowRight} size="16" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
</Note>
|
||||
<div class="flex flex-row gap-4 flex-wrap -mt-2">
|
||||
{#if site.data?.all_languages}
|
||||
{@const allLanguages = site.data.all_languages}
|
||||
{#each missing as language (language)}
|
||||
<a href="/profile/settings#languages" class="inline-block w-max">
|
||||
<Badge color="blue-subtle">
|
||||
<Icon src={Plus} size="16" micro />
|
||||
{allLanguages.find((i) => language == i.id)?.name}
|
||||
</Badge>
|
||||
</a>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if data.community.community_view.blocked}
|
||||
<Placeholder
|
||||
icon={XMark}
|
||||
title="Blocked"
|
||||
description="You've blocked this community."
|
||||
>
|
||||
<Button href="/profile/blocks">
|
||||
{#snippet suffix()}
|
||||
<Icon src={ArrowRight} size="16" mini />
|
||||
{/snippet}
|
||||
Blocked Communities
|
||||
</Button>
|
||||
</Placeholder>
|
||||
{:else}
|
||||
{@const SvelteComponent = browser ? VirtualFeed : PostFeed}
|
||||
<SvelteComponent
|
||||
bind:posts={data.posts}
|
||||
bind:lastSeen={
|
||||
() => data.client.lastSeen ?? 0, (v) => (data.client.lastSeen = v)
|
||||
}
|
||||
bind:params={data.params}
|
||||
virtualList={{ itemHeights: data.client?.itemHeights ?? [] }}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<svelte:element
|
||||
this={settings.infiniteScroll ? 'noscript' : 'div'}
|
||||
class="mt-auto"
|
||||
>
|
||||
<Pageination
|
||||
cursor={{ next: data.next_page }}
|
||||
href={(page) =>
|
||||
typeof page == 'number' ? `?page=${page}` : `?cursor=${page}`}
|
||||
>
|
||||
<span class="flex flex-row items-center gap-1">
|
||||
<Icon src={ChartBar} size="16" mini />
|
||||
{$t('routes.frontpage.footer', {
|
||||
users: site.data?.site_view.counts.users_active_day ?? '??',
|
||||
})}
|
||||
</span>
|
||||
</Pageination>
|
||||
</svelte:element>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</PostListShell>
|
||||
@@ -9,4 +9,4 @@
|
||||
let { topic }: Props = $props()
|
||||
</script>
|
||||
|
||||
<CommonItem title={topic.title ?? topic.name} href="/t/{topic.id}" />
|
||||
<CommonItem title={topic.title ?? topic.name} href="/topic/{topic.id}" />
|
||||
+48
-104
@@ -1,21 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment'
|
||||
import { page } from '$app/state'
|
||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||
import ViewSelect from '$lib/components/lemmy/dropdowns/ViewSelect.svelte'
|
||||
import ItemList from '$lib/components/lemmy/generic/ItemList.svelte'
|
||||
import { PostFeed, VirtualFeed } from '$lib/components/lemmy/post'
|
||||
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||
import { Header } from '$lib/components/ui/layout'
|
||||
import Pageination from '$lib/components/ui/layout/Pageination.svelte'
|
||||
import { PostListShell } from '$lib/components/ui/layout'
|
||||
import { t } from '$lib/i18n/translations.js'
|
||||
import type { FeedTypes } from '$lib/lemmy/feeds/feed.svelte.js'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { communityLink } from '$lib/util.svelte.js'
|
||||
import { Spinner } from 'mono-svelte'
|
||||
import Button from 'mono-svelte/button/Button.svelte'
|
||||
import { ArrowRight, Icon } from 'svelte-hero-icons'
|
||||
import { SvelteURL } from 'svelte/reactivity'
|
||||
|
||||
interface Props {
|
||||
@@ -24,16 +15,6 @@
|
||||
|
||||
let { data = $bindable() }: Props = $props()
|
||||
|
||||
$effect(() => {
|
||||
if (data.params.sort) settings.defaultSort.sort = data.params.sort
|
||||
})
|
||||
|
||||
const FeedComponent = $derived(
|
||||
settings.infiniteScroll && browser && !settings.posts.noVirtualize
|
||||
? VirtualFeed
|
||||
: PostFeed,
|
||||
)
|
||||
|
||||
let title = $state('Loading...')
|
||||
data.feed.then((i) => (title = i?.title ?? ''))
|
||||
</script>
|
||||
@@ -44,87 +25,50 @@
|
||||
</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="flex flex-col gap-2 max-w-full w-full min-w-0">
|
||||
<Header pageHeader>
|
||||
{#snippet extended()}
|
||||
<div class="min-h-56 grid place-items-center">
|
||||
{#await data.feed}
|
||||
<Spinner width={32} />
|
||||
{:then feed}
|
||||
{#if feed}
|
||||
<EntityHeader
|
||||
class="w-full relative flex flex-col"
|
||||
compact="always"
|
||||
avatarCircle={false}
|
||||
name={feed.title}
|
||||
avatar={feed.icon}
|
||||
>
|
||||
{#snippet nameDetail()}
|
||||
<p class="text-lg">{feed.name}</p>
|
||||
{/snippet}
|
||||
{#if feed.communities}
|
||||
<Expandable>
|
||||
{#snippet title()}
|
||||
{$t('content.communities')}
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={feed.communities.map((i) => ({
|
||||
id: i.id,
|
||||
name: i.title,
|
||||
url: communityLink(i),
|
||||
avatar: i.icon,
|
||||
instance: new SvelteURL(i.actor_id).hostname,
|
||||
}))}
|
||||
/>
|
||||
</Expandable>
|
||||
{/if}
|
||||
</EntityHeader>
|
||||
{/if}
|
||||
{/await}
|
||||
</div>
|
||||
<form class="" method="get" action={page.url.pathname}>
|
||||
<div class="flex flex-row gap-2">
|
||||
<Sort
|
||||
placement="bottom"
|
||||
name="sort"
|
||||
navigate
|
||||
bind:selected={data.params.sort!}
|
||||
/>
|
||||
<ViewSelect placement="bottom" />
|
||||
|
||||
<noscript>
|
||||
<Button
|
||||
class="self-end h-[34px] aspect-square"
|
||||
size="custom"
|
||||
submit
|
||||
>
|
||||
<Icon src={ArrowRight} size="16" micro />
|
||||
</Button>
|
||||
</noscript>
|
||||
</div>
|
||||
</form>
|
||||
{/snippet}
|
||||
</Header>
|
||||
|
||||
<FeedComponent
|
||||
bind:posts={data.posts}
|
||||
bind:lastSeen={
|
||||
() => data.client.lastSeen ?? 0, (v) => (data.client.lastSeen = v)
|
||||
}
|
||||
bind:params={data.params}
|
||||
virtualList={{ itemHeights: data.client?.itemHeights ?? [] }}
|
||||
/>
|
||||
<svelte:element
|
||||
this={settings.infiniteScroll && !settings.posts.noVirtualize
|
||||
? 'noscript'
|
||||
: 'div'}
|
||||
class="mt-auto flex flex-col"
|
||||
>
|
||||
<Pageination
|
||||
cursor={{ next: data.next_page }}
|
||||
href={(page) =>
|
||||
typeof page == 'number' ? `?page=${page}` : `?cursor=${page}`}
|
||||
back={false}
|
||||
/>
|
||||
</svelte:element>
|
||||
</div>
|
||||
<PostListShell
|
||||
client={data.client}
|
||||
posts={data.posts}
|
||||
cursor={data.next_page}
|
||||
getParams={data.params}
|
||||
params={{
|
||||
sort: data.params.sort!,
|
||||
}}
|
||||
>
|
||||
{#snippet extended()}
|
||||
<div class="min-h-56 grid place-items-center">
|
||||
{#await data.feed}
|
||||
<Spinner width={32} />
|
||||
{:then feed}
|
||||
{#if feed}
|
||||
<EntityHeader
|
||||
class="w-full relative flex flex-col"
|
||||
compact="always"
|
||||
avatarCircle={false}
|
||||
name={feed.title}
|
||||
avatar={feed.icon}
|
||||
>
|
||||
{#snippet nameDetail()}
|
||||
<p class="text-lg">{feed.name}</p>
|
||||
{/snippet}
|
||||
{#if feed.communities}
|
||||
<Expandable>
|
||||
{#snippet title()}
|
||||
{$t('content.communities')}
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={feed.communities.map((i) => ({
|
||||
id: i.id,
|
||||
name: i.title,
|
||||
url: communityLink(i),
|
||||
avatar: i.icon,
|
||||
instance: new SvelteURL(i.actor_id).hostname,
|
||||
}))}
|
||||
/>
|
||||
</Expandable>
|
||||
{/if}
|
||||
</EntityHeader>
|
||||
{/if}
|
||||
{/await}
|
||||
</div>
|
||||
{/snippet}
|
||||
</PostListShell>
|
||||
@@ -25,15 +25,28 @@ function buildContext(thread?: string) {
|
||||
return { parentId, showContext, max_depth, focus: thread?.split('.').at(-1) }
|
||||
}
|
||||
|
||||
function findInFeed(id: '/' | '/c/[name]', postId: string) {
|
||||
return feed(id, async (p) => ({
|
||||
// this will never run
|
||||
...(await client().getPosts(p)),
|
||||
client: {},
|
||||
params: p,
|
||||
}))
|
||||
.peek()
|
||||
?.posts.find((i) => i.post.id.toString() == postId)
|
||||
async function findInFeed(id: '/' | '/c/[name]' | '/f/[id]', postId: string) {
|
||||
// this never actually loads anything
|
||||
if (id == '/') {
|
||||
const resolved = feed(id, async (p) => ({
|
||||
posts: (await client().getPosts(p)).posts,
|
||||
client: {},
|
||||
params: p,
|
||||
})).peek()
|
||||
|
||||
return resolved
|
||||
? resolved?.posts?.find((i) => i.post.id.toString() == postId)
|
||||
: undefined
|
||||
} else {
|
||||
return feed(id, async (p) => ({
|
||||
...(await client().getPosts(p)),
|
||||
client: {},
|
||||
params: p,
|
||||
community: await client().getCommunity({}),
|
||||
}))
|
||||
.peek()
|
||||
?.posts.find((i) => i.post.id.toString() == postId)
|
||||
}
|
||||
}
|
||||
|
||||
export async function load({ params, url, route }) {
|
||||
@@ -44,7 +57,9 @@ export async function load({ params, url, route }) {
|
||||
const sort = settings?.defaultSort?.comments ?? 'Hot'
|
||||
|
||||
const cachedPost =
|
||||
findInFeed('/', params.id) ?? findInFeed('/c/[name]', params.id)
|
||||
(await findInFeed('/', params.id)) ??
|
||||
(await findInFeed('/c/[name]', params.id)) ??
|
||||
(await findInFeed('/f/[id]', params.id))
|
||||
|
||||
const {
|
||||
parentId,
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
<script lang="ts">
|
||||
import ItemList from '$lib/components/lemmy/generic/ItemList.svelte'
|
||||
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||
import { PostListShell } from '$lib/components/ui/layout'
|
||||
import { t } from '$lib/i18n/translations.js'
|
||||
import { communityLink } from '$lib/util.svelte.js'
|
||||
import { Spinner } from 'mono-svelte'
|
||||
import { SvelteURL } from 'svelte/reactivity'
|
||||
|
||||
let { data = $bindable() } = $props()
|
||||
|
||||
let title = $state('Loading...')
|
||||
data.topic.then((i) => (title = i?.title ?? ''))
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>
|
||||
{title}
|
||||
</title>
|
||||
</svelte:head>
|
||||
|
||||
<PostListShell
|
||||
client={data.client}
|
||||
posts={data.posts}
|
||||
cursor={data.next_page}
|
||||
getParams={data.params}
|
||||
params={{
|
||||
sort: data.params.sort!,
|
||||
}}
|
||||
>
|
||||
{#snippet extended()}
|
||||
<div class="min-h-56 grid place-items-center">
|
||||
{#await data.topic}
|
||||
<Spinner width={32} />
|
||||
{:then topic}
|
||||
{#if topic}
|
||||
<EntityHeader
|
||||
class="w-full relative flex flex-col"
|
||||
compact="always"
|
||||
avatarCircle={false}
|
||||
name={topic.name}
|
||||
>
|
||||
{#snippet nameDetail()}
|
||||
<p class="text-lg">{topic.name}</p>
|
||||
{/snippet}
|
||||
{#if topic.communities}
|
||||
<Expandable>
|
||||
{#snippet title()}
|
||||
{$t('content.communities')}
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={topic.communities.map((i) => ({
|
||||
id: i.id,
|
||||
name: i.title,
|
||||
url: communityLink(i),
|
||||
avatar: i.icon,
|
||||
instance: new SvelteURL(i.actor_id).hostname,
|
||||
}))}
|
||||
/>
|
||||
</Expandable>
|
||||
{/if}
|
||||
</EntityHeader>
|
||||
{/if}
|
||||
{/await}
|
||||
</div>
|
||||
{/snippet}
|
||||
</PostListShell>
|
||||
@@ -0,0 +1,38 @@
|
||||
import { client } from '$lib/client/lemmy.svelte.js'
|
||||
import type { SortType } from '$lib/client/types'
|
||||
import { feed } from '$lib/lemmy/feeds/feed.svelte.js'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { error } from '@sveltejs/kit'
|
||||
|
||||
export async function load({ url, fetch, route, params }) {
|
||||
const piefed = client({ func: fetch })
|
||||
|
||||
if (!piefed.getTopics) error(404, 'unsupported')
|
||||
|
||||
const sort: SortType =
|
||||
(url.searchParams.get('sort') as SortType) || settings.defaultSort.sort
|
||||
|
||||
const cursor = url.searchParams.get('cursor') as string | undefined
|
||||
|
||||
const feedData = await feed(route.id, async (p) => {
|
||||
const piefedTopicData = piefed.getTopics!({
|
||||
include_communities: true,
|
||||
}).then((i) => i.topics.find((j) => j.id.toString() == p.topic_id!))
|
||||
|
||||
return {
|
||||
...(await piefed.getPosts(p)),
|
||||
topic: piefedTopicData,
|
||||
params: p,
|
||||
client: {},
|
||||
}
|
||||
}).load({
|
||||
page_cursor: cursor,
|
||||
sort: sort,
|
||||
type_: 'All',
|
||||
limit: 20,
|
||||
show_hidden: settings.posts.showHidden,
|
||||
topic_id: params.id,
|
||||
})
|
||||
|
||||
return feedData
|
||||
}
|
||||
Reference in new issue
Block a user