feat: Add user pages
This commit is contained in:
1 parent
04704749b7
commit
9efe1df0c2
12 files changed
+222
-29
No files matched your search
@@ -6,8 +6,8 @@
|
||||
<div class="flex flex-col mx-auto gap-4 justify-center items-center">
|
||||
<h1 class="font-black text-3xl">{$page.status}</h1>
|
||||
<p class="mx-4 md:mx-8">
|
||||
Failed to fetch page. The lemmy servers are having quite a lot of issues
|
||||
right now, this is likely on their end.
|
||||
Failed to fetch page. Most major lemmy instances are having quite a lot of
|
||||
issues right now, this might be on their end.
|
||||
</p>
|
||||
<code class="bg-slate-100 dark:bg-zinc-800 px-2 py-1 rounded-md">
|
||||
{JSON.stringify($page.error)}
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||
import Subscribe from './Subscribe.svelte'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -56,11 +58,39 @@
|
||||
class="py-4 border-b border-black/20 dark:border-white/20
|
||||
flex flex-col gap-1 text-sm"
|
||||
>
|
||||
<span
|
||||
class="break-words max-w-full w-max text-base font-bold text-sky-400 hover:underline"
|
||||
>
|
||||
<CommunityLink community={community.community} />
|
||||
</span>
|
||||
<div class="flex flex-row justify-between items-center">
|
||||
<span
|
||||
class="break-words max-w-full w-max text-base font-bold text-sky-400 hover:underline"
|
||||
>
|
||||
<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}
|
||||
<span class="opacity-80">
|
||||
{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 { page } from '$app/stores'
|
||||
import { onMount } from 'svelte'
|
||||
import UserLink from '$lib/components/user/UserLink.svelte'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -88,7 +89,7 @@
|
||||
<div class="flex flex-col gap-2">
|
||||
<span class="flex flex-row gap-2 text-sm opacity-80 items-center">
|
||||
<CommunityLink avatar community={postData.community} />
|
||||
<span class="opacity-50">{postData.creator.name}</span>
|
||||
<span class="opacity-50"><UserLink user={postData.creator} /></span>
|
||||
</span>
|
||||
<h1 class="font-bold text-lg">{post.name}</h1>
|
||||
{#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