misc: update how badges work
This commit is contained in:
1 parent
67cfd758b0
commit
36a7838a47
2 files changed
+69
-18
No files matched your search
@@ -1,9 +1,48 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
import { env } from '$env/dynamic/public'
|
import { env } from '$env/dynamic/public'
|
||||||
|
|
||||||
const hasPhotonBadge = (actor_id: string) =>
|
import type { IconSource } from 'svelte-hero-icons'
|
||||||
env.PUBLIC_PHOTON_BADGE &&
|
|
||||||
env.PUBLIC_PHOTON_BADGE.split(',').includes(actor_id)
|
function parseBadge() {
|
||||||
|
try {
|
||||||
|
if (env.PUBLIC_BADGES) {
|
||||||
|
return JSON.parse(env.PUBLIC_BADGES)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const badges = parseBadge()
|
||||||
|
|
||||||
|
const getEnvBadge = (
|
||||||
|
actor_id: string
|
||||||
|
):
|
||||||
|
| {
|
||||||
|
classes: string
|
||||||
|
icon: 'photon' | IconSource
|
||||||
|
iconClass?: string
|
||||||
|
}
|
||||||
|
| false => {
|
||||||
|
if (badges.photon && badges.photon.includes?.(actor_id)) {
|
||||||
|
return {
|
||||||
|
classes:
|
||||||
|
'bg-gradient-to-r bg-clip-text text-transparent from-blue-500 to-purple-700 dark:from-blue-400 dark:to-purple-500',
|
||||||
|
icon: 'photon',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (badges.translator && badges.translator.includes?.(actor_id)) {
|
||||||
|
return {
|
||||||
|
classes:
|
||||||
|
'bg-gradient-to-r bg-clip-text text-transparent from-sky-500 to-blue-700 dark:from-blue-300 dark:to-indigo-500',
|
||||||
|
icon: Language,
|
||||||
|
iconClass: 'text-blue-500 dark:text-blue-400',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -11,7 +50,7 @@
|
|||||||
import Logo from '$lib/components/ui/Logo.svelte'
|
import Logo from '$lib/components/ui/Logo.svelte'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
import type { Person } from 'lemmy-js-client'
|
import type { Person } from 'lemmy-js-client'
|
||||||
import { Icon, NoSymbol } from 'svelte-hero-icons'
|
import { Icon, Language, NoSymbol } from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let user: Person
|
export let user: Person
|
||||||
export let avatar: boolean = false
|
export let avatar: boolean = false
|
||||||
@@ -22,7 +61,8 @@
|
|||||||
$userSettings.showInstances.user ||
|
$userSettings.showInstances.user ||
|
||||||
($userSettings.showInstances.comments && inComment)
|
($userSettings.showInstances.comments && inComment)
|
||||||
export let displayName = $userSettings.displayNames
|
export let displayName = $userSettings.displayNames
|
||||||
$: photonBadge = hasPhotonBadge(user.actor_id)
|
|
||||||
|
$: envBadge = getEnvBadge(user.actor_id)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<a
|
<a
|
||||||
@@ -42,10 +82,11 @@
|
|||||||
<span
|
<span
|
||||||
class="flex gap-0 items-center flex-shrink max-w-full min-w-0"
|
class="flex gap-0 items-center flex-shrink max-w-full min-w-0"
|
||||||
class:ml-0.5={avatar}
|
class:ml-0.5={avatar}
|
||||||
class:text-indigo-600={photonBadge}
|
|
||||||
class:dark:text-indigo-400={photonBadge}
|
|
||||||
>
|
>
|
||||||
<span class:font-medium={showInstance} class="username-text">
|
<span
|
||||||
|
class:font-medium={showInstance}
|
||||||
|
class="username-text {envBadge && envBadge.classes}"
|
||||||
|
>
|
||||||
{displayName ? user.display_name || user.name : user.name}
|
{displayName ? user.display_name || user.name : user.name}
|
||||||
</span>
|
</span>
|
||||||
{#if showInstance}
|
{#if showInstance}
|
||||||
@@ -66,8 +107,17 @@
|
|||||||
{#if user.bot_account}
|
{#if user.bot_account}
|
||||||
<div class="text-blue-500 font-bold" title="Bot">BOT</div>
|
<div class="text-blue-500 font-bold" title="Bot">BOT</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if photonBadge}
|
{#if envBadge}
|
||||||
<Logo width={16} />
|
{#if envBadge.icon == 'photon'}
|
||||||
|
<Logo width={16} />
|
||||||
|
{:else}
|
||||||
|
<Icon
|
||||||
|
src={envBadge.icon}
|
||||||
|
micro
|
||||||
|
size="16"
|
||||||
|
class={envBadge.iconClass ?? envBadge.classes}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
<slot name="badges" />
|
<slot name="badges" />
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
import { site } from '$lib/lemmy'
|
import { site } from '$lib/lemmy'
|
||||||
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
|
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
|
|
||||||
let showInstance = false
|
let showInstance = false
|
||||||
</script>
|
</script>
|
||||||
@@ -85,14 +86,14 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
{#if $profile?.user}
|
{#if $profile?.user}
|
||||||
<div class="flex flex-row gap-2 items-center py-2 mx-2 font-medium">
|
<UserLink
|
||||||
<Avatar
|
user={$profile?.user.local_user_view.person}
|
||||||
width={22}
|
showInstance={false}
|
||||||
url={$profile?.user?.local_user_view.person.avatar}
|
avatar
|
||||||
alt={$profile?.username}
|
avatarSize={24}
|
||||||
/>
|
displayName={false}
|
||||||
{$profile?.user?.local_user_view?.person.name}
|
class="font-medium px-2 py-1 pointer-events-none"
|
||||||
</div>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<MenuDivider>{$t('nav.menu.label')}</MenuDivider>
|
<MenuDivider>{$t('nav.menu.label')}</MenuDivider>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in new issue
Block a user