fix: move badges back to normal spot

This commit is contained in:
Xylight committed 2024-07-01 11:34:24 -07:00
1 parent 5f34a102c3
commit 5407a0e62d
1 file changed
+194 -184
+194 -184
View File
@@ -1,203 +1,213 @@
<script lang="ts"> <script lang="ts">
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte' import CommunityLink from "$lib/components/lemmy/community/CommunityLink.svelte";
import Avatar from '$lib/components/ui/Avatar.svelte' import Avatar from "$lib/components/ui/Avatar.svelte";
import { Badge } from 'mono-svelte' import { Badge } from "mono-svelte";
import UserLink from '$lib/components/lemmy/user/UserLink.svelte' import UserLink from "$lib/components/lemmy/user/UserLink.svelte";
import RelativeDate from '$lib/components/util/RelativeDate.svelte' import RelativeDate from "$lib/components/util/RelativeDate.svelte";
import type { Community, Person, SubscribedType } from 'lemmy-js-client' import type { Community, Person, SubscribedType } from "lemmy-js-client";
import { import {
Bookmark, Bookmark,
Check, Check,
ExclamationTriangle, ExclamationTriangle,
Icon, Icon,
LockClosed, LockClosed,
Megaphone, Megaphone,
Plus, Plus,
Trash, Trash,
} from 'svelte-hero-icons' } from "svelte-hero-icons";
import { getInstance } from '$lib/lemmy.js' import { getInstance } from "$lib/lemmy.js";
import { profile } from '$lib/auth.js' import { profile } from "$lib/auth.js";
import Subscribe from '../../../../routes/communities/Subscribe.svelte' import Subscribe from "../../../../routes/communities/Subscribe.svelte";
import ShieldIcon from '../moderation/ShieldIcon.svelte' import ShieldIcon from "../moderation/ShieldIcon.svelte";
import { userSettings } from '$lib/settings' import { userSettings } from "$lib/settings";
import Markdown from '$lib/components/markdown/Markdown.svelte' import Markdown from "$lib/components/markdown/Markdown.svelte";
import { t } from '$lib/translations' import { t } from "$lib/translations";
export let community: Community | undefined = undefined export let community: Community | undefined = undefined;
export let subscribed: SubscribedType | undefined = undefined export let subscribed: SubscribedType | undefined = undefined;
export let user: Person | undefined = undefined export let user: Person | undefined = undefined;
export let published: Date | undefined = undefined export let published: Date | undefined = undefined;
export let title: string | undefined = undefined export let title: string | undefined = undefined;
export let id: number | undefined = undefined export let id: number | undefined = undefined;
export let read: boolean = false export let read: boolean = false;
// Badges // Badges
export let badges = { export let badges = {
nsfw: false, nsfw: false,
saved: false, saved: false,
featured: false, featured: false,
deleted: false, deleted: false,
removed: false, removed: false,
locked: false, locked: false,
moderator: false, moderator: false,
admin: false, admin: false,
} };
</script> </script>
<div <div
class="grid w-full meta {community class="grid w-full meta {community
? 'grid-rows-2' ? 'grid-rows-2'
: 'grid-rows-1'} text-xs min-w-0 max-w-full" : 'grid-rows-1'} text-xs min-w-0 max-w-full"
style={$$props.style ?? ''} style={$$props.style ?? ""}
> >
{#if community} {#if community}
<Subscribe let:subscribe let:subscribing> <Subscribe let:subscribe let:subscribing>
<button <button
on:click={async () => { on:click={async () => {
if (!community) return if (!community) return;
await subscribe(community.id, subscribed) await subscribe(community.id, subscribed);
subscribed = subscribed =
subscribed == 'NotSubscribed' ? 'Subscribed' : 'NotSubscribed' subscribed == "NotSubscribed"
}} ? "Subscribed"
class="relative cursor-pointer pr-2 row-span-2 flex-shrink-0" : "NotSubscribed";
> }}
<Avatar class="relative cursor-pointer pr-2 row-span-2 flex-shrink-0"
url={community.icon} >
width={28} <Avatar
alt={community.name} url={community.icon}
style="grid-area: avatar; height: 100%;" width={28}
class="flex-shrink-0" alt={community.name}
/> style="grid-area: avatar; height: 100%;"
{#if subscribed != undefined && $profile?.jwt} class="flex-shrink-0"
<div />
class="absolute w-3.5 h-3.5 {subscribed == 'NotSubscribed' {#if subscribed != undefined && $profile?.jwt}
? 'bg-primary-900 dark:bg-primary-100 text-white dark:text-black' <div
: 'bg-primary-100 dark:bg-primary-900 text-black dark:text-white'} rounded-full ring-2 box-border 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 ring-slate-50 dark:ring-zinc-950
-bottom-1 right-1 grid place-items-center transition-all" -bottom-1 right-1 grid place-items-center transition-all"
> >
<Icon <Icon
src={subscribed == 'NotSubscribed' ? Plus : Check} src={subscribed == "NotSubscribed" ? Plus : Check}
mini mini
size="12" size="12"
/> />
</div> </div>
{/if}
</button>
</Subscribe>
{/if}
{#if community}
<CommunityLink
{community}
style="grid-area: community;"
class="flex-shrink"
/>
{/if}
<span
class="text-slate-600 dark:text-zinc-400 flex flex-row gap-2 items-center"
style="grid-area: stats;"
>
{#if user}
<UserLink avatarSize={20} {user} avatar={!community}>
<svelte:fragment slot="badges">
{#if badges.moderator}
<ShieldIcon filled width={14} class="text-green-500" />
{/if}
{#if badges.admin}
<ShieldIcon filled width={14} class="text-red-500" />
{/if}
</svelte:fragment>
</UserLink>
{/if} {/if}
</button> {#if published}
</Subscribe> <RelativeDate date={published} class="flex-shrink-0" />
{/if} {/if}
{#if community} </span>
<CommunityLink <div
{community} class="flex flex-row items-center self-center flex-wrap gap-2 [&>*]:flex-shrink-0 badges"
style="grid-area: community;" style="grid-area: badges;"
class="flex-shrink" >
/> {#if badges.nsfw}
{/if} <Badge
<span label={$t("post.badges.nsfw")}
class="text-slate-600 dark:text-zinc-400 flex flex-row gap-2 items-center" color="red-subtle"
style="grid-area: stats;" allowIconOnly
> >
{#if user} <Icon src={ExclamationTriangle} size="14" micro slot="icon" />
<UserLink avatarSize={20} {user} avatar={!community}> {$t("post.badges.nsfw")}
<svelte:fragment slot="badges"> </Badge>
{#if badges.moderator} {/if}
<ShieldIcon filled width={14} class="text-green-500" /> {#if badges.saved}
{/if} <Badge
{#if badges.admin} label={$t("post.badges.saved")}
<ShieldIcon filled width={14} class="text-red-500" /> color="yellow-subtle"
{/if} allowIconOnly
</svelte:fragment> >
</UserLink> <Icon src={Bookmark} micro size="14" slot="icon" />
{/if} {$t("post.badges.saved")}
{#if published} </Badge>
<RelativeDate date={published} class="flex-shrink-0" /> {/if}
{/if} {#if badges.locked}
</span> <Badge
<div label={$t("post.badges.locked")}
class="flex flex-row items-center self-center flex-wrap gap-2 [&>*]:flex-shrink-0 badges" color="yellow-subtle"
style="grid-area: badges;" allowIconOnly
> >
{#if badges.nsfw} <Icon src={LockClosed} micro size="14" slot="icon" />
<Badge label={$t('post.badges.nsfw')} color="red-subtle" allowIconOnly> <span class="max-md:hidden">{$t("post.badges.locked")}</span>
<Icon src={ExclamationTriangle} size="14" micro slot="icon" /> </Badge>
{$t('post.badges.nsfw')} {/if}
</Badge> {#if badges.removed}
{/if} <Badge
{#if badges.saved} label={$t("post.badges.removed")}
<Badge color="red-subtle"
label={$t('post.badges.saved')} allowIconOnly
color="yellow-subtle" >
allowIconOnly <Icon src={Trash} micro size="14" slot="icon" />
> <span class="max-md:hidden">{$t("post.badges.removed")}</span>
<Icon src={Bookmark} micro size="14" slot="icon" /> </Badge>
{$t('post.badges.saved')} {/if}
</Badge> {#if badges.deleted}
{/if} <Badge
{#if badges.locked} label={$t("post.badges.deleted")}
<Badge color="red-subtle"
label={$t('post.badges.locked')} allowIconOnly
color="yellow-subtle" >
allowIconOnly <Icon src={Trash} micro size="14" slot="icon" />
> <span class="max-md:hidden">{$t("post.badges.deleted")}</span>
<Icon src={LockClosed} micro size="14" slot="icon" /> </Badge>
<span class="max-md:hidden">{$t('post.badges.locked')}</span> {/if}
</Badge> {#if badges.featured}
{/if} <Badge
{#if badges.removed} label={$t("post.badges.featured")}
<Badge label={$t('post.badges.removed')} color="red-subtle" allowIconOnly> color="green-subtle"
<Icon src={Trash} micro size="14" slot="icon" /> allowIconOnly
<span class="max-md:hidden">{$t('post.badges.removed')}</span> >
</Badge> <Icon src={Megaphone} micro size="14" slot="icon" />
{/if} <span class="max-md:hidden">{$t("post.badges.featured")}</span>
{#if badges.deleted} </Badge>
<Badge label={$t('post.badges.deleted')} color="red-subtle" allowIconOnly> {/if}
<Icon src={Trash} micro size="14" slot="icon" /> <slot name="badges" />
<span class="max-md:hidden">{$t('post.badges.deleted')}</span> </div>
</Badge>
{/if}
{#if badges.featured}
<Badge
label={$t('post.badges.featured')}
color="green-subtle"
allowIconOnly
>
<Icon src={Megaphone} micro size="14" slot="icon" />
<span class="max-md:hidden">{$t('post.badges.featured')}</span>
</Badge>
{/if}
<slot name="badges" />
</div>
</div> </div>
{#if title && id} {#if title && id}
<a <a
href="/post/{getInstance()}/{id}" href="/post/{getInstance()}/{id}"
class="inline text-lg hover:underline class="inline text-lg hover:underline
hover:text-primary-900 hover:dark:text-primary-100 transition-colors hover:text-primary-900 hover:dark:text-primary-100 transition-colors
{$userSettings.font == 'satoshi/nunito' {$userSettings.font == 'satoshi/nunito'
? 'font-display font-semibold' ? 'font-display font-semibold'
: 'font-medium'}" : 'font-medium'}"
class:text-slate-600={$userSettings.markReadPosts && read} class:text-slate-600={$userSettings.markReadPosts && read}
class:dark:text-zinc-400={$userSettings.markReadPosts && read} class:dark:text-zinc-400={$userSettings.markReadPosts && read}
style="grid-area: title;" style="grid-area: title;"
> >
<Markdown source={title} inline noStyle class="leading-6"></Markdown> <Markdown source={title} inline noStyle class="leading-6"></Markdown>
</a> </a>
{/if} {/if}
<style> <style>
.meta { .meta {
display: grid; display: grid;
grid-template-areas: grid-template-areas:
'avatar community' "avatar community badges"
'avatar stats' "avatar stats badges";
'badges badges'; gap: 0;
gap: 0; grid-template-rows: auto auto;
grid-template-rows: auto auto auto; grid-template-columns: auto 1fr;
grid-template-columns: auto 1fr; }
}
.badges:not(:empty) {
padding-top: 0.5rem;
}
</style> </style>