optimize: denest postmeta

This commit is contained in:
Xylight committed 2024-02-24 10:16:13 -08:00
1 parent 8b82a782f5
commit 53318d2e5b
3 files changed
+98 -99

No files matched your search

@@ -12,6 +12,7 @@
</script> </script>
<a <a
{...$$restProps}
class="items-center flex flex-row gap-2 hover:underline flex-shrink-0" class="items-center flex flex-row gap-2 hover:underline flex-shrink-0"
href="/c/{community.name}@{new URL(community.actor_id).hostname}" href="/c/{community.name}@{new URL(community.actor_id).hostname}"
> >
@@ -63,8 +63,6 @@
community={hideCommunity ? undefined : post.community} community={hideCommunity ? undefined : post.community}
user={post.creator} user={post.creator}
published={publishedToDate(post.post.published)} published={publishedToDate(post.post.published)}
upvotes={post.counts.upvotes}
downvotes={post.counts.downvotes}
deleted={post.post.deleted} deleted={post.post.deleted}
removed={post.post.removed} removed={post.post.removed}
locked={post.post.locked} locked={post.post.locked}
+97 -97
View File
@@ -26,10 +26,6 @@
export let title: string | undefined = undefined export let title: string | undefined = undefined
export let id: number | undefined = undefined export let id: number | undefined = undefined
// Score
export let upvotes: number | undefined = undefined
export let downvotes: number | undefined = undefined
// Badges // Badges
export let nsfw: boolean = false export let nsfw: boolean = false
export let saved: boolean = false export let saved: boolean = false
@@ -39,108 +35,112 @@
export let locked: boolean = false export let locked: boolean = false
</script> </script>
<div class="flex flex-col gap-1 w-full"> <div
<span class="flex flex-row gap-2 text-sm items-center"> class="grid w-full meta {community ? 'grid-rows-2' : 'grid-rows-1'} text-xs"
{#if community} >
<Subscribe let:subscribe let:subscribing> {#if community}
<button <Subscribe let:subscribe let:subscribing>
on:click={async () => { <button
if (!community) return on:click={async () => {
await subscribe(community.id, subscribed) if (!community) return
subscribed = await subscribe(community.id, subscribed)
subscribed == 'NotSubscribed' ? 'Subscribed' : 'NotSubscribed' subscribed =
}} subscribed == 'NotSubscribed' ? 'Subscribed' : 'NotSubscribed'
class="relative cursor-pointer" }}
> class="relative cursor-pointer row-span-2 pr-2"
<Avatar url={community.icon} width={28} alt={community.name} />
{#if subscribed != undefined && $profile?.jwt}
<div
class="absolute w-3.5 h-3.5 {subscribed == 'NotSubscribed'
? 'bg-primary-900 dark:bg-primary-100 text-white dark:text-black'
: 'bg-primary-100 dark:bg-primary-900 text-black dark:text-white'} rounded-full ring-2 box-border
ring-slate-50 dark:ring-zinc-950
-bottom-1.5 -right-1.5 grid place-items-center transition-all"
>
<Icon
src={subscribed == 'NotSubscribed' ? Plus : Check}
mini
size="12"
/>
</div>
{/if}
</button>
</Subscribe>
{/if}
<div class="flex flex-col text-xs">
{#if community}
<CommunityLink {community} />
{/if}
<span
class="text-slate-600 dark:text-zinc-400 flex flex-row gap-1 flex-wrap items-center"
> >
{#if user} <Avatar
url={community.icon}
width={28}
alt={community.name}
style="grid-area: avatar; height: 100%;"
/>
{#if subscribed != undefined && $profile?.jwt}
<div <div
class="mr-0.5 flex items-center" class="absolute w-3.5 h-3.5 {subscribed == 'NotSubscribed'
class:text-slate-900={!community} ? 'bg-primary-900 dark:bg-primary-100 text-white dark:text-black'
class:dark:text-zinc-100={!community} : 'bg-primary-100 dark:bg-primary-900 text-black dark:text-white'} rounded-full ring-2 box-border
ring-slate-50 dark:ring-zinc-950
-bottom-1 right-1 grid place-items-center transition-all"
> >
<UserLink avatarSize={20} {user} avatar={!community} /> <Icon
src={subscribed == 'NotSubscribed' ? Plus : Check}
mini
size="12"
/>
</div> </div>
{/if} {/if}
{#if published} </button>
<RelativeDate date={published} /> </Subscribe>
{/if} {/if}
{#if upvotes != undefined && downvotes != undefined} {#if community}
<span>•</span> <CommunityLink {community} style="grid-area: community;" />
<span> {/if}
{Math.floor((upvotes / (upvotes + downvotes || 1)) * 100)}% <span
</span> class="text-slate-600 dark:text-zinc-400 flex flex-row gap-2 flex-wrap items-center row-span-2"
{/if} style="grid-area: stats;"
</span> >
</div> {#if user}
<UserLink avatarSize={20} {user} avatar={!community} />
<div {/if}
class="flex flex-row ml-auto gap-2 flex-shrink overflow-auto [&>*]:flex-shrink-0" {#if published}
> <RelativeDate date={published} />
{#if nsfw} {/if}
<Badge color="red-subtle">NSFW</Badge>
{/if}
{#if saved}
<Badge label="Saved" color="yellow-subtle">
<Icon src={Bookmark} mini size="12" />
<span class="max-md:hidden">Saved</span>
</Badge>
{/if}
{#if locked}
<Badge label="Locked" color="yellow-subtle">
<Icon src={LockClosed} mini size="14" />
<span class="max-md:hidden">Locked</span>
</Badge>
{/if}
{#if removed}
<Badge label="Removed" color="red-subtle">
<Icon src={Trash} mini size="14" />
<span class="max-md:hidden">Removed</span>
</Badge>
{/if}
{#if deleted}
<Badge label="Deleted" color="red-subtle">
<Icon src={Trash} mini size="14" />
<span class="max-md:hidden">Deleted</span>
</Badge>
{/if}
{#if featured}
<Badge label="Featured" color="green-subtle">
<Icon src={Megaphone} mini size="14" />
<span class="max-md:hidden">Featured</span>
</Badge>
{/if}
<slot name="badges" />
</div>
</span> </span>
<div
class="flex flex-row items-center place-self-end overflow-auto [&>*]:flex-shrink-0"
style="grid-area: badges;"
>
{#if nsfw}
<Badge color="red-subtle">NSFW</Badge>
{/if}
{#if saved}
<Badge label="Saved" color="yellow-subtle">
<Icon src={Bookmark} mini size="12" />
<span class="max-md:hidden">Saved</span>
</Badge>
{/if}
{#if locked}
<Badge label="Locked" color="yellow-subtle">
<Icon src={LockClosed} mini size="14" />
<span class="max-md:hidden">Locked</span>
</Badge>
{/if}
{#if removed}
<Badge label="Removed" color="red-subtle">
<Icon src={Trash} mini size="14" />
<span class="max-md:hidden">Removed</span>
</Badge>
{/if}
{#if deleted}
<Badge label="Deleted" color="red-subtle">
<Icon src={Trash} mini size="14" />
<span class="max-md:hidden">Deleted</span>
</Badge>
{/if}
{#if featured}
<Badge label="Featured" color="green-subtle">
<Icon src={Megaphone} mini size="14" />
<span class="max-md:hidden">Featured</span>
</Badge>
{/if}
<slot name="badges" />
</div>
{#if title && id} {#if title && id}
<a href="/post/{getInstance()}/{id}" class="font-medium"> <a href="/post/{getInstance()}/{id}" class="font-medium">
{title} {title}
</a> </a>
{/if} {/if}
</div> </div>
<style>
.meta {
display: grid;
grid-template-areas:
'avatar community badges'
'avatar stats badges';
gap: 0;
grid-template-columns: max-content;
}
</style>