misc: add subscribe button to postmeta
This commit is contained in:
1 parent
4383ba3ae5
commit
0ac6dc6e36
4 files changed
+46
-8
No files matched your search
@@ -1,23 +1,27 @@
|
||||
<script lang="ts">
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type { CommunityView } from 'lemmy-js-client'
|
||||
import type { CommunityView, SubscribedType } from 'lemmy-js-client'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { toast } from 'mono-svelte'
|
||||
|
||||
export let community: CommunityView
|
||||
export let community: CommunityView | undefined = undefined
|
||||
|
||||
let subscribing = false
|
||||
|
||||
async function subscribe() {
|
||||
async function subscribe(
|
||||
id: number | undefined = community?.community.id,
|
||||
subscribed: SubscribedType | undefined = community?.subscribed
|
||||
) {
|
||||
if (!$profile?.jwt) return
|
||||
if (!id || !subscribed) return
|
||||
|
||||
subscribing = true
|
||||
|
||||
try {
|
||||
const res = await getClient().followCommunity({
|
||||
auth: $profile.jwt,
|
||||
community_id: community.community.id,
|
||||
follow: community.subscribed == 'NotSubscribed',
|
||||
community_id: id,
|
||||
follow: subscribed == 'NotSubscribed',
|
||||
})
|
||||
|
||||
subscribing = false
|
||||
|
||||
@@ -141,6 +141,7 @@
|
||||
<PostMeta
|
||||
community={post.post_view.community}
|
||||
user={post.post_view.creator}
|
||||
bind:subscribed={post.community_view.subscribed}
|
||||
upvotes={post.post_view.counts.upvotes}
|
||||
downvotes={post.post_view.counts.downvotes}
|
||||
deleted={post.post_view.post.deleted}
|
||||
|
||||
Reference in new issue
Block a user