feat: add admin and moderator badges to posts and comments

This commit is contained in:
Xylight committed 2024-03-09 12:00:34 -08:00
1 parent 3f5c49d4c4
commit 3c74cfe4e6
7 files changed
+85 -36

No files matched your search

@@ -19,6 +19,7 @@
import { profile } from '$lib/auth.js'
import { Button, Modal } from 'mono-svelte'
import { publishedToDate } from '$lib/components/util/date.js'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
export let node: CommentNodeI
export let postId: number
@@ -104,7 +105,16 @@
avatarSize={22}
avatar
user={node.comment_view.creator}
/>
>
<svelte:fragment slot="badges">
{#if node.comment_view.creator_is_moderator}
<ShieldIcon filled width={14} class="text-green-500" />
{/if}
{#if node.comment_view.creator_is_admin}
<ShieldIcon filled width={14} class="text-red-500" />
{/if}
</svelte:fragment>
</UserLink>
{#if op}
<span class="text-sky-500">OP</span>
{/if}
@@ -21,11 +21,18 @@
>
<div class="flex flex-row justify-between items-center">
<PostMeta
deleted={false}
featured={false}
nsfw={comment.post.nsfw}
badges={{
nsfw: comment.post.nsfw,
removed: comment.post.removed,
admin: false,
moderator: false,
saved: false,
deleted: comment.post.deleted,
featured:
comment.post.featured_community || comment.post.featured_local,
locked: comment.post.locked,
}}
published={publishedToDate(comment.comment.published)}
saved={false}
community={community ? comment.community : undefined}
/>
<Button
@@ -10,7 +10,7 @@
viewBox="0 0 20 22"
fill="none"
xmlns="http://www.w3.org/2000/svg"
class="inline"
class="inline {$$props.class}"
>
<path
d="M10.516 1.17C10.3767 1.03791 10.192 0.964283 10 0.964283C9.80801 0.964283 9.62333 1.03791 9.484 1.17C7.36127 3.18588 4.53412 4.29133 1.607 4.25C1.44753 4.24793 1.29156 4.29674 1.16172 4.38935C1.03189 4.48196 0.934957 4.61355 0.885 4.765C0.462973 6.05116 0.248618 7.39637 0.25 8.75C0.25 14.692 4.314 19.683 9.813 21.098C9.93566 21.1296 10.0643 21.1296 10.187 21.098C15.686 19.683 19.75 14.692 19.75 8.75C19.75 7.36 19.527 6.02 19.115 4.765C19.0652 4.61336 18.9684 4.48156 18.8385 4.38875C18.7087 4.29595 18.5526 4.247 18.393 4.249L18.25 4.25C15.254 4.25 12.533 3.08 10.516 1.17Z"
@@ -24,7 +24,7 @@
viewBox="0 0 20 22"
fill="none"
xmlns="http://www.w3.org/2000/svg"
class="inline"
class="inline {$$props.class}"
>
<path
fill-rule="evenodd"
+21 -9
View File
@@ -46,12 +46,16 @@
community={hideCommunity ? undefined : post.community}
user={post.creator}
published={publishedToDate(post.post.published)}
deleted={post.post.deleted}
removed={post.post.removed}
locked={post.post.locked}
featured={post.post.featured_local || post.post.featured_community}
nsfw={post.post.nsfw}
saved={post.saved}
badges={{
deleted: post.post.deleted,
removed: post.post.removed,
locked: post.post.locked,
featured: post.post.featured_local || post.post.featured_community,
nsfw: post.post.nsfw,
saved: post.saved,
admin: post.creator_is_admin,
moderator: post.creator_is_moderator,
}}
subscribed={$profile?.user?.follows
.map((c) => c.community.id)
.includes(post.community.id)
@@ -64,10 +68,18 @@
</PostMeta>
<PostMedia bind:post={post.post} {view} {type} />
{#if view == 'list' || view == 'compact'}
<PostMediaCompact {view} bind:post={post.post} style="grid-area: media; grid-column: span 2 / span 2;" />
<PostMediaCompact
{view}
bind:post={post.post}
style="grid-area: media; grid-column: span 2 / span 2;"
/>
{/if}
{#if post.post.body && !post.post.nsfw && view != 'compact'}
<PostBody body={post.post.body} {view} style="grid-area: body; grid-column: span 1 / span 1;" />
<PostBody
body={post.post.body}
{view}
style="grid-area: body; grid-column: span 1 / span 1;"
/>
{/if}
{#if actions}
<PostActions
@@ -96,4 +108,4 @@
grid-template-rows: 3;
grid-template-columns: 2;
}
</style>
</style>
+27 -13
View File
@@ -17,6 +17,7 @@
import { getInstance } from '$lib/lemmy.js'
import { profile } from '$lib/auth.js'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
export let community: Community | undefined = undefined
export let subscribed: SubscribedType | undefined = undefined
@@ -27,12 +28,16 @@
export let id: number | undefined = undefined
// Badges
export let nsfw: boolean = false
export let saved: boolean = false
export let featured: boolean = false
export let deleted: boolean = false
export let removed: boolean = false
export let locked: boolean = false
export let badges = {
nsfw: false,
saved: false,
featured: false,
deleted: false,
removed: false,
locked: false,
moderator: false,
admin: false,
}
</script>
<div
@@ -81,7 +86,16 @@
style="grid-area: stats;"
>
{#if user}
<UserLink avatarSize={20} {user} avatar={!community} />
<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 published}
<RelativeDate date={published} />
@@ -92,34 +106,34 @@
class="flex flex-row items-center place-self-end overflow-auto [&>*]:flex-shrink-0"
style="grid-area: badges;"
>
{#if nsfw}
{#if badges.nsfw}
<Badge color="red-subtle">NSFW</Badge>
{/if}
{#if saved}
{#if badges.saved}
<Badge label="Saved" color="yellow-subtle">
<Icon src={Bookmark} mini size="12" />
<span class="max-md:hidden">Saved</span>
</Badge>
{/if}
{#if locked}
{#if badges.locked}
<Badge label="Locked" color="yellow-subtle">
<Icon src={LockClosed} mini size="14" />
<span class="max-md:hidden">Locked</span>
</Badge>
{/if}
{#if removed}
{#if badges.removed}
<Badge label="Removed" color="red-subtle">
<Icon src={Trash} mini size="14" />
<span class="max-md:hidden">Removed</span>
</Badge>
{/if}
{#if deleted}
{#if badges.deleted}
<Badge label="Deleted" color="red-subtle">
<Icon src={Trash} mini size="14" />
<span class="max-md:hidden">Deleted</span>
</Badge>
{/if}
{#if featured}
{#if badges.featured}
<Badge label="Featured" color="green-subtle">
<Icon src={Megaphone} mini size="14" />
<span class="max-md:hidden">Featured</span>
@@ -45,5 +45,6 @@
{#if user.bot_account}
<div class="text-blue-500 font-bold" title="Bot">BOT</div>
{/if}
<slot name="badges" />
{/if}
</a>
@@ -168,14 +168,19 @@
community={post.post_view.community}
user={post.post_view.creator}
bind:subscribed={post.community_view.subscribed}
deleted={post.post_view.post.deleted}
removed={post.post_view.post.removed}
locked={post.post_view.post.locked}
featured={post.post_view.post.featured_community ||
post.post_view.post.featured_local}
nsfw={post.post_view.post.nsfw}
badges={{
deleted: post.post_view.post.deleted,
removed: post.post_view.post.removed,
locked: post.post_view.post.locked,
featured:
post.post_view.post.featured_community ||
post.post_view.post.featured_local,
nsfw: post.post_view.post.nsfw,
saved: post.post_view.saved,
admin: post.post_view.creator_is_admin,
moderator: post.post_view.creator_is_moderator,
}}
published={publishedToDate(post.post_view.post.published)}
saved={post.post_view.saved}
/>
</div>
<Button on:click={() => history.back()} size="square-md">