refactor: use icon prop instead of snippet prefix
This commit is contained in:
56 files changed
+409
-595
No files matched your search
@@ -1,4 +1,5 @@
|
||||
<script lang="ts" module> type BadgeType =
|
||||
<script lang="ts" module>
|
||||
type BadgeType =
|
||||
| 'nsfw'
|
||||
| 'saved'
|
||||
| 'featured'
|
||||
@@ -86,11 +87,11 @@
|
||||
|
||||
const newTitle = title
|
||||
.toString()
|
||||
.replace(/^(\[.[^\]]+\])|(\[.[^\]]+\])$/g, match => {
|
||||
.replace(/^(\[.[^\]]+\])|(\[.[^\]]+\])$/g, (match) => {
|
||||
const contents = match.split(',').map((part: string) => part.trim())
|
||||
|
||||
contents
|
||||
.map(i => i.replaceAll(/(\[|\])/g, ''))
|
||||
.map((i) => i.replaceAll(/(\[|\])/g, ''))
|
||||
.forEach((content: string) => {
|
||||
extracted.push(
|
||||
textToTag.get(content) ?? {
|
||||
@@ -332,15 +333,16 @@
|
||||
{/if}
|
||||
{#each Object.keys(badges)
|
||||
// filter by ones that are true
|
||||
.filter(i => badges[i as BadgeType] == true)
|
||||
.filter((i) => badges[i as BadgeType] == true)
|
||||
// get from predetermined map
|
||||
.map(i => badgeToData.get(i as BadgeType))
|
||||
.map((i) => badgeToData.get(i as BadgeType))
|
||||
// remove null
|
||||
.filter(i => i != undefined) as badge}
|
||||
<Badge label={badge.label} color={badge.color} allowIconOnly>{#snippet icon()}
|
||||
.filter((i) => i != undefined) as badge}
|
||||
<Badge label={badge.label} color={badge.color} allowIconOnly
|
||||
>{#snippet icon()}
|
||||
<Icon src={badge.icon} micro size="14" />{/snippet}{badge.label}
|
||||
</Badge>
|
||||
{/each}
|
||||
{/each}
|
||||
{@render extraBadges?.()}
|
||||
</div>
|
||||
</header>
|
||||
@@ -358,10 +360,8 @@
|
||||
<a
|
||||
href={useAttachedUrl
|
||||
? postUrl
|
||||
: `/post/${encodeURIComponent(profile.current.intsance)}/${id}`}
|
||||
target={useAttachedUrl
|
||||
? '_blank'
|
||||
: undefined}
|
||||
: `/post/${encodeURIComponent(profile.current.instance)}/${id}`}
|
||||
target={useAttachedUrl ? '_blank' : undefined}
|
||||
rel={useAttachedUrl ? 'noopener noreferrer' : undefined}
|
||||
class="inline-block hover:underline hover:text-primary-900 dark:hover:text-primary-100 transition-colors"
|
||||
>
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
<PostForm
|
||||
edit
|
||||
editingPost={post.post}
|
||||
onsubmit={e => {
|
||||
onsubmit={(e) => {
|
||||
editing = false
|
||||
post = e
|
||||
onedit?.(e)
|
||||
@@ -124,11 +124,8 @@
|
||||
color="secondary"
|
||||
rounding="pill"
|
||||
class={buttonSquare}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={BugAnt} micro size="16" />
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={BugAnt}
|
||||
></Button>
|
||||
{/if}
|
||||
{#if profile.current?.user && (amMod(profile.current.user, post.community) || isAdmin(profile.current.user))}
|
||||
{#await import('$lib/components/lemmy/moderation/ModerationMenu.svelte') then { default: ModerationMenu }}
|
||||
@@ -164,11 +161,8 @@
|
||||
loading={saving}
|
||||
disabled={saving}
|
||||
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.saved ? BookmarkSlash : Bookmark} size="16" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={post.saved ? BookmarkSlash : Bookmark}
|
||||
></Button>
|
||||
{/if}
|
||||
|
||||
<Menu placement="bottom-end">
|
||||
@@ -180,11 +174,8 @@
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
class={buttonSquare}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} size="16" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={EllipsisHorizontal}
|
||||
></Button>
|
||||
{/snippet}
|
||||
{#snippet children(open)}
|
||||
{#if open}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { PiefedClient } from '$lib/client/piefed/piefed'
|
||||
import type { PostView } from '$lib/client/types'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { deleteItem, markAsRead } from '$lib/lemmy/contentview'
|
||||
import { setSessionStorage } from '$lib/session'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { instanceToURL } from '$lib/util.svelte'
|
||||
import type { PostView } from '$lib/client/types'
|
||||
import { Button, Menu, MenuButton, toast } from 'mono-svelte'
|
||||
import {
|
||||
ArrowTopRightOnSquare,
|
||||
@@ -15,7 +17,6 @@
|
||||
EyeSlash,
|
||||
Flag,
|
||||
GlobeAlt,
|
||||
Icon,
|
||||
MapPin,
|
||||
PencilSquare,
|
||||
Share,
|
||||
@@ -24,8 +25,6 @@
|
||||
} from 'svelte-hero-icons'
|
||||
import { report } from '../../moderation/moderation'
|
||||
import { hidePost } from '../helpers'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { PiefedClient } from '$lib/client/piefed/piefed'
|
||||
|
||||
interface Props {
|
||||
post: PostView
|
||||
@@ -52,10 +51,7 @@
|
||||
</script>
|
||||
|
||||
{#if profile.current?.user && profile.current?.jwt && profile.current.user.local_user_view.person.id == post.creator.id}
|
||||
<MenuButton onclick={() => (editing = true)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} size="16" micro />
|
||||
{/snippet}
|
||||
<MenuButton onclick={() => (editing = true)} icon={PencilSquare}>
|
||||
{$t('post.actions.more.edit')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -65,10 +61,8 @@
|
||||
if (profile.current?.jwt)
|
||||
post.read = await markAsRead(post.post, !post.read)
|
||||
}}
|
||||
icon={post.read ? EyeSlash : Eye}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.read ? EyeSlash : Eye} size="16" micro />
|
||||
{/snippet}
|
||||
{post.read
|
||||
? $t('post.actions.more.markUnread')
|
||||
: $t('post.actions.more.markRead')}
|
||||
@@ -78,10 +72,8 @@
|
||||
<MenuButton
|
||||
onclick={() => share()}
|
||||
class={['flex-1', !post.post.local && 'rounded-r-lg']}
|
||||
icon={Share}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.share')}
|
||||
</MenuButton>
|
||||
{#if !post.post.local}
|
||||
@@ -94,27 +86,13 @@
|
||||
size="custom"
|
||||
class="w-6 h-6 self-center"
|
||||
data-autoclose="false"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={EllipsisHorizontal}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={EllipsisHorizontal}
|
||||
></Button>
|
||||
{/snippet}
|
||||
<MenuButton onclick={() => share(true)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={GlobeAlt} size="16" micro />
|
||||
{/snippet}
|
||||
<MenuButton onclick={() => share(true)} icon={GlobeAlt}>
|
||||
{$t('filter.location.global')}
|
||||
</MenuButton>
|
||||
<MenuButton onclick={() => share(false)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={MapPin} size="16" micro />
|
||||
{/snippet}
|
||||
<MenuButton onclick={() => share(false)} icon={MapPin}>
|
||||
{$t('filter.location.local')}
|
||||
</MenuButton>
|
||||
</Menu>
|
||||
@@ -141,10 +119,8 @@
|
||||
|
||||
goto('/create/post?crosspost=true')
|
||||
}}
|
||||
icon={ArrowTopRightOnSquare}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowTopRightOnSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.crosspost')}
|
||||
</MenuButton>
|
||||
{#if profile.current.user && post.creator.id == profile.current.user.local_user_view.person.id}
|
||||
@@ -154,10 +130,8 @@
|
||||
post.post.deleted = await deleteItem(post, !post.post.deleted)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
icon={Trash}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Trash} size="16" micro />
|
||||
{/snippet}
|
||||
{post.post.deleted
|
||||
? $t('post.actions.more.restore')
|
||||
: $t('post.actions.more.delete')}
|
||||
@@ -177,19 +151,14 @@
|
||||
if (hidden) onhide?.(hidden)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
icon={XMark}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={XMark} size="16" micro />
|
||||
{/snippet}
|
||||
{post.hidden
|
||||
? $t('post.actions.more.unhide')
|
||||
: $t('post.actions.more.hide')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton onclick={() => report(post)} color="danger-subtle">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Flag} size="16" micro />
|
||||
{/snippet}
|
||||
<MenuButton onclick={() => report(post)} color="danger-subtle" icon={Flag}>
|
||||
{$t('moderation.report')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<script lang="ts">
|
||||
import type { PostView } from '$lib/client/types'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import type { PostView } from '$lib/client/types'
|
||||
import { Button } from 'mono-svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { ArchiveBox, Icon, Plus } from 'svelte-hero-icons'
|
||||
import { ArchiveBox, Plus } from 'svelte-hero-icons'
|
||||
import { Post } from '..'
|
||||
|
||||
interface Props {
|
||||
@@ -26,10 +26,7 @@
|
||||
title="No posts"
|
||||
description="There are no posts that match this filter."
|
||||
>
|
||||
<Button href="/communities">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Plus} size="16" mini />
|
||||
{/snippet}
|
||||
<Button href="/communities" icon={Plus}>
|
||||
<span>Follow some communities</span>
|
||||
</Button>
|
||||
</Placeholder>
|
||||
|
||||
@@ -181,10 +181,12 @@
|
||||
title={$t('routes.frontpage.empty.title')}
|
||||
description={$t('routes.frontpage.empty.description')}
|
||||
>
|
||||
<Button href="/communities" rounding="pill" color="primary">
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowTopRightOnSquare} size="16" mini />
|
||||
{/snippet}
|
||||
<Button
|
||||
href="/communities"
|
||||
rounding="pill"
|
||||
color="primary"
|
||||
icon={ArrowTopRightOnSquare}
|
||||
>
|
||||
{$t('nav.communities')}
|
||||
</Button>
|
||||
</Placeholder>
|
||||
@@ -265,10 +267,7 @@
|
||||
community_name: feedData.community_name ?? 'undefined',
|
||||
})}
|
||||
{#snippet action()}
|
||||
<Button color="tertiary">
|
||||
{#snippet prefix()}
|
||||
<Icon src={ChevronDoubleUp} size="16" micro />
|
||||
{/snippet}
|
||||
<Button color="tertiary" icon={ChevronDoubleUp}>
|
||||
{$t('routes.post.scrollToTop')}
|
||||
</Button>
|
||||
{/snippet}
|
||||
|
||||
@@ -360,10 +360,8 @@
|
||||
size="sm"
|
||||
color={data.alt_text ? 'primary' : 'ghost'}
|
||||
class="text-xs"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={ChatBubbleBottomCenterText} size="15" micro />
|
||||
{/snippet}{$t('form.post.altText')}
|
||||
icon={ChatBubbleBottomCenterText}
|
||||
>{$t('form.post.altText')}
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
@@ -372,10 +370,8 @@
|
||||
size="sm"
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
icon={Photo}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Photo} size="15" micro />
|
||||
{/snippet}
|
||||
{$t('form.post.uploadImage')}
|
||||
</Button>
|
||||
{#if generation.generatable}
|
||||
@@ -386,10 +382,8 @@
|
||||
size="sm"
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
icon={Sparkles}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Sparkles} size="15" micro />
|
||||
{/snippet}
|
||||
{$t('form.post.generateTitle')}
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
Reference in new issue
Block a user