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
@@ -41,7 +41,7 @@
|
|||||||
delay: index < 4 ? index * 100 : 0,
|
delay: index < 4 ? index * 100 : 0,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Post view={$userSettings.view} {post} />
|
<Post view={$userSettings.view} bind:post />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@@ -4,17 +4,23 @@
|
|||||||
import { Badge } from 'mono-svelte'
|
import { Badge } from 'mono-svelte'
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import RelativeDate from '$lib/components/util/RelativeDate.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 {
|
import {
|
||||||
Bookmark,
|
Bookmark,
|
||||||
|
Check,
|
||||||
Icon,
|
Icon,
|
||||||
LockClosed,
|
LockClosed,
|
||||||
Megaphone,
|
Megaphone,
|
||||||
|
Plus,
|
||||||
Trash,
|
Trash,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { getInstance } from '$lib/lemmy.js'
|
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 community: Community | undefined = undefined
|
||||||
|
export let subscribed: SubscribedType | undefined = undefined
|
||||||
|
|
||||||
export let user: Person | undefined = undefined
|
export let user: Person | undefined = undefined
|
||||||
export let published: Date | undefined = undefined
|
export let published: Date | undefined = undefined
|
||||||
export let title: string | undefined = undefined
|
export let title: string | undefined = undefined
|
||||||
@@ -36,7 +42,34 @@
|
|||||||
<div class="flex flex-col gap-1 w-full">
|
<div class="flex flex-col gap-1 w-full">
|
||||||
<span class="flex flex-row gap-2 text-sm items-center">
|
<span class="flex flex-row gap-2 text-sm items-center">
|
||||||
{#if community}
|
{#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}
|
{/if}
|
||||||
<div class="flex flex-col text-xs">
|
<div class="flex flex-col text-xs">
|
||||||
{#if community}
|
{#if community}
|
||||||
|
|||||||
@@ -1,23 +1,27 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getClient } from '$lib/lemmy.js'
|
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 { profile } from '$lib/auth.js'
|
||||||
import { toast } from 'mono-svelte'
|
import { toast } from 'mono-svelte'
|
||||||
|
|
||||||
export let community: CommunityView
|
export let community: CommunityView | undefined = undefined
|
||||||
|
|
||||||
let subscribing = false
|
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 (!$profile?.jwt) return
|
||||||
|
if (!id || !subscribed) return
|
||||||
|
|
||||||
subscribing = true
|
subscribing = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getClient().followCommunity({
|
const res = await getClient().followCommunity({
|
||||||
auth: $profile.jwt,
|
auth: $profile.jwt,
|
||||||
community_id: community.community.id,
|
community_id: id,
|
||||||
follow: community.subscribed == 'NotSubscribed',
|
follow: subscribed == 'NotSubscribed',
|
||||||
})
|
})
|
||||||
|
|
||||||
subscribing = false
|
subscribing = false
|
||||||
|
|||||||
@@ -141,6 +141,7 @@
|
|||||||
<PostMeta
|
<PostMeta
|
||||||
community={post.post_view.community}
|
community={post.post_view.community}
|
||||||
user={post.post_view.creator}
|
user={post.post_view.creator}
|
||||||
|
bind:subscribed={post.community_view.subscribed}
|
||||||
upvotes={post.post_view.counts.upvotes}
|
upvotes={post.post_view.counts.upvotes}
|
||||||
downvotes={post.post_view.counts.downvotes}
|
downvotes={post.post_view.counts.downvotes}
|
||||||
deleted={post.post_view.post.deleted}
|
deleted={post.post_view.post.deleted}
|
||||||
|
|||||||
Reference in new issue
Block a user