design: improve entityheader design

This commit is contained in:
Xylight committed 2024-09-08 14:48:03 -07:00
1 parent 23834137a7
commit 53ec967dce
8 files changed
+198 -141

No files matched your search

@@ -68,8 +68,8 @@
</button> </button>
{#if moderators.length > 0} {#if moderators.length > 0}
<Expandable <Expandable
bind:open={$userSettings.expand.team} class="border rounded-xl bg-white/50 dark:bg-zinc-900/50 w-full p-3 px-4
class="py-2 border-y border-slate-200 dark:border-zinc-800" dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text-zinc-300 transition-colors"
> >
<svelte:fragment slot="title"> <svelte:fragment slot="title">
<ShieldIcon width={15} filled /> <ShieldIcon width={15} filled />
@@ -166,6 +166,7 @@
body={post.post.body} body={post.post.body}
{view} {view}
style="grid-area: body" style="grid-area: body"
class="relative"
/> />
{/if} {/if}
{#if actions} {#if actions}
@@ -47,9 +47,9 @@ ${view == 'list' ? `max-h-24` : 'max-h-48'}`
on:click={() => (expanded = !expanded)} on:click={() => (expanded = !expanded)}
size="square-sm" size="square-sm"
color="tertiary" color="tertiary"
class="text-black dark:text-white absolute z-10 isolate drop-shadow-xl pointer-events-auto {expanded class="text-black dark:text-white absolute z-10 isolate pointer-events-auto bottom-0 {expanded
? 'bottom-6' ? 'bg-slate-200/50 dark:bg-zinc-900 border shadow-md'
: 'bottom-16'} left-1/2 -translate-x-1/2" : ''} left-1/2 -translate-x-1/2 mb-4"
title="Expand" title="Expand"
> >
<Icon <Icon
@@ -102,8 +102,6 @@
} }
let popoverOpen = false let popoverOpen = false
$: console.log(popoverOpen)
</script> </script>
<!-- <!--
+49 -17
View File
@@ -4,6 +4,7 @@
import PostBody from '../lemmy/post/PostBody.svelte' import PostBody from '../lemmy/post/PostBody.svelte'
import LabelStat from './LabelStat.svelte' import LabelStat from './LabelStat.svelte'
import { optimizeImageURL } from '../lemmy/post/helpers' import { optimizeImageURL } from '../lemmy/post/helpers'
import FormattedNumber from '../util/FormattedNumber.svelte'
export let avatar: string | undefined = undefined export let avatar: string | undefined = undefined
export let name: string export let name: string
@@ -13,7 +14,10 @@
export let stats: { export let stats: {
name: string name: string
value: string value: string
format?: boolean
}[] = [] }[] = []
export let center: boolean = false
</script> </script>
<Material <Material
@@ -23,11 +27,12 @@
class="z-10 relative border-slate-200 dark:border-zinc-700" class="z-10 relative border-slate-200 dark:border-zinc-700"
{...$$restProps} {...$$restProps}
> >
{#if banner} {#if banner || avatar}
<div class="max-h-36 overflow-visible"> <div class="max-h-36 overflow-visible">
<img <img
src={banner} src={banner ?? avatar}
class="w-full object-cover h-48 rounded-xl bg-white dark:bg-zinc-900" class="w-full object-cover h-48 rounded-t-xl bg-white dark:bg-zinc-900 banner-mask"
class:blur-3xl={!banner}
height="192" height="192"
alt="User banner" alt="User banner"
/> />
@@ -37,41 +42,46 @@
overflow-hidden" overflow-hidden"
> >
<img <img
src={optimizeImageURL(banner, 64)} src={optimizeImageURL(banner ?? avatar ?? '', 64)}
alt="" alt=""
class="opacity-10 blur-2xl h-full w-full saturate-200" class="opacity-10 blur-2xl h-full w-full saturate-200"
/> />
</div> </div>
{/if} {/if}
<div class="p-4 flex flex-col sm:flex-row gap-4"> <div class="p-4 flex flex-col sm:flex-row gap-4 items">
<div class="space-y-3 flex-1"> <div class="space-y-3 flex-1 flex flex-col items-center text-center">
<Avatar <Avatar
width={64} width={64}
url={avatar} url={avatar}
alt={name} alt={name}
class="ring-4 ring-slate-25 dark:ring-zinc-925 bg-slate-25 dark:bg-zinc-925" class=" ring-slate-25 dark:ring-zinc-925 bg-slate-25 dark:bg-zinc-925"
/> />
<div> <div class="flex flex-col items-center">
<svelte:element <svelte:element
this={url ? 'a' : 'span'} this={url ? 'a' : 'span'}
href={url} href={url}
class="text-lg font-medium {url class="text-xl font-semibold {url
? 'hover:underline hover:text-primary-900 hover:dark:text-primary-100' ? 'hover:underline hover:text-primary-900 hover:dark:text-primary-100'
: ''}" : ''}"
> >
{name} {name}
</svelte:element> </svelte:element>
<span <span
class="flex items-center gap-0 text-sm text-slate-600 dark:text-zinc-400" class="flex items-center gap-0 text-sm text-slate-600 dark:text-zinc-400 max-w-full w-max"
> >
<slot name="nameDetail" /> <slot name="nameDetail" />
</span> </span>
</div> </div>
<div class="relative"> {#if bio}
{#if bio} <div class="relative {center ? 'text-center' : 'text-left'}">
<PostBody class="text-sm" view="list" body={bio} clickThrough /> <div
{/if} class="p-4 relative bg-white/50 dark:bg-zinc-900/50 border border-slate-300 dark:border-zinc-800 border-opacity-50
</div> rounded-xl"
>
<PostBody class="text-sm" view="list" body={bio} clickThrough />
</div>
</div>
{/if}
</div> </div>
{#if $$slots.actions} {#if $$slots.actions}
<div class="space-y-3 flex flex-col" class:sm:pt-12={banner != undefined}> <div class="space-y-3 flex flex-col" class:sm:pt-12={banner != undefined}>
@@ -81,12 +91,34 @@
</div> </div>
<div class="space-y-3 p-4 pt-0"> <div class="space-y-3 p-4 pt-0">
{#if stats.length > 0} {#if stats.length > 0}
<div class="text-sm flex flex-row flex-wrap gap-3"> <div class="text-sm flex flex-row flex-wrap gap-3 mx-auto">
{#each stats as stat} {#each stats as stat}
<LabelStat content={stat.value} formatted label={stat.name} /> <div
class="p-3 px-4 rounded-xl flex-1 bg-white/50 dark:bg-zinc-900/50 border border-slate-300 dark:border-zinc-800 border-opacity-50"
>
<div class="text-primary-900 dark:text-primary-100">
{stat.name}
</div>
<div class="text-xl font-semibold">
{#if stat.format ?? true}
<FormattedNumber
number={Number(stat.value)}
options={{ notation: 'standard' }}
/>
{:else}
{stat.value}
{/if}
</div>
</div>
{/each} {/each}
</div> </div>
{/if} {/if}
<slot /> <slot />
</div> </div>
</Material> </Material>
<style>
.banner-mask {
mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
}
</style>
+30 -23
View File
@@ -1,24 +1,10 @@
<script lang="ts"> <script lang="ts" context="module">
import { locale } from '$lib/translations' export function formatRelativeDate(
date: Date,
export let date: Date options: Intl.RelativeTimeFormatOptions,
export let relativeTo: Date | undefined = undefined locale?: string,
export let options: Intl.RelativeTimeFormatOptions = { relativeTo?: Date
numeric: 'always', ) {
style: 'narrow',
}
const toLocaleDateString = (date: Date): string => {
try {
return date.toLocaleString()
} catch (err) {
return 'Invalid Date'
}
}
$: dateTime = toLocaleDateString(date)
function formatRelativeDate(date: Date) {
try { try {
const now = relativeTo?.getTime() ?? Date.now() const now = relativeTo?.getTime() ?? Date.now()
@@ -38,7 +24,7 @@
if (diffInMillis >= thresholds[i].threshold) { if (diffInMillis >= thresholds[i].threshold) {
const value = Math.round(diffInMillis / thresholds[i].threshold) const value = Math.round(diffInMillis / thresholds[i].threshold)
let language = $locale let language = locale ?? 'en'
const rtf = new Intl.RelativeTimeFormat(language, options) const rtf = new Intl.RelativeTimeFormat(language, options)
@@ -52,11 +38,32 @@
} }
</script> </script>
<script lang="ts">
import { locale } from '$lib/translations'
export let date: Date
export let relativeTo: Date | undefined = undefined
export let options: Intl.RelativeTimeFormatOptions = {
numeric: 'always',
style: 'narrow',
}
const toLocaleDateString = (date: Date): string => {
try {
return date.toLocaleString()
} catch (err) {
return 'Invalid Date'
}
}
$: dateTime = toLocaleDateString(date)
</script>
<time <time
datetime={dateTime} datetime={dateTime}
title={dateTime} title={dateTime}
class={$$props.class ?? ''} class={$$props.class ?? ''}
style={$$props.style ?? ''} style={$$props.style ?? ''}
> >
{formatRelativeDate(date)} {formatRelativeDate(date, options, $locale, relativeTo)}
</time> </time>
+3
View File
@@ -859,5 +859,8 @@
"upvotes": "{{default}} upvotes", "upvotes": "{{default}} upvotes",
"downvotes": "{{default}} downvotes" "downvotes": "{{default}} downvotes"
} }
},
"stats": {
"joined": "Joined"
} }
} }
+110 -94
View File
@@ -34,6 +34,8 @@
import ItemList from '$lib/components/lemmy/generic/ItemList.svelte' import ItemList from '$lib/components/lemmy/generic/ItemList.svelte'
import { t } from '$lib/translations.js' import { t } from '$lib/translations.js'
import EntityHeader from '$lib/components/ui/EntityHeader.svelte' import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
import { publishedToDate } from '$lib/components/util/date.js'
import { formatRelativeDate } from '$lib/components/util/RelativeDate.svelte'
export let data export let data
@@ -142,113 +144,127 @@
{/if} {/if}
<div class="flex flex-col gap-4 max-w-full w-full"> <div class="flex flex-col gap-4 max-w-full w-full">
<EntityHeader <div class="">
avatar={data.person_view.person.avatar} <EntityHeader
name={data.person_view.person.display_name || data.person_view.person.name} avatar={data.person_view.person.avatar}
banner={data.person_view.person.banner} name={data.person_view.person.display_name ||
bio={data.person_view.person.bio} data.person_view.person.name}
stats={[ banner={data.person_view.person.banner}
{ bio={data.person_view.person.bio}
name: $t('content.posts'), stats={[
value: data.person_view.counts.post_count.toString(), {
}, name: $t('content.posts'),
{ value: data.person_view.counts.post_count.toString(),
name: $t('content.comments'), },
value: data.person_view.counts.comment_count.toString(), {
}, name: $t('content.comments'),
]} value: data.person_view.counts.comment_count.toString(),
> },
<span class="text-sm flex gap-0 items-center" slot="nameDetail"> {
@ name: $t('stats.joined'),
<UserLink value: formatRelativeDate(
showInstance publishedToDate(data.person_view.person.published),
user={data.person_view.person} { style: 'long' }
displayName={false} ).toString(),
class="font-normal" format: false,
/> },
</span> ]}
{#if (data.moderates ?? []).length > 0} >
<Expandable <span class="text-sm flex gap-0 items-center w-max" slot="nameDetail">
class="border-y w-full py-3 @
dark:border-zinc-800 text-slate-700 dark:text-zinc-300 transition-colors" <UserLink
> showInstance
<span slot="title" class="flex items-center gap-1"> user={data.person_view.person}
<ShieldIcon width={14} filled /> displayName={false}
{$t('routes.profile.moderates')} class="font-normal"
</span>
<ItemList
items={data.moderates.map((m) => ({
id: m.community.id,
name: m.community.title,
url: communityLink(m.community),
avatar: m.community.icon,
instance: new URL(m.community.actor_id).hostname,
}))}
/> />
</Expandable> </span>
{/if} {#if (data.moderates ?? []).length > 0}
<svelte:fragment slot="actions"> <Expandable
{#if $profile?.user && $profile.jwt && data.person_view.person.id != $profile.user.local_user_view.person.id} class="border rounded-xl bg-white/50 dark:bg-zinc-900/50 w-full p-3 px-4
<div class="flex items-center gap-2 w-full"> dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text-zinc-300 transition-colors"
<Button >
size="square-md" <span slot="title" class="flex items-center gap-1">
color="secondary" <ShieldIcon width={14} filled />
href="/inbox/messages/{data.person_view.person.id}" {$t('routes.profile.moderates')}
title="Message" </span>
> <ItemList
<Icon slot="prefix" solid size="16" src={Envelope} /> items={data.moderates.map((m) => ({
</Button> id: m.community.id,
{#if data.person_view.person.matrix_user_id} name: m.community.title,
url: communityLink(m.community),
avatar: m.community.icon,
instance: new URL(m.community.actor_id).hostname,
}))}
/>
</Expandable>
{/if}
<svelte:fragment slot="actions">
{#if $profile?.user && $profile.jwt && data.person_view.person.id != $profile.user.local_user_view.person.id}
<div class="flex items-center gap-2 w-full">
<Button <Button
size="square-md" size="square-md"
color="secondary" color="secondary"
href="https://matrix.to/#/{data.person_view.person href="/inbox/messages/{data.person_view.person.id}"
.matrix_user_id}" title="Message"
title="Matrix User"
> >
<Icon slot="prefix" solid size="16" src={AtSymbol} /> <Icon slot="prefix" solid size="16" src={Envelope} />
</Button> </Button>
{/if} {#if data.person_view.person.matrix_user_id}
{#if isAdmin($profile?.user)} <Button
<Menu class="ml-auto" placement="bottom-end"> size="square-md"
color="secondary"
href="https://matrix.to/#/{data.person_view.person
.matrix_user_id}"
title="Matrix User"
>
<Icon slot="prefix" solid size="16" src={AtSymbol} />
</Button>
{/if}
{#if isAdmin($profile?.user)}
<Menu class="ml-auto" placement="bottom-end">
<Button size="square-md" slot="target">
<ShieldIcon width={16} filled />
</Button>
<MenuButton
color="danger-subtle"
on:click={() =>
ban(
data.person_view.person.banned,
data.person_view.person
)}
>
<Icon slot="prefix" mini size="16" src={ShieldExclamation} />
{data.person_view.person.banned ? 'Unban' : 'Ban'}
</MenuButton>
<MenuButton
color="danger-subtle"
on:click={() => (purgingUser = !purgingUser)}
>
<Icon slot="prefix" mini size="16" src={Fire} />
Purge
</MenuButton>
</Menu>
{/if}
<Menu placement="bottom-end">
<Button size="square-md" slot="target"> <Button size="square-md" slot="target">
<ShieldIcon width={16} filled /> <Icon src={EllipsisHorizontal} slot="prefix" size="16" mini />
</Button> </Button>
<MenuButton <MenuButton
color="danger-subtle" color="danger-subtle"
on:click={() => on:click={() => blockUser(data.person_view.person.id)}
ban(data.person_view.person.banned, data.person_view.person)}
> >
<Icon slot="prefix" mini size="16" src={ShieldExclamation} /> <Icon slot="prefix" mini size="16" src={NoSymbol} />
{data.person_view.person.banned ? 'Unban' : 'Ban'} {isBlocked($profile.user, data.person_view.person.id)
</MenuButton> ? 'Unblock'
<MenuButton : 'Block'}
color="danger-subtle"
on:click={() => (purgingUser = !purgingUser)}
>
<Icon slot="prefix" mini size="16" src={Fire} />
Purge
</MenuButton> </MenuButton>
</Menu> </Menu>
{/if} </div>
<Menu placement="bottom-end"> {/if}
<Button size="square-md" slot="target"> </svelte:fragment>
<Icon src={EllipsisHorizontal} slot="prefix" size="16" mini /> </EntityHeader>
</Button> </div>
<MenuButton
color="danger-subtle"
on:click={() => blockUser(data.person_view.person.id)}
>
<Icon slot="prefix" mini size="16" src={NoSymbol} />
{isBlocked($profile.user, data.person_view.person.id)
? 'Unblock'
: 'Block'}
</MenuButton>
</Menu>
</div>
{/if}
</svelte:fragment>
</EntityHeader>
<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">
<div class="flex flex-row gap-4 flex-wrap"> <div class="flex flex-row gap-4 flex-wrap">