feat: Add community list
This commit is contained in:
1 parent
633dc33714
commit
89bd20b8d0
5 files changed
+142
-42
No files matched your search
@@ -1,21 +1,21 @@
|
||||
<script lang="ts">
|
||||
import type { GetCommunityResponse } from 'lemmy-js-client'
|
||||
import type { GetCommunityResponse } from 'lemmy-js-client'
|
||||
import Avatar from '../../post/[id]/Avatar.svelte'
|
||||
|
||||
export let data: GetCommunityResponse
|
||||
export let data: GetCommunityResponse
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex flex-row gap-4 items-center">
|
||||
<img
|
||||
src={data.community_view.community.icon}
|
||||
alt="test"
|
||||
class="rounded-full bg-white border-slate-200 border p-2"
|
||||
width={64}
|
||||
height={64}
|
||||
/>
|
||||
<h1 class="font-bold text-xl">
|
||||
{data.community_view.community.name}
|
||||
</h1>
|
||||
</div>
|
||||
<slot />
|
||||
<div class="flex flex-row gap-4 items-center">
|
||||
<Avatar
|
||||
url={data.community_view.community.icon ??
|
||||
`https://api.dicebear.com/6.x/initials/svg?seed=${data.community_view.community.name}`}
|
||||
alt={data.community_view.community.title}
|
||||
width={64}
|
||||
/>
|
||||
<h1 class="font-bold text-xl">
|
||||
{data.community_view.community.name}
|
||||
</h1>
|
||||
</div>
|
||||
<slot />
|
||||
</div>
|
||||
@@ -0,0 +1,14 @@
|
||||
import { lemmy } from '$lib/lemmy.js'
|
||||
import type { ListingType } from 'lemmy-js-client'
|
||||
|
||||
export function load(req) {
|
||||
const type = req.url.searchParams.get('listingType') as ListingType
|
||||
const page = Number(req.url.searchParams.get('page')) || 1
|
||||
|
||||
return lemmy.listCommunities({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: 'Active',
|
||||
type_: type,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import MultiSelect from '$lib/components/MultiSelect.svelte'
|
||||
import { page } from '$app/stores'
|
||||
import {
|
||||
ChatBubbleLeftEllipsis,
|
||||
ChatBubbleOvalLeftEllipsis,
|
||||
Icon,
|
||||
PencilSquare,
|
||||
UserGroup,
|
||||
} from 'svelte-hero-icons'
|
||||
import CommunityLink from '$lib/components/CommunityLink.svelte'
|
||||
|
||||
export let data
|
||||
</script>
|
||||
|
||||
<MultiSelect
|
||||
options={['Subscribed', 'Local', 'All']}
|
||||
selected={$page.url.searchParams.get('type') ?? 'Local'}
|
||||
on:select={(e) => {
|
||||
const url = $page.url
|
||||
url.searchParams.set('type', e.detail)
|
||||
url.searchParams.delete('page')
|
||||
goto(url, {
|
||||
invalidateAll: true,
|
||||
})
|
||||
}}
|
||||
/>
|
||||
|
||||
<ul class="flex flex-col">
|
||||
{#each data.communities as community}
|
||||
<li>
|
||||
<div
|
||||
class="py-4 border-b border-black/20 dark:border-white/20
|
||||
flex flex-col gap-1 text-sm"
|
||||
>
|
||||
<span
|
||||
class="break-words max-w-full w-max text-base font-bold text-sky-400 hover:underline"
|
||||
>
|
||||
<CommunityLink community={community.community} />
|
||||
</span>
|
||||
{#if !community.community.local}
|
||||
<span class="opacity-80">
|
||||
{new URL(community.community.actor_id).hostname}
|
||||
</span>
|
||||
{/if}
|
||||
<div class="flex flex-row gap-3 items-center mt-2">
|
||||
<div class="flex flex-row gap-1 items-center">
|
||||
<Icon src={UserGroup} width={16} mini />
|
||||
<span>
|
||||
{Intl.NumberFormat('en', { notation: 'compact' }).format(
|
||||
community.counts.subscribers
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex flex-row gap-1 items-center">
|
||||
<Icon src={PencilSquare} mini width={16} />
|
||||
<span>
|
||||
{Intl.NumberFormat('en', { notation: 'compact' }).format(
|
||||
community.counts.posts
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex flex-row gap-1 items-center">
|
||||
<Icon src={ChatBubbleOvalLeftEllipsis} mini width={16} />
|
||||
<span>
|
||||
{Intl.NumberFormat('en', { notation: 'compact' }).format(
|
||||
community.counts.comments
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
@@ -68,7 +68,11 @@
|
||||
<button aria-label="Upvote" class="p-1 px-1.5">
|
||||
<Icon src={ChevronUp} mini width={20} height={20} />
|
||||
</button>
|
||||
<span class="text-sm">{postRes.counts.score}</span>
|
||||
<span class="text-sm">
|
||||
{Intl.NumberFormat('en', { notation: 'compact' }).format(
|
||||
postRes.counts.score
|
||||
)}
|
||||
</span>
|
||||
<button aria-label="Downvote" class="p-1 px-1.5">
|
||||
<Icon src={ChevronDown} mini width={20} height="20}" />
|
||||
</button>
|
||||
@@ -80,7 +84,11 @@
|
||||
href="/post/{postRes.post.id}"
|
||||
>
|
||||
<Icon src={ChatBubbleLeft} width={16} height={16} />
|
||||
<span class="text-sm">{postRes.counts.comments}</span>
|
||||
<span class="text-sm">
|
||||
{Intl.NumberFormat('en', { notation: 'compact' }).format(
|
||||
postRes.counts.comments
|
||||
)}
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
Reference in new issue
Block a user