feat: add user page to profile page
This commit is contained in:
1 parent
a5c41a9c90
commit
d193719475
8 files changed
+102
-5
No files matched your search
@@ -196,11 +196,7 @@
|
|||||||
{$profile?.user ? $profile.user.local_user_view.person.name : 'Profile'}
|
{$profile?.user ? $profile.user.local_user_view.person.name : 'Profile'}
|
||||||
</li>
|
</li>
|
||||||
{#if $profile?.user}
|
{#if $profile?.user}
|
||||||
<MenuButton
|
<MenuButton link href="/profile">
|
||||||
link
|
|
||||||
href="/u/{$profile.user.local_user_view.person
|
|
||||||
.name}@{$profile.instance}"
|
|
||||||
>
|
|
||||||
<Icon src={UserCircle} mini width={16} /> Profile
|
<Icon src={UserCircle} mini width={16} /> Profile
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuButton link href="/inbox">
|
<MenuButton link href="/inbox">
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<script>
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
import { page } from '$app/stores'
|
||||||
|
|
||||||
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Profile</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-4 h-full">
|
||||||
|
<MultiSelect
|
||||||
|
headless
|
||||||
|
options={['/profile/user', '/profile/settings']}
|
||||||
|
optionNames={['User', 'Settings']}
|
||||||
|
selected={$page.url.pathname}
|
||||||
|
on:select={(e) => {
|
||||||
|
goto(e.detail)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
import { getClient } from '$lib/lemmy.js'
|
||||||
|
import { getItemPublished } from '$lib/lemmy/item.js'
|
||||||
|
import type { SortType } from 'lemmy-js-client'
|
||||||
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
|
export async function load({ params, url, fetch }) {
|
||||||
|
if (!get(profile)?.user) return {}
|
||||||
|
|
||||||
|
const page = Number(url.searchParams.get('page')) || 1
|
||||||
|
const type: 'comments' | 'posts' | 'all' =
|
||||||
|
(url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all'
|
||||||
|
const sort: SortType = (url.searchParams.get('sort') as SortType) || 'New'
|
||||||
|
|
||||||
|
const user = await getClient(undefined, fetch).getPersonDetails({
|
||||||
|
limit: 20,
|
||||||
|
page: page,
|
||||||
|
username: get(profile)!.user?.local_user_view.person.name,
|
||||||
|
sort: sort,
|
||||||
|
auth: get(profile)?.jwt,
|
||||||
|
})
|
||||||
|
|
||||||
|
const items = [...user.posts, ...user.comments]
|
||||||
|
|
||||||
|
if (sort == 'TopAll') {
|
||||||
|
items.sort(
|
||||||
|
(a, b) =>
|
||||||
|
b.counts.upvotes -
|
||||||
|
b.counts.downvotes -
|
||||||
|
(a.counts.upvotes - a.counts.downvotes)
|
||||||
|
)
|
||||||
|
} else if (sort == 'New') {
|
||||||
|
items.sort(
|
||||||
|
(a, b) =>
|
||||||
|
Date.parse(getItemPublished(b)) - Date.parse(getItemPublished(a))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: type,
|
||||||
|
page: page,
|
||||||
|
sort: sort,
|
||||||
|
user: {
|
||||||
|
person_view: user.person_view,
|
||||||
|
submissions: items,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
You're not supposed to be here.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { redirect } from '@sveltejs/kit'
|
||||||
|
|
||||||
|
export const load = async () => {
|
||||||
|
throw redirect(300, '/profile/user')
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
hi
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import UserPage from '../../u/[name]/+page.svelte'
|
||||||
|
export let data
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if data.user && data.sort && data.type && data.page}
|
||||||
|
<UserPage
|
||||||
|
data={{
|
||||||
|
items: data.user.submissions,
|
||||||
|
page: data.page,
|
||||||
|
person_view: data.user.person_view,
|
||||||
|
sort: data.sort,
|
||||||
|
type: data.type,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
<pre>
|
||||||
|
{JSON.stringify(data)}
|
||||||
|
</pre>
|
||||||
|
{/if}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export async function load({ parent }) {
|
||||||
|
return await parent()
|
||||||
|
}
|
||||||
Reference in new issue
Block a user