design: improve communities page

This commit is contained in:
Xylight committed 2024-08-17 18:35:10 -07:00
1 parent e8f5d743d8
commit f54c444fe6
6 files changed
+224 -82

No files matched your search

@@ -24,32 +24,62 @@
import Entity from '$lib/components/ui/Entity.svelte'
export let community: CommunityView
export let view: 'cozy' | 'compact' = 'compact'
export let showCounts: boolean = true
let showInfo = false
</script>
{#if showInfo}
<Modal title={$t('routes.community.title')} bind:open={showInfo}>
<Modal title={$t('form.post.community')} bind:open={showInfo}>
<CommunityCard community_view={community} />
</Modal>
{/if}
<div class="py-4 flex flex-col gap-2 text-sm max-w-full relative">
<div class="flex flex-row items-center max-w-full w-full">
<div
class={$$props.class ??
'py-4 flex flex-col gap-4 text-sm max-w-full relative'}
>
<div
class="flex
{view == 'cozy'
? 'flex-col gap-2'
: 'flex-row'} items-center max-w-full w-full"
>
<a
href="/c/{fullCommunityName(
community.community.name,
community.community.actor_id
)}"
class="hover:underline"
class="flex-1"
>
<Entity
icon={community.community.icon}
label={new URL(community.community.actor_id).hostname}
name={community.community.title}
></Entity>
<div
class="flex {view == 'cozy'
? 'flex-col gap-2'
: 'flex-row'} gap-2 items-center"
>
<slot name="icon">
<Avatar
url={community.community.icon}
width={32}
alt={community.community.name}
/>
</slot>
<div class="flex flex-col">
<div class="font-medium text-base">
{community.community.title}
</div>
<div class="text-sm text-slate-600 dark:text-zinc-400">
<span>{new URL(community.community.actor_id).hostname}</span>
{#if !showCounts}
•
<FormattedNumber number={community.counts.subscribers} />
{/if}
</div>
</div>
</div>
</a>
<div class="ml-auto flex flex-row items-center gap-2">
<div class="flex flex-row items-center gap-2">
<Button size="square-md" on:click={() => (showInfo = !showInfo)}>
<Icon src={InformationCircle} size="16" micro />
</Button>
@@ -93,8 +123,8 @@
</Subscribe>
</div>
</div>
{#if community.counts}
<div class="flex flex-row gap-3 items-center">
{#if showCounts}
<div class="flex flex-row gap-3 items-center justify-center">
{#if community.counts.posts}
<LabelStat
content={community.counts.posts.toString()}
+49 -17
View File
@@ -7,29 +7,61 @@
} from 'svelte-hero-icons'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import { userLink } from '$lib/lemmy/generic'
import Avatar from '$lib/components/ui/Avatar.svelte'
export let user: PersonView
export let view: 'cozy' | 'compact' = 'compact'
export let showCounts: boolean = true
</script>
<div
class="py-2
flex flex-col gap-3 text-sm max-w-full"
class={$$props.class ??
'py-4 flex flex-col gap-4 text-sm max-w-full relative'}
>
<div class="flex flex-row items-center">
<span
class="break-words max-w-full w-max text-base font-bold text-sky-400 hover:underline"
>
<UserLink avatar user={user.person} />
</span>
<div
class="flex
{view == 'cozy'
? 'flex-col gap-2'
: 'flex-row'} items-center max-w-full w-full"
>
<a href={userLink(user.person)} class="flex-1">
<div
class="flex {view == 'cozy'
? 'flex-col gap-2'
: 'flex-row'} gap-2 items-center"
>
<slot name="icon">
<Avatar url={user.person.avatar} width={32} alt={user.person.name} />
</slot>
<div class="flex flex-col">
<div class="font-medium text-base">
{user.person.display_name ?? user.person.name}
</div>
<div class="text-sm text-slate-600 dark:text-zinc-400">
{new URL(user.person.actor_id).hostname}
</div>
</div>
</div>
</a>
</div>
<div class="flex flex-row gap-3 items-center">
<div class="flex flex-row gap-1 items-center" title="Post count">
<Icon src={PencilSquare} mini width={16} />
<FormattedNumber number={user.counts.post_count} />
{#if showCounts}
<div class="flex flex-row gap-3 items-center justify-center">
{#if user.counts.post_count}
<LabelStat
content={user.counts.post_count.toString()}
formatted
label="Posts"
/>
{/if}
{#if user.counts.comment_count}
<LabelStat
content={user.counts.comment_count.toString()}
formatted
label="Comments"
/>
{/if}
</div>
<div class="flex flex-row gap-1 items-center" title="Comment count">
<Icon src={ChatBubbleOvalLeftEllipsis} mini width={16} />
<FormattedNumber number={user.counts.comment_count} />
</div>
</div>
{/if}
</div>
+3 -1
View File
@@ -226,7 +226,9 @@
"title": "No Results",
"description": "There are no results that match that filter. Try refining your search.",
"alt": "Search across the fediverse"
}
},
"top": "Top results",
"other": "Other results"
},
"saved": "Saved",
"createPost": "Create Post",
+70 -26
View File
@@ -16,6 +16,9 @@
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
import { t } from '$lib/translations.js'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
import { contentPadding } from '$lib/components/ui/layout/Shell.svelte'
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
export let data
@@ -55,35 +58,41 @@
</p>
</Material>
</Popover>
<form
on:submit|preventDefault={() => searchParam($page.url, 'q', search, 'page')}
class="flex gap-2 flex-row items-center"
slot="extended"
>
<TextInput
bind:value={search}
aria-label={$t('routes.search.query')}
size="md"
class="flex-1"
/>
<Button
submit
color="secondary"
size="custom"
class="self-end"
style="width: 38px; height: 38px;"
title="Search"
>
<Icon src={MagnifyingGlass} size="16" mini />
</Button>
</form>
</Header>
<div
class="mt-4 mb-0 sticky z-30"
style="top: max(1.5rem, {$contentPadding.top}px);"
>
<Tabs routes={[]} class="p-2 dark:bg-zinc-925/70">
<form
on:submit|preventDefault={() =>
searchParam($page.url, 'q', search, 'page')}
class="flex gap-2 flex-row items-center w-full text-base h-10"
>
<TextInput
bind:value={search}
aria-label={$t('routes.search.query')}
size="lg"
class="flex-1 !rounded-full h-full !text-base"
/>
<Button
submit
color="secondary"
size="custom"
class="flex-shrink-0 h-full aspect-square"
title="Search"
rounding="pill"
>
<Icon src={MagnifyingGlass} size="16" mini />
</Button>
</form>
</Tabs>
</div>
<div class="flex flex-row flex-wrap gap-4 mt-4 items-center">
<Location selected={data.type} />
<Sort selected={data.sort} />
</div>
<ul class="flex flex-col divide-y divide-slate-200 dark:divide-zinc-800">
<ul class="flex flex-col divide-y divide-slate-200 dark:divide-zinc-800 my-6">
{#if data.communities.length == 0}
<Placeholder
icon={QuestionMarkCircle}
@@ -91,8 +100,43 @@
description={$t('routes.search.noResults.description')}
/>
{/if}
{#each data.communities as community}
<CommunityItem {community} />
{#if (data.query ?? '' != '') && data.communities.length > 0}
<SectionTitle class="!border-0 pb-2">
{$t('routes.search.top')}
</SectionTitle>
<div
class="grid md:grid-cols-2 lg:grid-cols-3 gap-4 items-center mb-6 !border-0"
>
{#each data.communities.slice(0, 3) as community}
<Material
color="distinct"
padding="none"
rounding="xl"
class="dark:border-t-zinc-800 h-full"
>
<CommunityItem
{community}
showCounts={false}
class="w-full p-4 text-center"
view="cozy"
/>
</Material>
{/each}
</div>
{/if}
{#if data.communities.slice(data.query ?? '' != '' ? 3 : 0).length > 0}
<SectionTitle class="!border-0 pb-2">
{$t('routes.search.other')}
</SectionTitle>
{/if}
{#each data.communities.slice(data.query ?? '' != '' ? 3 : 0) as community}
<div
class="-mx-4 sm:-mx-6 px-6 hover:bg-slate-100 hover:dark:bg-zinc-800 transition-colors"
>
<CommunityItem {community} showCounts={false} class="py-3" />
</div>
{/each}
</ul>
{#if data.communities.length > 0}
+50 -25
View File
@@ -35,6 +35,8 @@
import { slide } from 'svelte/transition'
import { t } from '$lib/translations.js'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
import { contentPadding } from '$lib/components/ui/layout/Shell.svelte'
type Result = PostView | CommentView | PersonView | CommunityView
@@ -53,29 +55,36 @@
<Header pageHeader>
{$t('routes.search.title')}
<form
on:submit|preventDefault={() => searchParam($page.url, 'q', query, 'page')}
class="flex flex-row gap-2 items-center"
slot="extended"
>
<TextInput
bind:value={query}
aria-label={$t('routes.search.query')}
size="md"
class="flex-1 rounded-lg"
/>
<Button
submit
color="secondary"
size="custom"
class="self-end"
style="width: 38px; height: 38px;"
title="Search"
>
<Icon src={MagnifyingGlass} size="16" mini />
</Button>
</form>
</Header>
<div
class="mt-4 mb-0 sticky z-30"
style="top: max(1.5rem, {$contentPadding.top}px);"
>
<Tabs routes={[]} class="p-2 dark:bg-zinc-925/70">
<form
on:submit|preventDefault={() =>
searchParam($page.url, 'q', query, 'page')}
class="flex gap-2 flex-row items-center w-full text-base h-10"
>
<TextInput
bind:value={query}
aria-label={$t('routes.search.query')}
size="lg"
class="flex-1 !rounded-full h-full !text-base"
/>
<Button
submit
color="secondary"
size="custom"
class="flex-shrink-0 h-full aspect-square"
title="Search"
rounding="pill"
>
<Icon src={MagnifyingGlass} size="16" mini />
</Button>
</form>
</Tabs>
</div>
<div class="flex flex-row flex-wrap items-center gap-4 mt-4">
<Select
bind:value={data.type}
@@ -136,7 +145,15 @@
{#if object}
<div transition:slide={{ axis: 'y', easing: expoOut }}>
{#if object.community}
<CommunityItem community={object.community} />
<div
class="-mx-4 sm:-mx-6 px-6 hover:bg-slate-100 hover:dark:bg-zinc-800 transition-colors"
>
<CommunityItem
community={object.community}
showCounts={false}
class="py-3"
/>
</div>
{/if}
{#if object.post}
<Post post={object.post} />
@@ -161,9 +178,17 @@
{:else if isCommentView(result)}
<CommentItem comment={result} />
{:else if isCommunityView(result)}
<CommunityItem community={result} />
<div
class="-mx-4 sm:-mx-6 px-6 hover:bg-slate-100 hover:dark:bg-zinc-800 transition-colors"
>
<CommunityItem community={result} showCounts={false} class="py-3" />
</div>
{:else if isUser(result)}
<UserItem user={result} />
<div
class="-mx-4 sm:-mx-6 px-6 hover:bg-slate-100 hover:dark:bg-zinc-800 transition-colors"
>
<UserItem user={result} showCounts={false} class="py-3" />
</div>
{/if}
{/each}
</div>
+10 -1
View File
@@ -19,7 +19,8 @@ export async function load({ url, fetch }) {
const community = Number(url.searchParams.get('community')) || undefined
const sort = url.searchParams.get('sort') || 'New'
const type = url.searchParams.get('type') || 'All'
const listing_type = url.searchParams.get('listing_type') as ListingType || 'All'
const listing_type =
(url.searchParams.get('listing_type') as ListingType) || 'All'
if (query) {
const results = await client({ func: fetch }).search({
@@ -41,6 +42,14 @@ export async function load({ url, fetch }) {
const everything = [...posts, ...comments, ...users, ...communities]
if (sort == 'New') {
everything.sort(
(a, b) =>
new Date(getItemPublished(b)).getTime() -
new Date(getItemPublished(a)).getTime()
)
}
return {
type: type,
sort: sort,