feat: add filters to saved posts

This commit is contained in:
Xylight committed 2024-09-11 19:55:09 -07:00
1 parent 8f9ead1fe1
commit f94a7e82eb
4 files changed
+60 -10

No files matched your search

+51 -5
View File
@@ -11,9 +11,22 @@
import { Bookmark } from 'svelte-hero-icons'
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 { Select } from 'mono-svelte'
import {
Icon,
Bars3,
PencilSquare,
ChatBubbleOvalLeft,
AdjustmentsHorizontal,
} from 'svelte-hero-icons'
export let data
// svelte being stupid
$: type = data.type as any
const isComment = (item: CommentView | PostView): item is CommentView =>
'comment' in item
</script>
@@ -22,7 +35,33 @@
<title>{$t('routes.saved')}</title>
</svelte:head>
<Header pageHeader>{$t('routes.saved')}</Header>
<Header pageHeader>
{$t('routes.saved')}
<div slot="extended" class="flex items-center">
<Select
bind:value={type}
on:change={() => searchParam($page.url, 'type', type, 'page')}
>
<div class="flex items-center gap-0.5" slot="label">
<Icon src={AdjustmentsHorizontal} size="15" mini />
{$t('filter.filter')}
</div>
<option value="all">
<Icon src={Bars3} micro size="15" />
{$t('content.all')}
</option>
<option value="posts">
<Icon src={PencilSquare} micro size="15" />
{$t('content.posts')}
</option>
<option value="comments">
<Icon src={ChatBubbleOvalLeft} micro size="15" />
{$t('content.comments')}
</option>
</Select>
</div>
</Header>
<div
class="flex flex-col list-none my-4 divide-slate-200 dark:divide-zinc-800"
class:gap-4={$userSettings.view == 'card'}
@@ -46,7 +85,14 @@
{/each}
{/if}
</div>
<Pageination
on:change={(p) => searchParam($page.url, 'page', p.detail.toString())}
page={data.page}
/>
<div
class="sticky z-30 mx-auto max-w-full"
style="bottom: max(1.5rem, {$contentPadding.bottom}px);"
>
<Tabs routes={[]} class="mx-auto">
<Pageination
on:change={(p) => searchParam($page.url, 'page', p.detail.toString())}
page={data.page}
/>
</Tabs>
</div>
+8 -4
View File
@@ -20,6 +20,8 @@ function getSavedItemPublished(item: PostView | CommentView) {
export async function load({ url, fetch }) {
if (!get(profile)) return { posts: [], page: 0 }
const page = Number(url.searchParams.get('page')) || 1
const type: 'comments' | 'posts' | 'all' =
(url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all'
const client = getClient(undefined, fetch)
@@ -27,14 +29,16 @@ export async function load({ url, fetch }) {
saved_only: true,
limit: 20,
page: page,
sort: 'New' as SortType & CommentSortType,
// sort: 'New' as SortType & CommentSortType,
type_: 'All' as ListingType,
}
const [posts, comments] = await Promise.all([
client.getPosts(params),
type == 'posts' || type == 'all' ? client.getPosts(params) : { posts: [] },
client.getComments(params),
type == 'comments' || type == 'all'
? client.getComments(params)
: { comments: [] },
])
const everything = [...posts.posts, ...comments.comments].sort(
@@ -43,5 +47,5 @@ export async function load({ url, fetch }) {
Date.parse(getSavedItemPublished(a))
)
return { page: page, data: everything }
return { page: page, data: everything, type: type }
}