design: use entityheaders for instance and community cards

This commit is contained in:
Xylight committed 2025-11-02 17:00:30 -08:00
1 parent 4a18cdb63a
commit 9ec5bb853a
8 files changed
+161 -122

No files matched your search

+3
View File
@@ -547,6 +547,9 @@
"hide": "Hide",
"unhide": "Unhide",
"share": "Share",
"share.from": "Share from",
"share.global": "Origin server",
"share.local": "Your server",
"crosspost": "Crosspost",
"delete": "Delete",
"restore": "Restore"
+13 -18
View File
@@ -7,8 +7,6 @@
import Markdown from '$lib/app/markdown/Markdown.svelte'
import { settings } from '$lib/app/settings.svelte'
import { fullCommunityName, userLink } from '$lib/app/util.svelte'
import Avatar from '$lib/ui/generic/Avatar.svelte'
import Entity from '$lib/ui/generic/Entity.svelte'
import ItemList from '$lib/ui/generic/ItemList.svelte'
import LabelStat from '$lib/ui/info/LabelStat.svelte'
import EndPlaceholder from '$lib/ui/layout/EndPlaceholder.svelte'
@@ -108,6 +106,8 @@
</script>
<script lang="ts">
import EntityHeader from '$lib/ui/generic/EntityHeader.svelte'
let loading = $state({
blocking: false,
subscribing: false,
@@ -170,24 +170,19 @@
clazz,
]}
>
<div class="px-3 overflow-hidden">
<Entity
name={community_view.community.title}
label="!{fullCommunityName(
<EntityHeader
name={community_view.community.title}
avatar={community_view.community.icon}
banner={community_view.community.banner}
avatarCircle={false}
>
{#snippet nameDetail()}
!{fullCommunityName(
community_view.community.name,
community_view.community.actor_id,
)}"
>
{#snippet customIcon()}
<Avatar
width={32}
url={community_view.community.icon}
alt={community_view.community.name}
circle={false}
/>
{/snippet}
</Entity>
</div>
)}
{/snippet}
</EntityHeader>
<EndPlaceholder size="xs" margin="sm">
{$t('form.post.community')}
+37 -22
View File
@@ -4,12 +4,12 @@
import Markdown from '$lib/app/markdown/Markdown.svelte'
import { settings } from '$lib/app/settings.svelte'
import { userLink } from '$lib/app/util.svelte'
import Avatar from '$lib/ui/generic/Avatar.svelte'
import EntityHeader from '$lib/ui/generic/EntityHeader.svelte'
import ItemList from '$lib/ui/generic/ItemList.svelte'
import LabelStat from '$lib/ui/info/LabelStat.svelte'
import EndPlaceholder from '$lib/ui/layout/EndPlaceholder.svelte'
import SidebarButton from '$lib/ui/sidebar/SidebarButton.svelte'
import { Badge, Expandable } from 'mono-svelte'
import { Badge, Expandable, Popover } from 'mono-svelte'
import {
BuildingOffice,
Icon,
@@ -17,7 +17,6 @@
ServerStack,
} from 'svelte-hero-icons/dist'
import type { ClassValue, HTMLAttributes } from 'svelte/elements'
import { optimizeImageURL } from '../post'
interface Props extends HTMLAttributes<HTMLDivElement> {
site: SiteView
@@ -36,20 +35,13 @@
clazz,
]}
>
{#if site.site.banner}
<div class="rounded-xl bg-slate-100 dark:bg-zinc-925">
<img
src={optimizeImageURL(site.site.banner, 512)}
alt="Site banner"
class="h-32 object-cover w-full"
style="border-radius: inherit;"
/>
</div>
{/if}
<div class="mx-3 space-y-3">
<Avatar width={32} url={site.site.icon} alt="" circle={false} />
<h2 class="font-medium text-lg -my-2">{site.site.name}</h2>
</div>
<EntityHeader
name={site.site.name}
avatar={site.site.icon}
banner={site.site.banner}
compact="always"
avatarCircle={false}
/>
<div class="flex flex-col gap-1">
{#if taglines && taglines.length > 0}
<Markdown
@@ -96,11 +88,34 @@
content={site.counts.comments.toString()}
formatted
/>
<LabelStat
label={$t('cards.community.activeDay')}
content={site.counts.users_active_day.toString()}
formatted
/>
<Popover openOnHover placement="bottom-end">
{#snippet target(attachment)}
<button class="text-left cursor-pointer" {@attach attachment}>
<LabelStat
label={$t('cards.community.activeDay')}
content={site.counts.users_active_day.toString()}
formatted
/>
</button>
{/snippet}
<div class="flex flex-row gap-4 flex-wrap px-3">
<LabelStat
label={$t('filter.sort.top.time.week')}
content={site.counts.users_active_week.toString()}
formatted
/>
<LabelStat
label={$t('filter.sort.top.time.month')}
content={site.counts.users_active_month.toString()}
formatted
/>
<LabelStat
label={$t('filter.sort.top.time.6months')}
content={site.counts.users_active_half_year.toString()}
formatted
/>
</div>
</Popover>
<LabelStat
label={$t('content.communities')}
content={site.counts.communities.toString()}
+2 -2
View File
@@ -93,7 +93,7 @@
onclick={() => castVote(vote == targetNum ? 0 : targetNum)}
class={[
'flex items-center gap-0.5 transition-colors relative cursor-pointer h-full p-2 active:brightness-90',
'first:rounded-l-3xl last:rounded-r-3xl',
'first:rounded-l-[inherit] last:rounded-r-[inherit]',
'last:flex-row-reverse',
vote == targetNum
? shouldShowVoteColor(
@@ -137,7 +137,7 @@
<div
class={[
buttonColor.ghost,
'rounded-3xl h-full font-medium flex relative hover:bg-transparent!',
'rounded-full h-full font-medium flex relative hover:bg-transparent!',
voteRatio < 85 && settings.voteRatioBar && 'vote-ratio',
]}
aria-label={$t('aria.vote.group')}
@@ -3,10 +3,19 @@
import { profile } from '$lib/app/auth.svelte'
import { t } from '$lib/app/i18n'
import { settings, type View } from '$lib/app/settings.svelte'
import { instanceToURL } from '$lib/app/util.svelte'
import { save } from '$lib/feature/legacy/contentview'
import { publishedToDate } from '$lib/ui/util/date'
import FormattedNumber from '$lib/ui/util/FormattedNumber.svelte'
import { Button, Menu, Modal, Spinner } from 'mono-svelte'
import {
Button,
Menu,
MenuButton,
MenuDivider,
Modal,
Spinner,
toast,
} from 'mono-svelte'
import {
Bookmark,
BookmarkSlash,
@@ -14,7 +23,10 @@
ChatBubbleOvalLeft,
ChatBubbleOvalLeftEllipsis,
EllipsisHorizontal,
GlobeAlt,
Icon,
MapPin,
Share,
ShieldCheck,
} from 'svelte-hero-icons/dist'
import { PostVote } from '..'
@@ -42,6 +54,21 @@
}: Props = $props()
let buttonHeight = $derived(view == 'compact' ? 'h-7.5' : 'h-8')
let buttonSquare = $derived(view == 'compact' ? 'w-7.5 h-7.5' : 'w-8 h-8')
function share(global: boolean = true) {
const link = global
? post.post.ap_id
: `${instanceToURL(profile.current.instance)}/post/${post.post.id}`
if (navigator.share)
navigator.share?.({
url: link,
})
else {
navigator.clipboard.writeText(link)
toast({ content: $t('toast.copied') })
}
}
</script>
{#if editing}
@@ -116,6 +143,7 @@
<FormattedNumber number={post.counts.comments} />
</Button>
<div class="flex-1"></div>
{#if settings.debugInfo}
{#if debug}
{#await import('$lib/ui/util/debug/DebugObject.svelte') then { default: DebugObject }}
@@ -170,6 +198,30 @@
></Button>
{/if}
<Menu placement="bottom-end">
{#snippet target(attachment)}
<Button
{@attach post.post.local ? () => {} : attachment}
rounding="pill"
color="ghost"
size="custom"
class={buttonSquare}
onclick={() => {
if (post.post.local) share()
}}
icon={Share}
title={$t('post.actions.more.share')}
/>
{/snippet}
<MenuDivider showLabel>{$t('post.actions.more.share.from')}</MenuDivider>
<MenuButton onclick={() => share(true)} icon={GlobeAlt}>
{$t('post.actions.more.share.global')}
</MenuButton>
<MenuButton onclick={() => share(false)} icon={MapPin}>
{$t('post.actions.more.share.local')}
</MenuButton>
</Menu>
<Menu placement="bottom-end">
{#snippet target(popover)}
<Button
@@ -7,20 +7,15 @@
import { t } from '$lib/app/i18n'
import { setSessionStorage } from '$lib/app/session'
import { settings } from '$lib/app/settings.svelte'
import { instanceToURL } from '$lib/app/util.svelte'
import { deleteItem, markAsRead } from '$lib/feature/legacy/contentview'
import { report } from '$lib/feature/moderation/moderation'
import { Button, Menu, MenuButton, toast } from 'mono-svelte'
import { MenuButton } from 'mono-svelte'
import {
ArrowTopRightOnSquare,
EllipsisHorizontal,
Eye,
EyeSlash,
Flag,
GlobeAlt,
MapPin,
PencilSquare,
Share,
Trash,
XMark,
} from 'svelte-hero-icons/dist'
@@ -33,21 +28,6 @@
}
let { post = $bindable(), onhide, editing = $bindable() }: Props = $props()
function share(global: boolean = true) {
const link = global
? post.post.ap_id
: `${instanceToURL(profile.current.instance)}/post/${post.post.id}`
if (navigator.share)
navigator.share?.({
url: link,
})
else {
navigator.clipboard.writeText(link)
toast({ content: $t('toast.copied') })
}
}
</script>
{#if profile.current?.user && profile.current?.jwt && profile.current.user.local_user_view.person.id == post.creator.id}
@@ -68,36 +48,6 @@
: $t('post.actions.more.markRead')}
</MenuButton>
{/if}
<div class="flex flex-row">
<MenuButton
onclick={() => share()}
class={['flex-1', !post.post.local && 'rounded-r-lg']}
icon={Share}
>
{$t('post.actions.more.share')}
</MenuButton>
{#if !post.post.local}
<Menu>
{#snippet target(attachment)}
<Button
{@attach attachment}
aria-label={$t('post.actions.more.label')}
color="tertiary"
size="custom"
class="w-6 h-6 self-center"
data-autoclose="false"
icon={EllipsisHorizontal}
></Button>
{/snippet}
<MenuButton onclick={() => share(true)} icon={GlobeAlt}>
{$t('filter.location.global')}
</MenuButton>
<MenuButton onclick={() => share(false)} icon={MapPin}>
{$t('filter.location.local')}
</MenuButton>
</Menu>
{/if}
</div>
{#if profile.current?.jwt}
<MenuButton
onclick={() => {
+39 -24
View File
@@ -3,6 +3,7 @@
import { Material } from 'mono-svelte'
import type { ClassValue } from 'svelte/elements'
import LabelStat from '../info/LabelStat.svelte'
import TextProps from '../text/TextProps.svelte'
import Avatar from './Avatar.svelte'
import Blobs from './Blobs.svelte'
@@ -14,7 +15,7 @@
url?: string | undefined
stats?: {
name: string
value: string
value: string | number
format?: boolean
}[]
class?: ClassValue
@@ -42,55 +43,69 @@
}: Props = $props()
</script>
<div {...rest} class={['z-10 text-sm contents w-full space-y-4', clazz]}>
<Material padding="xl" rounding="3xl" class="flex flex-col gap-4">
<div {...rest} class={['z-10 text-sm w-full space-y-4 @container', clazz]}>
<Material padding="xl" rounding="3xl" class="flex flex-col gap-2 @lg:gap-4">
<div
class="relative overflow-hidden rounded-t-[inherit] -m-6 mask-b-from-0"
class="relative overflow-hidden rounded-t-[inherit] -m-6 mask-b-from-0 h-32 @lg:h-48"
>
{#if banner}
<img
src={banner}
class="w-full object-cover h-48 bg-white dark:bg-zinc-900"
class="w-full object-cover h-full bg-white dark:bg-zinc-900"
height="192"
alt="User banner"
/>
{:else}
<div class="scale-150">
<div class="scale-150 h-full">
<Blobs seed={name} />
</div>
{/if}
</div>
<Avatar
width={72}
url={avatar}
alt={name}
circle={avatarCircle}
class={[
'ring-slate-25 bg-slate-25 dark:bg-zinc-925 ring-6 relative dark:ring-zinc-950',
'-mt-8',
!avatarCircle && 'rounded-3xl!',
]}
/>
{#snippet icon(width: number)}
<Avatar
{width}
url={avatar}
alt={name}
circle={avatarCircle}
class={[
'ring-slate-25 bg-slate-25 dark:bg-zinc-925 ring-2 relative dark:ring-zinc-950',
'-mt-8',
!avatarCircle && 'rounded-xl @md:rounded-3xl!',
]}
/>
{/snippet}
<div class="contents @md:hidden">
{@render icon(48)}
</div>
<div class="hidden @md:contents">
{@render icon(72)}
</div>
<div class="space-y-1">
<svelte:element
this={url ? 'a' : 'h1'}
href={url}
class="text-2xl font-medium tracking-tight {url
class="text-xl @md:text-2xl font-medium tracking-tight {url
? 'hover:underline hover:text-primary-900 dark:hover:text-primary-100'
: ''}"
>
{name}
</svelte:element>
<p
class="flex items-center gap-0 text-sm text-slate-600 dark:text-zinc-400 max-w-full w-max"
>
{@render nameDetail?.()}
</p>
{#if nameDetail}
<p
class="flex items-center gap-0 text-sm text-slate-600 dark:text-zinc-400 max-w-full w-max"
>
<TextProps wrap="no-wrap">
{@render nameDetail?.()}
</TextProps>
</p>
{/if}
</div>
</Material>
{#if actions || stats}
{#if actions || stats.length > 0}
<div class="space-y-4">
<div class="flex flex-col flex-1">
{#if actions}
+13 -4
View File
@@ -84,7 +84,8 @@
open = newOpen
}
const mouseLeave = () => openOnHover && toggle(false)
const mouseover = () => openOnHover && toggle(true)
const mouseleave = () => openOnHover && toggle(false)
const focus = () => openOnHover && toggle(true)
const focusout = () => openOnHover && toggle(false)
const click = () => {
@@ -112,7 +113,8 @@
}
}
e.addEventListener('mouseleave', mouseLeave)
e.addEventListener('mouseover', mouseover)
e.addEventListener('mouseleave', mouseleave)
e.addEventListener('focus', focus)
e.addEventListener('focusout', focusout)
e.addEventListener('click', click)
@@ -121,7 +123,8 @@
floatingRef(e)
return () => {
e.removeEventListener('mouseleave', mouseLeave)
e.addEventListener('mouseover', mouseover)
e.removeEventListener('mouseleave', mouseleave)
e.removeEventListener('focus', focus)
e.removeEventListener('focusout', focusout)
e.removeEventListener('click', click)
@@ -149,7 +152,13 @@
{#if popover}
{@render popover(open)}
{:else}
<Material elevation="high" color="distinct" class="flex flex-col">
<Material
elevation="high"
color="distinct"
rounding="xl"
padding="sm"
class="flex flex-col"
>
{@render children?.(open)}
</Material>
{/if}