feat [3/3]: add topic viewing

This commit is contained in:
James Xylight authored and xylight committed 2025-09-17 00:27:11 +00:00
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',
+1
View File
@@ -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>
+3 -2
View File
@@ -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
+14
View File
@@ -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>>()