misc: add subscribe button to postmeta

This commit is contained in:
Xyphyn committed 2023-09-19 16:46:46 -07:00
1 parent 4383ba3ae5
commit 0ac6dc6e36
4 files changed
+46 -8

No files matched your search

@@ -41,7 +41,7 @@
delay: index < 4 ? index * 100 : 0,
}}
>
<Post view={$userSettings.view} {post} />
<Post view={$userSettings.view} bind:post />
</div>
{/if}
{/each}
+35 -2
View File
@@ -4,17 +4,23 @@
import { Badge } from 'mono-svelte'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import type { Community, Person } from 'lemmy-js-client'
import type { Community, Person, SubscribedType } from 'lemmy-js-client'
import {
Bookmark,
Check,
Icon,
LockClosed,
Megaphone,
Plus,
Trash,
} from 'svelte-hero-icons'
import { getInstance } from '$lib/lemmy.js'
import { profile } from '$lib/auth.js'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
export let community: Community | undefined = undefined
export let subscribed: SubscribedType | undefined = undefined
export let user: Person | undefined = undefined
export let published: Date | undefined = undefined
export let title: string | undefined = undefined
@@ -36,7 +42,34 @@
<div class="flex flex-col gap-1 w-full">
<span class="flex flex-row gap-2 text-sm items-center">
{#if community}
<Avatar url={community.icon} width={24} alt={community.name} />
<Subscribe let:subscribe let:subscribing>
<button
on:click={async () => {
if (!community) return
await subscribe(community.id, subscribed)
subscribed =
subscribed == 'NotSubscribed' ? 'Subscribed' : 'NotSubscribed'
}}
class="relative cursor-pointer"
>
<Avatar url={community.icon} width={28} alt={community.name} />
{#if subscribed != undefined && $profile?.jwt}
<div
class="absolute w-3.5 h-3.5 {subscribed == 'NotSubscribed'
? 'bg-primary-900 dark:bg-primary-100 text-white dark:text-black'
: 'bg-primary-100 dark:bg-primary-900 text-black dark:text-white'} rounded-full ring-2 box-border
ring-slate-50 dark:ring-zinc-950
-bottom-1.5 -right-1.5 grid place-items-center transition-all"
>
<Icon
src={subscribed == 'NotSubscribed' ? Plus : Check}
mini
size="12"
/>
</div>
{/if}
</button>
</Subscribe>
{/if}
<div class="flex flex-col text-xs">
{#if community}
+9 -5
View File
@@ -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}