feat: Add user pages
This commit is contained in:
1 parent
04704749b7
commit
9efe1df0c2
12 files changed
+222
-29
No files matched your search
+3
-6
@@ -1,5 +1,3 @@
|
|||||||
import { error } from '@sveltejs/kit'
|
|
||||||
|
|
||||||
function buildUrl(inputUrl: URL): URL {
|
function buildUrl(inputUrl: URL): URL {
|
||||||
let withoutCors = inputUrl.pathname.replace('/cors/', '')
|
let withoutCors = inputUrl.pathname.replace('/cors/', '')
|
||||||
|
|
||||||
@@ -10,9 +8,9 @@ function buildUrl(inputUrl: URL): URL {
|
|||||||
return new URL(`${withoutCors}?${inputUrl.searchParams.toString()}`)
|
return new URL(`${withoutCors}?${inputUrl.searchParams.toString()}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleError() {
|
export function handleError({ error, event }) {
|
||||||
return {
|
return {
|
||||||
message: 'The proxy failed to fetch from that URL',
|
message: 'There was an error during rendering',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,13 +69,12 @@ export async function handle({ event, resolve }) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('caught it')
|
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
message: 'the proxy failed to fetch from server',
|
message: 'the proxy failed to fetch from server',
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
status: 500,
|
status: 200,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,19 +5,15 @@
|
|||||||
export let avatar: boolean = false
|
export let avatar: boolean = false
|
||||||
|
|
||||||
function linkFromCommunity(community: Community) {
|
function linkFromCommunity(community: Community) {
|
||||||
const local = community.local
|
|
||||||
|
|
||||||
// if (local) {
|
|
||||||
// return `/c/${community.name}`
|
|
||||||
// } else {
|
|
||||||
const domain = new URL(community.actor_id).hostname
|
const domain = new URL(community.actor_id).hostname
|
||||||
|
|
||||||
return `/c/${community.name}@${domain}`
|
return `/c/${community.name}@${domain}`
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<a class="items-center flex flex-row gap-2" href={linkFromCommunity(community)}>
|
<a
|
||||||
|
class="items-center flex flex-row gap-2 hover:underline"
|
||||||
|
href={linkFromCommunity(community)}
|
||||||
|
>
|
||||||
{#if avatar}
|
{#if avatar}
|
||||||
<img
|
<img
|
||||||
src={community.icon ??
|
src={community.icon ??
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
import { authData, getClient } from '$lib/lemmy.js'
|
import { authData, getClient } from '$lib/lemmy.js'
|
||||||
import PostVote from '$lib/components/lemmy/PostVote.svelte'
|
import PostVote from '$lib/components/lemmy/PostVote.svelte'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
|
import UserLink from '$lib/components/user/UserLink.svelte'
|
||||||
|
|
||||||
let postRes: PostView
|
let postRes: PostView
|
||||||
export { postRes as post }
|
export { postRes as post }
|
||||||
@@ -64,7 +65,7 @@
|
|||||||
<span class="flex flex-row gap-2 text-sm opacity-80 items-center">
|
<span class="flex flex-row gap-2 text-sm opacity-80 items-center">
|
||||||
<CommunityLink avatar community={postRes.community} />
|
<CommunityLink avatar community={postRes.community} />
|
||||||
<div class="ml-auto" />
|
<div class="ml-auto" />
|
||||||
<span class="opacity-50">{postRes.creator.name}</span>
|
<UserLink user={postRes.creator} />
|
||||||
<span class="opacity-50">
|
<span class="opacity-50">
|
||||||
<RelativeDate date={new Date(postRes.post.published)} />
|
<RelativeDate date={new Date(postRes.post.published)} />
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
import { Color } from '$lib/ui/colors.js'
|
import { Color } from '$lib/ui/colors.js'
|
||||||
import CommentForm from './CommentForm.svelte'
|
import CommentForm from './CommentForm.svelte'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
|
import UserLink from '$lib/components/user/UserLink.svelte'
|
||||||
|
|
||||||
export let node: CommentNodeI
|
export let node: CommentNodeI
|
||||||
|
|
||||||
@@ -66,12 +67,9 @@
|
|||||||
<summary
|
<summary
|
||||||
class="flex flex-row cursor-pointer arrow gap-2 items-center group"
|
class="flex flex-row cursor-pointer arrow gap-2 items-center group"
|
||||||
>
|
>
|
||||||
<Avatar
|
<span class="text-sm">
|
||||||
url={node.comment_view.creator.avatar ??
|
<UserLink avatar user={node.comment_view.creator} />
|
||||||
`https://api.dicebear.com/6.x/initials/svg?seed=${node.comment_view.creator.name}`}
|
</span>
|
||||||
width={24}
|
|
||||||
/>
|
|
||||||
<span class="text-sm">{node.comment_view.creator.name}</span>
|
|
||||||
<span class="text-sm opacity-60 md:inline hidden">
|
<span class="text-sm opacity-60 md:inline hidden">
|
||||||
{node.comment_view.counts.score} point{node.comment_view.counts.score ==
|
{node.comment_view.counts.score} point{node.comment_view.counts.score ==
|
||||||
1
|
1
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
Cog6Tooth,
|
Cog6Tooth,
|
||||||
Icon,
|
Icon,
|
||||||
Inbox,
|
Inbox,
|
||||||
|
UserCircle,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -65,6 +66,9 @@
|
|||||||
<Icon src={ArrowLeftOnRectangle} mini width={16} /> Log in
|
<Icon src={ArrowLeftOnRectangle} mini width={16} /> Log in
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{:else}
|
{:else}
|
||||||
|
<MenuButton link href="/u/{$user.person_view.person.name}">
|
||||||
|
<Icon src={UserCircle} mini width={16} /> Profile
|
||||||
|
</MenuButton>
|
||||||
<MenuButton link href="/inbox">
|
<MenuButton link href="/inbox">
|
||||||
<Icon src={Inbox} mini width={16} /> Inbox
|
<Icon src={Inbox} mini width={16} /> Inbox
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { Person } from 'lemmy-js-client'
|
||||||
|
|
||||||
|
export let user: Person
|
||||||
|
export let avatar: boolean = false
|
||||||
|
|
||||||
|
function linkFromCommunity(user: Person) {
|
||||||
|
const domain = new URL(user.actor_id).hostname
|
||||||
|
return `/u/${user.name}@${domain}`
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<a
|
||||||
|
class="items-center flex flex-row gap-2 hover:underline"
|
||||||
|
href={linkFromCommunity(user)}
|
||||||
|
>
|
||||||
|
{#if avatar}
|
||||||
|
<img
|
||||||
|
src={user.avatar ??
|
||||||
|
`https://api.dicebear.com/6.x/initials/svg?seed=${user.name}`}
|
||||||
|
alt=""
|
||||||
|
width={24}
|
||||||
|
height={24}
|
||||||
|
class="rounded-full aspect-square object-cover"
|
||||||
|
loading="lazy"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
{user.name}
|
||||||
|
</a>
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
<div class="flex flex-col mx-auto gap-4 justify-center items-center">
|
<div class="flex flex-col mx-auto gap-4 justify-center items-center">
|
||||||
<h1 class="font-black text-3xl">{$page.status}</h1>
|
<h1 class="font-black text-3xl">{$page.status}</h1>
|
||||||
<p class="mx-4 md:mx-8">
|
<p class="mx-4 md:mx-8">
|
||||||
Failed to fetch page. The lemmy servers are having quite a lot of issues
|
Failed to fetch page. Most major lemmy instances are having quite a lot of
|
||||||
right now, this is likely on their end.
|
issues right now, this might be on their end.
|
||||||
</p>
|
</p>
|
||||||
<code class="bg-slate-100 dark:bg-zinc-800 px-2 py-1 rounded-md">
|
<code class="bg-slate-100 dark:bg-zinc-800 px-2 py-1 rounded-md">
|
||||||
{JSON.stringify($page.error)}
|
{JSON.stringify($page.error)}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
import Link from '$lib/components/input/Link.svelte'
|
import Link from '$lib/components/input/Link.svelte'
|
||||||
import { Color } from '$lib/ui/colors.js'
|
import { Color } from '$lib/ui/colors.js'
|
||||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||||
|
import Subscribe from './Subscribe.svelte'
|
||||||
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -56,11 +58,39 @@
|
|||||||
class="py-4 border-b border-black/20 dark:border-white/20
|
class="py-4 border-b border-black/20 dark:border-white/20
|
||||||
flex flex-col gap-1 text-sm"
|
flex flex-col gap-1 text-sm"
|
||||||
>
|
>
|
||||||
<span
|
<div class="flex flex-row justify-between items-center">
|
||||||
class="break-words max-w-full w-max text-base font-bold text-sky-400 hover:underline"
|
<span
|
||||||
>
|
class="break-words max-w-full w-max text-base font-bold text-sky-400 hover:underline"
|
||||||
<CommunityLink community={community.community} />
|
>
|
||||||
</span>
|
<CommunityLink community={community.community} />
|
||||||
|
</span>
|
||||||
|
<div class="w-24">
|
||||||
|
<Subscribe {community} let:subscribe let:subscribing>
|
||||||
|
<Button
|
||||||
|
disabled={subscribing}
|
||||||
|
loading={subscribing}
|
||||||
|
large
|
||||||
|
on:click={async () => {
|
||||||
|
const res = await subscribe()
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
community.subscribed =
|
||||||
|
res.community_view.subscribed != 'NotSubscribed'
|
||||||
|
? 'Subscribed'
|
||||||
|
: 'NotSubscribed'
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
color={community.subscribed == 'Subscribed'
|
||||||
|
? Color.accent
|
||||||
|
: Color.secondary}
|
||||||
|
>
|
||||||
|
{community.subscribed == 'Subscribed'
|
||||||
|
? 'Subscribed'
|
||||||
|
: 'Subscribe'}
|
||||||
|
</Button>
|
||||||
|
</Subscribe>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{#if !community.community.local}
|
{#if !community.community.local}
|
||||||
<span class="opacity-80">
|
<span class="opacity-80">
|
||||||
{new URL(community.community.actor_id).hostname}
|
{new URL(community.community.actor_id).hostname}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { getClient } from '$lib/lemmy.js'
|
||||||
|
import type {
|
||||||
|
Community,
|
||||||
|
CommunityView,
|
||||||
|
SubscribedType,
|
||||||
|
} from 'lemmy-js-client'
|
||||||
|
import { authData } from '$lib/lemmy.js'
|
||||||
|
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
|
||||||
|
export let community: CommunityView
|
||||||
|
|
||||||
|
let subscribing = false
|
||||||
|
|
||||||
|
async function subscribe() {
|
||||||
|
if (!$authData?.token) return
|
||||||
|
|
||||||
|
subscribing = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await getClient().followCommunity({
|
||||||
|
auth: $authData.token,
|
||||||
|
community_id: community.community.id,
|
||||||
|
follow: community.subscribed == 'NotSubscribed',
|
||||||
|
})
|
||||||
|
|
||||||
|
subscribing = false
|
||||||
|
return res
|
||||||
|
} catch (error) {
|
||||||
|
addToast('Error', 'Failed to subscribe to community', ToastType.error)
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribing = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<slot {subscribe} {subscribing} />
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
import PostVote from '$lib/components/lemmy/PostVote.svelte'
|
import PostVote from '$lib/components/lemmy/PostVote.svelte'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
|
import UserLink from '$lib/components/user/UserLink.svelte'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -88,7 +89,7 @@
|
|||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<span class="flex flex-row gap-2 text-sm opacity-80 items-center">
|
<span class="flex flex-row gap-2 text-sm opacity-80 items-center">
|
||||||
<CommunityLink avatar community={postData.community} />
|
<CommunityLink avatar community={postData.community} />
|
||||||
<span class="opacity-50">{postData.creator.name}</span>
|
<span class="opacity-50"><UserLink user={postData.creator} /></span>
|
||||||
</span>
|
</span>
|
||||||
<h1 class="font-bold text-lg">{post.name}</h1>
|
<h1 class="font-bold text-lg">{post.name}</h1>
|
||||||
{#if post.url}
|
{#if post.url}
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
|
||||||
|
import Link from '$lib/components/input/Link.svelte'
|
||||||
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
|
import StickyCard from '$lib/components/ui/StickyCard.svelte'
|
||||||
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
|
import type { GetPersonDetailsResponse } from 'lemmy-js-client'
|
||||||
|
import {
|
||||||
|
Calendar,
|
||||||
|
ChatBubbleOvalLeftEllipsis,
|
||||||
|
Icon,
|
||||||
|
PencilSquare,
|
||||||
|
} from 'svelte-hero-icons'
|
||||||
|
import SvelteMarkdown from 'svelte-markdown'
|
||||||
|
|
||||||
|
export let data: {
|
||||||
|
user: GetPersonDetailsResponse
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex flex-row gap-4 max-w-full">
|
||||||
|
<div class="flex flex-col gap-4 max-w-full">
|
||||||
|
{#each data.user.comments as item}
|
||||||
|
<Card class="flex flex-col bg-white rounded-md p-4 flex-1">
|
||||||
|
<div class="flex flex-row justify-between items-center">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<span class="text-xs dark:text-slate-400 text-zinc-600">
|
||||||
|
<CommunityLink avatar community={item.community} />
|
||||||
|
</span>
|
||||||
|
<span class="flex flex-row items-center text-sm font-bold">
|
||||||
|
{item.post.name}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<Link href="/post/{item.post.id}#{item.comment.id}">Jump</Link>
|
||||||
|
</div>
|
||||||
|
<div class="list-none">
|
||||||
|
<Comment
|
||||||
|
postId={item.post.id}
|
||||||
|
node={{ children: [], comment_view: item, depth: 1 }}
|
||||||
|
replying={false}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="max-w-sm w-full hidden xl:block">
|
||||||
|
<StickyCard>
|
||||||
|
<Avatar
|
||||||
|
width={64}
|
||||||
|
url={data.user.person_view.person.name ??
|
||||||
|
`https://api.dicebear.com/6.x/initials/svg?seed=${data.user.person_view.person.name}`}
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
|
<span class="flex flex-row items-center gap-1 text-sm">
|
||||||
|
<Icon src={Calendar} width={16} height={16} mini />
|
||||||
|
<span class="capitalize">
|
||||||
|
<RelativeDate
|
||||||
|
date={new Date(data.user.person_view.person.published)}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
<div class="text-sm flex flex-row flex-wrap gap-3">
|
||||||
|
<span class="flex flex-row items-center gap-1">
|
||||||
|
<Icon src={PencilSquare} width={16} height={16} mini />
|
||||||
|
<FormattedNumber number={data.user.person_view.counts.post_count} />
|
||||||
|
</span>
|
||||||
|
<span class="flex flex-row items-center gap-1">
|
||||||
|
<Icon src={ChatBubbleOvalLeftEllipsis} width={16} height={16} mini />
|
||||||
|
<FormattedNumber
|
||||||
|
number={data.user.person_view.counts.comment_count}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<h1 class="font-bold text-lg">
|
||||||
|
{data.user.person_view.person.name}
|
||||||
|
</h1>
|
||||||
|
{#if data.user.person_view.person.bio}
|
||||||
|
<SvelteMarkdown source={data.user.person_view.person.bio} />
|
||||||
|
{/if}
|
||||||
|
</StickyCard>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { authData, getClient } from '$lib/lemmy.js'
|
||||||
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
|
export function load({ params }) {
|
||||||
|
return {
|
||||||
|
user: getClient().getPersonDetails({
|
||||||
|
limit: 40,
|
||||||
|
page: 1,
|
||||||
|
username: params.name,
|
||||||
|
sort: 'New',
|
||||||
|
auth: get(authData)?.token,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user