feat: community preview in feeds
This commit is contained in:
1 parent
31d295747b
commit
87649204ba
4 files changed
+152
-130
No files matched your search
@@ -0,0 +1,125 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth'
|
||||
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
||||
|
||||
import { t } from '$lib/translations'
|
||||
import { fullCommunityName } from '$lib/util'
|
||||
import type {
|
||||
Community,
|
||||
CommunityAggregates,
|
||||
SubscribedType,
|
||||
} from 'lemmy-js-client'
|
||||
import { Button, toast } from 'mono-svelte'
|
||||
import {
|
||||
Check,
|
||||
Cog6Tooth,
|
||||
Icon,
|
||||
InformationCircle,
|
||||
Plus,
|
||||
} from 'svelte-hero-icons'
|
||||
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
|
||||
|
||||
export let community: Community
|
||||
export let subscribed: SubscribedType
|
||||
export let counts: CommunityAggregates | undefined = undefined
|
||||
</script>
|
||||
|
||||
<EntityHeader
|
||||
banner={community.banner}
|
||||
avatar={community.icon}
|
||||
name={community.title}
|
||||
stats={counts
|
||||
? [
|
||||
{
|
||||
name: $t('cards.community.members'),
|
||||
value: counts.subscribers.toString(),
|
||||
},
|
||||
{
|
||||
name: $t('content.posts'),
|
||||
value: counts.posts.toString(),
|
||||
},
|
||||
{
|
||||
name: $t('cards.community.activeDay'),
|
||||
value: counts.users_active_day.toString(),
|
||||
},
|
||||
]
|
||||
: []}
|
||||
bio={community.description}
|
||||
>
|
||||
<button
|
||||
on:click={() => {
|
||||
navigator?.clipboard?.writeText?.(
|
||||
`!${fullCommunityName(community.name, community.actor_id)}`
|
||||
)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
class="text-sm flex gap-0 items-center"
|
||||
slot="nameDetail"
|
||||
>
|
||||
!{fullCommunityName(community.name, community.actor_id)}
|
||||
</button>
|
||||
<div class="flex items-center gap-2 h-max">
|
||||
{#if $profile?.jwt}
|
||||
<Subscribe
|
||||
community={{
|
||||
community: community,
|
||||
banned_from_community: false,
|
||||
blocked: false,
|
||||
// @ts-ignore
|
||||
counts: counts ?? {},
|
||||
subscribed: subscribed,
|
||||
}}
|
||||
let:subscribe
|
||||
let:subscribing
|
||||
>
|
||||
<Button
|
||||
disabled={subscribing}
|
||||
loading={subscribing}
|
||||
size="lg"
|
||||
color={subscribed == 'NotSubscribed' ? 'primary' : 'secondary'}
|
||||
on:click={async () => {
|
||||
subscribed =
|
||||
(await subscribe())?.community_view.subscribed ?? 'NotSubscribed'
|
||||
}}
|
||||
class="flex-1 relative z-[inherit]"
|
||||
>
|
||||
<Icon
|
||||
src={subscribed != 'NotSubscribed' ? Check : Plus}
|
||||
micro
|
||||
size="16"
|
||||
slot="prefix"
|
||||
/>
|
||||
{subscribed == 'Subscribed' || subscribed == 'Pending'
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
</Button>
|
||||
</Subscribe>
|
||||
{/if}
|
||||
|
||||
<!-- <Button
|
||||
size="lg"
|
||||
color="secondary"
|
||||
class="flex-1"
|
||||
on:click={() => (sidebar = !sidebar)}
|
||||
>
|
||||
<Icon src={InformationCircle} size="16" micro />
|
||||
{$t('cards.site.about')}
|
||||
</Button> -->
|
||||
{#if $profile?.user && $profile.user.moderates
|
||||
.map((c) => c.community.id)
|
||||
.includes(community.id)}
|
||||
<Button
|
||||
size="square-lg"
|
||||
color="secondary"
|
||||
rounding="xl"
|
||||
href="/c/{fullCommunityName(
|
||||
community.name,
|
||||
community.actor_id
|
||||
)}/settings"
|
||||
style="height: 38px; width: 38px;"
|
||||
>
|
||||
<Icon src={Cog6Tooth} size="16" mini />
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
</EntityHeader>
|
||||
@@ -41,7 +41,7 @@
|
||||
<script lang="ts">
|
||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import { Badge } from 'mono-svelte'
|
||||
import { Badge, Material, Popover } from 'mono-svelte'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import type { Community, Person, SubscribedType } from 'lemmy-js-client'
|
||||
@@ -64,6 +64,7 @@
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { Pencil, type IconSource } from 'svelte-hero-icons'
|
||||
import CommunityHeader from '../community/CommunityHeader.svelte'
|
||||
|
||||
export let community: Community | undefined = undefined
|
||||
export let showCommunity: boolean = true
|
||||
@@ -111,41 +112,29 @@
|
||||
: 'grid-rows-1'} text-xs min-w-0 max-w-full"
|
||||
style={$$props.style ?? ''}
|
||||
>
|
||||
{#if showCommunity && community}
|
||||
<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 pr-2 row-span-2 flex-shrink-0"
|
||||
{#if showCommunity && community && subscribed}
|
||||
<Popover>
|
||||
<div
|
||||
class="relative cursor-pointer pr-2 row-span-2 flex-shrink-0 group/community"
|
||||
slot="target"
|
||||
>
|
||||
<Avatar
|
||||
url={community.icon}
|
||||
width={32}
|
||||
alt={community.name}
|
||||
style="grid-area: avatar; height: 100%;"
|
||||
class="flex-shrink-0"
|
||||
class="group-hover/community:ring-1 transition-all ring-offset-1 ring-primary-900 dark:ring-primary-100"
|
||||
/>
|
||||
{#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 grid place-items-center transition-all
|
||||
right-0 -translate-x-1 -translate-y-2"
|
||||
>
|
||||
<Icon
|
||||
src={subscribed == 'NotSubscribed' ? Plus : Check}
|
||||
micro
|
||||
size="14"
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
</button>
|
||||
</Subscribe>
|
||||
</div>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<div
|
||||
slot="popover"
|
||||
class="max-w-md rounded-2xl bg-white dark:bg-zinc-950"
|
||||
on:click|stopPropagation={() => {}}
|
||||
>
|
||||
<CommunityHeader bind:community bind:subscribed />
|
||||
</div>
|
||||
</Popover>
|
||||
{/if}
|
||||
{#if showCommunity && community}
|
||||
<CommunityLink
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
{#if optimizedURLs[0] != undefined}
|
||||
<img
|
||||
{...$$restProps}
|
||||
loading="lazy"
|
||||
srcset="{optimizedURLs[0]} 1x, {optimizedURLs[1]} 2x, {optimizedURLs[2]} 4x, {optimizedURLs[3]} 6x"
|
||||
src={optimizedURLs[0]}
|
||||
@@ -49,7 +50,7 @@
|
||||
{width}
|
||||
{title}
|
||||
class="aspect-square object-cover overflow-hidden {$$props.class} flex-shrink-0"
|
||||
style="width: {width}px; height: {width}px;"
|
||||
style="width: {width}px; height: {width}px; {$$props.style || undefined}"
|
||||
class:rounded-full={circle}
|
||||
class:rounded-md={!circle}
|
||||
/>
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||
import Subscribe from '../../communities/Subscribe.svelte'
|
||||
import { resumables } from '$lib/lemmy/item'
|
||||
import CommunityHeader from '$lib/components/lemmy/community/CommunityHeader.svelte'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -77,105 +78,11 @@
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-col gap-4 max-w-full w-full min-w-0">
|
||||
<EntityHeader
|
||||
banner={community.community.banner}
|
||||
avatar={community.community.icon}
|
||||
name={community.community.title}
|
||||
stats={[
|
||||
{
|
||||
name: $t('cards.community.members'),
|
||||
value: community.counts.subscribers.toString(),
|
||||
},
|
||||
{
|
||||
name: $t('content.posts'),
|
||||
value: community.counts.posts.toString(),
|
||||
},
|
||||
{
|
||||
name: $t('cards.community.activeDay'),
|
||||
value: community.counts.users_active_day.toString(),
|
||||
},
|
||||
]}
|
||||
bio={community.community.description}
|
||||
>
|
||||
<button
|
||||
on:click={() => {
|
||||
navigator?.clipboard?.writeText?.(
|
||||
`!${fullCommunityName(
|
||||
community.community.name,
|
||||
community.community.actor_id
|
||||
)}`
|
||||
)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
class="text-sm flex gap-0 items-center"
|
||||
slot="nameDetail"
|
||||
>
|
||||
!{fullCommunityName(
|
||||
community.community.name,
|
||||
community.community.actor_id
|
||||
)}
|
||||
</button>
|
||||
<div class="flex items-center gap-2 h-max">
|
||||
{#if $profile?.jwt}
|
||||
<Subscribe let:subscribe bind:community let:subscribing>
|
||||
<Button
|
||||
disabled={subscribing}
|
||||
loading={subscribing}
|
||||
size="lg"
|
||||
color={community.subscribed == 'NotSubscribed'
|
||||
? 'primary'
|
||||
: 'secondary'}
|
||||
on:click={async () => {
|
||||
community.subscribed =
|
||||
(await subscribe())?.community_view.subscribed ??
|
||||
'NotSubscribed'
|
||||
|
||||
if ($page.data.slots?.sidebar?.props.community_view)
|
||||
$page.data.slots.sidebar.props.community_view = community
|
||||
}}
|
||||
class="flex-1 relative z-[inherit]"
|
||||
>
|
||||
<Icon
|
||||
src={community.subscribed != 'NotSubscribed' ? Check : Plus}
|
||||
micro
|
||||
size="16"
|
||||
slot="prefix"
|
||||
/>
|
||||
{community.subscribed == 'Subscribed' ||
|
||||
community.subscribed == 'Pending'
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
</Button>
|
||||
</Subscribe>
|
||||
{/if}
|
||||
|
||||
<Button
|
||||
size="lg"
|
||||
color="secondary"
|
||||
class="flex-1"
|
||||
on:click={() => (sidebar = !sidebar)}
|
||||
>
|
||||
<Icon src={InformationCircle} size="16" micro />
|
||||
{$t('cards.site.about')}
|
||||
</Button>
|
||||
{#if $profile?.user && $profile.user.moderates
|
||||
.map((c) => c.community.id)
|
||||
.includes(community.community.id)}
|
||||
<Button
|
||||
size="square-lg"
|
||||
color="secondary"
|
||||
rounding="xl"
|
||||
href="/c/{fullCommunityName(
|
||||
community.community.name,
|
||||
community.community.actor_id
|
||||
)}/settings"
|
||||
style="height: 38px; width: 38px;"
|
||||
>
|
||||
<Icon src={Cog6Tooth} size="16" mini />
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
</EntityHeader>
|
||||
<CommunityHeader
|
||||
bind:community={community.community}
|
||||
bind:subscribed={community.subscribed}
|
||||
counts={community.counts}
|
||||
/>
|
||||
<Sort selected={data.sort} />
|
||||
{#if community.blocked}
|
||||
<Placeholder
|
||||
|
||||
Reference in new issue
Block a user