feat: Add user pages
This commit is contained in:
1 parent
04704749b7
commit
9efe1df0c2
12 files changed
+222
-29
No files matched your search
@@ -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} />
|
||||
Reference in new issue
Block a user