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">
|
<script lang="ts">
|
||||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||||
import Avatar from '$lib/components/ui/Avatar.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 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, SubscribedType } from 'lemmy-js-client'
|
import type { Community, Person, SubscribedType } from 'lemmy-js-client'
|
||||||
@@ -64,6 +64,7 @@
|
|||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { Pencil, type IconSource } from 'svelte-hero-icons'
|
import { Pencil, type IconSource } from 'svelte-hero-icons'
|
||||||
|
import CommunityHeader from '../community/CommunityHeader.svelte'
|
||||||
|
|
||||||
export let community: Community | undefined = undefined
|
export let community: Community | undefined = undefined
|
||||||
export let showCommunity: boolean = true
|
export let showCommunity: boolean = true
|
||||||
@@ -111,41 +112,29 @@
|
|||||||
: 'grid-rows-1'} text-xs min-w-0 max-w-full"
|
: 'grid-rows-1'} text-xs min-w-0 max-w-full"
|
||||||
style={$$props.style ?? ''}
|
style={$$props.style ?? ''}
|
||||||
>
|
>
|
||||||
{#if showCommunity && community}
|
{#if showCommunity && community && subscribed}
|
||||||
<Subscribe let:subscribe let:subscribing>
|
<Popover>
|
||||||
<button
|
<div
|
||||||
on:click={async () => {
|
class="relative cursor-pointer pr-2 row-span-2 flex-shrink-0 group/community"
|
||||||
if (!community) return
|
slot="target"
|
||||||
await subscribe(community.id, subscribed)
|
|
||||||
subscribed =
|
|
||||||
subscribed == 'NotSubscribed' ? 'Subscribed' : 'NotSubscribed'
|
|
||||||
}}
|
|
||||||
class="relative cursor-pointer pr-2 row-span-2 flex-shrink-0"
|
|
||||||
>
|
>
|
||||||
<Avatar
|
<Avatar
|
||||||
url={community.icon}
|
url={community.icon}
|
||||||
width={32}
|
width={32}
|
||||||
alt={community.name}
|
alt={community.name}
|
||||||
style="grid-area: avatar; height: 100%;"
|
class="group-hover/community:ring-1 transition-all ring-offset-1 ring-primary-900 dark:ring-primary-100"
|
||||||
class="flex-shrink-0"
|
|
||||||
/>
|
/>
|
||||||
{#if subscribed != undefined && $profile?.jwt}
|
</div>
|
||||||
<div
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
class="absolute w-3.5 h-3.5 {subscribed == 'NotSubscribed'
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
? 'bg-primary-900 dark:bg-primary-100 text-white dark:text-black'
|
<div
|
||||||
: 'bg-primary-100 dark:bg-primary-900 text-black dark:text-white'} rounded-full ring-2 box-border
|
slot="popover"
|
||||||
ring-slate-50 dark:ring-zinc-950 grid place-items-center transition-all
|
class="max-w-md rounded-2xl bg-white dark:bg-zinc-950"
|
||||||
right-0 -translate-x-1 -translate-y-2"
|
on:click|stopPropagation={() => {}}
|
||||||
>
|
>
|
||||||
<Icon
|
<CommunityHeader bind:community bind:subscribed />
|
||||||
src={subscribed == 'NotSubscribed' ? Plus : Check}
|
</div>
|
||||||
micro
|
</Popover>
|
||||||
size="14"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</button>
|
|
||||||
</Subscribe>
|
|
||||||
{/if}
|
{/if}
|
||||||
{#if showCommunity && community}
|
{#if showCommunity && community}
|
||||||
<CommunityLink
|
<CommunityLink
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
{#if optimizedURLs[0] != undefined}
|
{#if optimizedURLs[0] != undefined}
|
||||||
<img
|
<img
|
||||||
|
{...$$restProps}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
srcset="{optimizedURLs[0]} 1x, {optimizedURLs[1]} 2x, {optimizedURLs[2]} 4x, {optimizedURLs[3]} 6x"
|
srcset="{optimizedURLs[0]} 1x, {optimizedURLs[1]} 2x, {optimizedURLs[2]} 4x, {optimizedURLs[3]} 6x"
|
||||||
src={optimizedURLs[0]}
|
src={optimizedURLs[0]}
|
||||||
@@ -49,7 +50,7 @@
|
|||||||
{width}
|
{width}
|
||||||
{title}
|
{title}
|
||||||
class="aspect-square object-cover overflow-hidden {$$props.class} flex-shrink-0"
|
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-full={circle}
|
||||||
class:rounded-md={!circle}
|
class:rounded-md={!circle}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||||
import Subscribe from '../../communities/Subscribe.svelte'
|
import Subscribe from '../../communities/Subscribe.svelte'
|
||||||
import { resumables } from '$lib/lemmy/item'
|
import { resumables } from '$lib/lemmy/item'
|
||||||
|
import CommunityHeader from '$lib/components/lemmy/community/CommunityHeader.svelte'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -77,105 +78,11 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="flex flex-col gap-4 max-w-full w-full min-w-0">
|
<div class="flex flex-col gap-4 max-w-full w-full min-w-0">
|
||||||
<EntityHeader
|
<CommunityHeader
|
||||||
banner={community.community.banner}
|
bind:community={community.community}
|
||||||
avatar={community.community.icon}
|
bind:subscribed={community.subscribed}
|
||||||
name={community.community.title}
|
counts={community.counts}
|
||||||
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>
|
|
||||||
<Sort selected={data.sort} />
|
<Sort selected={data.sort} />
|
||||||
{#if community.blocked}
|
{#if community.blocked}
|
||||||
<Placeholder
|
<Placeholder
|
||||||
|
|||||||
Reference in new issue
Block a user