feat [2/3]: add feed viewing
This commit is contained in:
1 parent
5ed8346027
commit
82a8747ad4
6 files changed
+202
-10
No files matched your search
@@ -50,7 +50,7 @@
|
|||||||
blocked?: boolean
|
blocked?: boolean
|
||||||
banner?: boolean
|
banner?: boolean
|
||||||
class?: string
|
class?: string
|
||||||
compact?: 'lg'
|
compact?: 'always' | 'lg'
|
||||||
avatarCircle?: boolean
|
avatarCircle?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
nameDetail?: import('svelte').Snippet
|
nameDetail?: import('svelte').Snippet
|
||||||
actions?: import('svelte').Snippet
|
actions?: import('svelte').Snippet
|
||||||
children?: import('svelte').Snippet
|
children?: import('svelte').Snippet
|
||||||
compact?: 'lg'
|
compact?: 'always' | 'lg'
|
||||||
avatarCircle?: boolean
|
avatarCircle?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +48,7 @@
|
|||||||
<div
|
<div
|
||||||
class={[
|
class={[
|
||||||
compact == 'lg' && 'lg:hidden',
|
compact == 'lg' && 'lg:hidden',
|
||||||
|
compact == 'always' && 'hidden',
|
||||||
'absolute inset-0 h-96 overflow-x-hidden -z-10',
|
'absolute inset-0 h-96 overflow-x-hidden -z-10',
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
@@ -80,7 +81,7 @@
|
|||||||
!avatarCircle && 'rounded-3xl!',
|
!avatarCircle && 'rounded-3xl!',
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
<div class="py-4 flex flex-col xl:flex-row gap-4">
|
<div class="py-4 flex flex-col gap-4">
|
||||||
<div class="flex flex-col flex-1">
|
<div class="flex flex-col flex-1">
|
||||||
<svelte:element
|
<svelte:element
|
||||||
this={url ? 'a' : 'span'}
|
this={url ? 'a' : 'span'}
|
||||||
@@ -107,7 +108,8 @@
|
|||||||
<div
|
<div
|
||||||
class={[
|
class={[
|
||||||
compact == 'lg' && 'lg:hidden',
|
compact == 'lg' && 'lg:hidden',
|
||||||
'text-sm flex flex-row flex-wrap overflow-hidden gap-4 h-full',
|
compact == 'always' ? 'hidden' : 'flex',
|
||||||
|
'text-sm flex-row flex-wrap overflow-hidden gap-4 h-full',
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{#each stats as stat}
|
{#each stats as stat}
|
||||||
@@ -136,6 +138,7 @@
|
|||||||
<div
|
<div
|
||||||
class={[
|
class={[
|
||||||
compact == 'lg' && 'lg:hidden',
|
compact == 'lg' && 'lg:hidden',
|
||||||
|
compact == 'always' && 'hidden',
|
||||||
'relative w-full mb-4 text-base',
|
'relative w-full mb-4 text-base',
|
||||||
center ? 'text-center' : 'text-left',
|
center ? 'text-center' : 'text-left',
|
||||||
]}
|
]}
|
||||||
|
|||||||
@@ -37,11 +37,17 @@
|
|||||||
{style}
|
{style}
|
||||||
aria-label={$t('aria.element.pageHeader')}
|
aria-label={$t('aria.element.pageHeader')}
|
||||||
>
|
>
|
||||||
<h1
|
{#if children}
|
||||||
class={[sizes[size], 'flex gap-2 w-full tracking-tight font-medium', clazz]}
|
<h1
|
||||||
>
|
class={[
|
||||||
{@render children?.()}
|
sizes[size],
|
||||||
</h1>
|
'flex gap-2 w-full tracking-tight font-medium',
|
||||||
|
clazz,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</h1>
|
||||||
|
{/if}
|
||||||
{#if extended}
|
{#if extended}
|
||||||
<div class="flex flex-col gap-3 mt-3">
|
<div class="flex flex-col gap-3 mt-3">
|
||||||
{@render extended?.()}
|
{@render extended?.()}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { profile } from '$lib/auth.svelte'
|
|||||||
import type {
|
import type {
|
||||||
CommentView,
|
CommentView,
|
||||||
CommunityView,
|
CommunityView,
|
||||||
|
FeedView,
|
||||||
GetComments,
|
GetComments,
|
||||||
GetCommunityResponse,
|
GetCommunityResponse,
|
||||||
GetPersonDetails,
|
GetPersonDetails,
|
||||||
@@ -48,7 +49,7 @@ export class Feed<Params, Response> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FeedTypes {
|
export interface FeedTypes {
|
||||||
'/': [
|
'/': [
|
||||||
GetPosts,
|
GetPosts,
|
||||||
{
|
{
|
||||||
@@ -94,6 +95,20 @@ interface FeedTypes {
|
|||||||
params: { posts: GetPost; comments: GetComments }
|
params: { posts: GetPost; comments: GetComments }
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
'/f/[id]': [
|
||||||
|
GetPosts,
|
||||||
|
|
||||||
|
{
|
||||||
|
posts: PostView[]
|
||||||
|
next_page?: string
|
||||||
|
params: GetPosts
|
||||||
|
feed: Promise<FeedView | undefined>
|
||||||
|
client: {
|
||||||
|
itemHeights?: (number | null)[]
|
||||||
|
lastSeen?: number
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
const feeds = new SvelteMap<keyof FeedTypes, Feed<any, any>>()
|
const feeds = new SvelteMap<keyof FeedTypes, Feed<any, any>>()
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
<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 { 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 {
|
||||||
|
data: FeedTypes['/f/[id]'][1]
|
||||||
|
}
|
||||||
|
|
||||||
|
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>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>
|
||||||
|
{title}
|
||||||
|
</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>
|
||||||
@@ -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.getFeeds) 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 piefedFeedData = piefed.getFeeds!({ include_communities: true }).then(
|
||||||
|
(i) => i.feeds.find((j) => j.id.toString() == p.feed_id!),
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
...(await piefed.getPosts(p)),
|
||||||
|
feed: piefedFeedData,
|
||||||
|
params: p,
|
||||||
|
client: {},
|
||||||
|
}
|
||||||
|
}).load({
|
||||||
|
page_cursor: cursor,
|
||||||
|
sort: sort,
|
||||||
|
type_: 'All',
|
||||||
|
limit: 20,
|
||||||
|
show_hidden: settings.posts.showHidden,
|
||||||
|
feed_id: params.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
return feedData
|
||||||
|
}
|
||||||
Reference in new issue
Block a user