migrate: convert most components to svelte 5
This commit is contained in:
1 parent
d670f39f0a
commit
10ef4123da
225 files changed
+5441
-3341
No files matched your search
@@ -31,26 +31,6 @@
|
||||
import { profile } from '$lib/auth'
|
||||
import { goto } from '$app/navigation'
|
||||
|
||||
export let post: PostView
|
||||
export let actions: boolean = true
|
||||
export let hideCommunity = false
|
||||
export let view = $userSettings.view
|
||||
|
||||
$: tags = parseTags(post.post.name)
|
||||
$: type = mediaType(post.post.url, view)
|
||||
$: rule = getTagRule(tags.tags)
|
||||
|
||||
$: hideTitle =
|
||||
$userSettings.posts.deduplicateEmbed &&
|
||||
post.post.embed_title == post.post.name &&
|
||||
view != 'compact' &&
|
||||
type != 'iframe'
|
||||
|
||||
$: hideBody =
|
||||
$userSettings.posts.deduplicateEmbed &&
|
||||
post.post.embed_description == post.post.body &&
|
||||
view != 'compact'
|
||||
|
||||
function getTagRule(tags: Tag[]): 'blur' | 'hide' | undefined {
|
||||
const tagContent = tags.map((t) => t.content.toLowerCase())
|
||||
|
||||
@@ -75,9 +55,40 @@
|
||||
}
|
||||
}
|
||||
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
post: PostView
|
||||
actions?: boolean
|
||||
hideCommunity?: boolean
|
||||
view?: any
|
||||
style?: string
|
||||
class?: string
|
||||
badges?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
post,
|
||||
actions = true,
|
||||
hideCommunity = false,
|
||||
view = $userSettings.view,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
badges,
|
||||
}: Props = $props()
|
||||
|
||||
let tags = $derived(parseTags(post.post.name))
|
||||
let type = $derived(mediaType(post.post.url, view))
|
||||
let rule = $derived(getTagRule(tags.tags))
|
||||
let hideTitle = $derived(
|
||||
$userSettings.posts.deduplicateEmbed &&
|
||||
post.post.embed_title == post.post.name &&
|
||||
view != 'compact' &&
|
||||
type != 'iframe',
|
||||
)
|
||||
let hideBody = $derived(
|
||||
$userSettings.posts.deduplicateEmbed &&
|
||||
post.post.embed_description == post.post.body &&
|
||||
view != 'compact',
|
||||
)
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -85,9 +96,9 @@
|
||||
This is the sole component for displaying posts.
|
||||
It adapts to all kinds of form factors for different contexts, such as feeds, full post view, and crosspost list.
|
||||
-->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
||||
<div
|
||||
class="post relative max-w-full min-w-0 w-full cursor-pointer outline-none
|
||||
group
|
||||
@@ -97,10 +108,10 @@
|
||||
{view == 'cozy' ? 'py-5 flex flex-col gap-2' : ''}
|
||||
{clazz ?? ''}"
|
||||
id={post.post.id.toString()}
|
||||
on:click={(e) => {
|
||||
onclick={(e) => {
|
||||
onClick(e)
|
||||
}}
|
||||
on:keydown={(e) => {
|
||||
onkeydown={(e) => {
|
||||
// @ts-ignore
|
||||
if (e.key == 'Enter') onClick(e)
|
||||
}}
|
||||
@@ -135,7 +146,9 @@
|
||||
tags={tags?.tags}
|
||||
{view}
|
||||
>
|
||||
<slot name="badges" slot="badges" />
|
||||
{#snippet extraBadges()}
|
||||
{@render badges?.()}
|
||||
{/snippet}
|
||||
</PostMeta>
|
||||
{#key post.post.url}
|
||||
<div
|
||||
@@ -178,11 +191,15 @@
|
||||
{:else if view == 'compact'}
|
||||
<div class="flex flex-row items-center gap-2 text-sm">
|
||||
<Badge>
|
||||
<Icon src={ArrowUp} slot="icon" size="14" micro />
|
||||
{#snippet icon()}
|
||||
<Icon src={ArrowUp} size="14" micro />
|
||||
{/snippet}
|
||||
{post.counts.score}
|
||||
</Badge>
|
||||
<Badge>
|
||||
<Icon src={ChatBubbleOvalLeft} slot="icon" size="14" micro />
|
||||
{#snippet icon()}
|
||||
<Icon src={ChatBubbleOvalLeft} size="14" micro />
|
||||
{/snippet}
|
||||
{post.counts.comments}
|
||||
</Badge>
|
||||
</div>
|
||||
@@ -194,7 +211,7 @@
|
||||
group-hover:inset-y-0.5 group-hover:-inset-x-4 group-hover:sm:-inset-x-5 group-hover:opacity-100
|
||||
group-focus:inset-y-0.5 group-focus:-inset-x-4 group-focus:sm:-inset-x-5 group-focus:opacity-100
|
||||
duration-150"
|
||||
/>
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<style lang="postcss">
|
||||
|
||||
@@ -67,28 +67,37 @@
|
||||
formatRelativeDate,
|
||||
} from '$lib/components/util/RelativeDate.svelte'
|
||||
|
||||
export let post: PostView
|
||||
export let view: View = 'cozy'
|
||||
export let debug: boolean = false
|
||||
|
||||
const dispatcher = createEventDispatcher<{ edit: PostView; hide: boolean }>()
|
||||
|
||||
let editing = false
|
||||
let saving = false
|
||||
let editing = $state(false)
|
||||
let saving = $state(false)
|
||||
|
||||
let translating = false
|
||||
let translating = $state(false)
|
||||
|
||||
let localShare = false
|
||||
let localShare = $state(false)
|
||||
|
||||
$: buttonHeight = view == 'compact' ? 'h-7' : 'h-8'
|
||||
$: buttonSquare = view == 'compact' ? 'w-7 h-7' : 'w-8 h-8'
|
||||
interface Props {
|
||||
post: PostView
|
||||
view?: View
|
||||
debug?: boolean
|
||||
style?: string
|
||||
}
|
||||
|
||||
export let style: string = ''
|
||||
let {
|
||||
post = $bindable(),
|
||||
view = 'cozy',
|
||||
debug = $bindable(false),
|
||||
style = '',
|
||||
}: Props = $props()
|
||||
let buttonHeight = $derived(view == 'compact' ? 'h-7' : 'h-8')
|
||||
let buttonSquare = $derived(view == 'compact' ? 'w-7 h-7' : 'w-8 h-8')
|
||||
</script>
|
||||
|
||||
{#if editing}
|
||||
<Modal bind:open={editing}>
|
||||
<h1 slot="title" class="text-2xl font-bold">Editing post</h1>
|
||||
{#snippet customTitle()}
|
||||
<h1 class="text-2xl font-bold">Editing post</h1>
|
||||
{/snippet}
|
||||
{#await import('./form/PostForm.svelte')}
|
||||
<div class="mx-auto h-96 flex justify-center items-center">
|
||||
<Spinner width={32} />
|
||||
@@ -103,10 +112,10 @@
|
||||
dispatcher('edit', e.detail)
|
||||
}}
|
||||
>
|
||||
<svelte:fragment slot="formtitle">
|
||||
{#snippet formtitle()}
|
||||
<!-- Have the title not exist at all -->
|
||||
{''}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</PostForm>
|
||||
{/await}
|
||||
</Modal>
|
||||
@@ -152,7 +161,7 @@
|
||||
/>
|
||||
<FormattedNumber number={post.counts.comments} />
|
||||
</Button>
|
||||
<div class="flex-1" />
|
||||
<div class="flex-1"></div>
|
||||
|
||||
{#if $userSettings.debugInfo}
|
||||
{#if debug}
|
||||
@@ -169,7 +178,9 @@
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
<Icon src={BugAnt} micro size="16" slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={BugAnt} micro size="16" />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if $profile?.user && (amMod($profile.user, post.community) || isAdmin($profile.user))}
|
||||
@@ -200,12 +211,9 @@
|
||||
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
<Icon
|
||||
src={post.saved ? BookmarkSlash : Bookmark}
|
||||
size="16"
|
||||
mini
|
||||
slot="prefix"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.saved ? BookmarkSlash : Bookmark} size="16" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
@@ -216,21 +224,26 @@
|
||||
targetClass="h-full"
|
||||
title={$t('post.actions.more.label')}
|
||||
>
|
||||
<Button
|
||||
slot="target"
|
||||
title={$t('post.actions.more.label')}
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
<Icon slot="prefix" src={EllipsisHorizontal} width={16} micro />
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
title={$t('post.actions.more.label')}
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} width={16} micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('cards.site.stats')}</MenuDivider>
|
||||
<div class="flex flex-row gap-1 items-center">
|
||||
<MenuButton class="flex-1">
|
||||
<Icon src={Clock} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Clock} size="16" micro />
|
||||
{/snippet}
|
||||
<span>
|
||||
{publishedToDate(post.post.published).toLocaleDateString(undefined, {
|
||||
dateStyle: 'short',
|
||||
@@ -242,10 +255,12 @@
|
||||
publishedToDate(post.post.updated),
|
||||
{
|
||||
style: 'long',
|
||||
}
|
||||
},
|
||||
)}
|
||||
<MenuButton class="flex-1" aria-label={editedTime}>
|
||||
<Icon src={Pencil} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Pencil} size="16" micro />
|
||||
{/snippet}
|
||||
<RelativeDate date={publishedToDate(post.post.updated)} />
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -256,7 +271,9 @@
|
||||
<MenuButton
|
||||
aria-label={$t('aria.vote.score', { default: post.counts.score })}
|
||||
>
|
||||
<Icon src={ArrowsUpDown} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowsUpDown} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.vote.score')}
|
||||
•
|
||||
<FormattedNumber
|
||||
@@ -276,25 +293,17 @@
|
||||
{/if}
|
||||
<MenuDivider>{$t('post.actions.more.creator')}</MenuDivider>
|
||||
<MenuButton link href={userLink(post.creator)}>
|
||||
<Icon
|
||||
src={UserCircle}
|
||||
size="16"
|
||||
micro
|
||||
slot="prefix"
|
||||
class="flex-shrink-0"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserCircle} size="16" micro class="flex-shrink-0" />
|
||||
{/snippet}
|
||||
<TextProps wrap="no-wrap">
|
||||
{post.creator.name}
|
||||
</TextProps>
|
||||
</MenuButton>
|
||||
<MenuButton link href={communityLink(post.community)}>
|
||||
<Icon
|
||||
src={Newspaper}
|
||||
size="16"
|
||||
micro
|
||||
slot="prefix"
|
||||
class="flex-shrink-0"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Newspaper} size="16" micro class="flex-shrink-0" />
|
||||
{/snippet}
|
||||
<TextProps wrap="no-wrap">
|
||||
{post.community.title}
|
||||
</TextProps>
|
||||
@@ -304,7 +313,9 @@
|
||||
</MenuDivider>
|
||||
{#if $profile?.user && $profile?.jwt && $profile.user.local_user_view.person.id == post.creator.id}
|
||||
<MenuButton on:click={() => (editing = true)}>
|
||||
<Icon src={PencilSquare} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.edit')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -315,7 +326,9 @@
|
||||
post.read = await markAsRead(post.post, !post.read, $profile.jwt)
|
||||
}}
|
||||
>
|
||||
<Icon slot="prefix" src={post.read ? EyeSlash : Eye} size="16" micro />
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.read ? EyeSlash : Eye} size="16" micro />
|
||||
{/snippet}
|
||||
{post.read
|
||||
? $t('post.actions.more.markUnread')
|
||||
: $t('post.actions.more.markRead')}
|
||||
@@ -331,15 +344,17 @@
|
||||
navigator.clipboard.writeText(
|
||||
localShare
|
||||
? `${instanceToURL(getInstance())}/post/${post.post.id}`
|
||||
: post.post.ap_id
|
||||
: post.post.ap_id,
|
||||
)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
class="flex-1 !py-0"
|
||||
>
|
||||
<Icon src={Share} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.share')}
|
||||
<div class="flex-1" />
|
||||
<div class="flex-1"></div>
|
||||
{#if !post.post.local}
|
||||
<div class="flex">
|
||||
<Button
|
||||
@@ -371,7 +386,9 @@
|
||||
translating = !translating
|
||||
}}
|
||||
>
|
||||
<Icon src={Language} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Language} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.translate')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -399,7 +416,9 @@
|
||||
goto('/create/post?crosspost=true')
|
||||
}}
|
||||
>
|
||||
<Icon src={ArrowTopRightOnSquare} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowTopRightOnSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.crosspost')}
|
||||
</MenuButton>
|
||||
{#if $profile.user && post.creator.id == $profile.user.local_user_view.person.id}
|
||||
@@ -409,12 +428,14 @@
|
||||
post.post.deleted = await deleteItem(
|
||||
post,
|
||||
!post.post.deleted,
|
||||
$profile.jwt
|
||||
$profile.jwt,
|
||||
)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
>
|
||||
<Icon src={Trash} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Trash} size="16" micro />
|
||||
{/snippet}
|
||||
{post.post.deleted
|
||||
? $t('post.actions.more.restore')
|
||||
: $t('post.actions.more.delete')}
|
||||
@@ -428,7 +449,7 @@
|
||||
const hidden = await hidePost(
|
||||
post.post.id,
|
||||
!post.hidden,
|
||||
$profile?.jwt
|
||||
$profile?.jwt,
|
||||
)
|
||||
post.hidden = hidden
|
||||
if (hidden) {
|
||||
@@ -437,14 +458,18 @@
|
||||
}}
|
||||
color="danger-subtle"
|
||||
>
|
||||
<Icon slot="prefix" src={XMark} size="16" micro />
|
||||
{#snippet prefix()}
|
||||
<Icon src={XMark} size="16" micro />
|
||||
{/snippet}
|
||||
{post.hidden
|
||||
? $t('post.actions.more.unhide')
|
||||
: $t('post.actions.more.hide')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton on:click={() => report(post)} color="danger-subtle">
|
||||
<Icon src={Flag} width={16} micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Flag} width={16} micro />
|
||||
{/snippet}
|
||||
{$t('moderation.report')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -4,15 +4,8 @@
|
||||
import { Button } from 'mono-svelte'
|
||||
import { ChevronDown, Icon } from 'svelte-hero-icons'
|
||||
|
||||
export let body: string
|
||||
export let view: View = 'cozy'
|
||||
export let clickThrough = false
|
||||
let htmlElement = 'div'
|
||||
|
||||
export { htmlElement as element }
|
||||
|
||||
let expanded = false
|
||||
let element: Element
|
||||
let expanded = $state(false)
|
||||
let element: Element = $state()
|
||||
|
||||
function isOverflown(element: Element, body: string = '') {
|
||||
if (!element) return
|
||||
@@ -26,11 +19,25 @@
|
||||
return overflows
|
||||
}
|
||||
|
||||
$: overflows = isOverflown(element, body)
|
||||
interface Props {
|
||||
body: string
|
||||
view?: View
|
||||
clickThrough?: boolean
|
||||
element?: string
|
||||
style?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
body,
|
||||
view = 'cozy',
|
||||
clickThrough = false,
|
||||
element: htmlElement = 'div',
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
let overflows = $derived(isOverflown(element, body))
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
export interface Tag {
|
||||
content: string
|
||||
color?: string
|
||||
@@ -12,7 +12,7 @@
|
||||
])
|
||||
|
||||
export const parseTags = (
|
||||
title?: string
|
||||
title?: string,
|
||||
): { tags: Tag[]; title?: string } => {
|
||||
if (!title) return { tags: [] }
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
extracted.push(
|
||||
textToTag.get(content) ?? {
|
||||
content: content,
|
||||
}
|
||||
},
|
||||
)
|
||||
})
|
||||
return ''
|
||||
@@ -43,6 +43,8 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { stopPropagation } from 'svelte/legacy'
|
||||
|
||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import { Badge, Popover } from 'mono-svelte'
|
||||
@@ -70,37 +72,53 @@
|
||||
import CommunityHeader from '../community/CommunityHeader.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date'
|
||||
|
||||
export let community: Community | undefined = undefined
|
||||
export let showCommunity: boolean = true
|
||||
export let subscribed: SubscribedType | undefined = undefined
|
||||
let popoverOpen = $state(false)
|
||||
|
||||
export let user: Person | undefined = undefined
|
||||
export let published: Date | undefined = undefined
|
||||
export let title: string | undefined = undefined
|
||||
export let id: number | undefined = undefined
|
||||
export let read: boolean = false
|
||||
export let edited: string | undefined = undefined
|
||||
|
||||
export let view: View = 'cozy'
|
||||
|
||||
// Badges
|
||||
export let badges = {
|
||||
nsfw: false,
|
||||
saved: false,
|
||||
featured: false,
|
||||
deleted: false,
|
||||
removed: false,
|
||||
locked: false,
|
||||
moderator: false,
|
||||
admin: false,
|
||||
interface Props {
|
||||
community?: Community | undefined
|
||||
showCommunity?: boolean
|
||||
subscribed?: SubscribedType | undefined
|
||||
user?: Person | undefined
|
||||
published?: Date | undefined
|
||||
title?: string | undefined
|
||||
id?: number | undefined
|
||||
read?: boolean
|
||||
edited?: string | undefined
|
||||
view?: View
|
||||
// Badges
|
||||
badges?: any
|
||||
tags?: Tag[]
|
||||
style?: string
|
||||
titleClass?: string
|
||||
extraBadges?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
export let tags: Tag[] = []
|
||||
|
||||
let popoverOpen = false
|
||||
|
||||
export let style: string = ''
|
||||
export let titleClass: string = ''
|
||||
let {
|
||||
community = $bindable(undefined),
|
||||
showCommunity = true,
|
||||
subscribed = $bindable(undefined),
|
||||
user = undefined,
|
||||
published = undefined,
|
||||
title = undefined,
|
||||
id = undefined,
|
||||
read = false,
|
||||
edited = undefined,
|
||||
view = 'cozy',
|
||||
badges = {
|
||||
nsfw: false,
|
||||
saved: false,
|
||||
featured: false,
|
||||
deleted: false,
|
||||
removed: false,
|
||||
locked: false,
|
||||
moderator: false,
|
||||
admin: false,
|
||||
},
|
||||
tags = [],
|
||||
style = '',
|
||||
titleClass = '',
|
||||
extraBadges,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -114,32 +132,36 @@
|
||||
class:compact={view == 'compact'}
|
||||
{style}
|
||||
>
|
||||
{#if showCommunity && community && subscribed && showCommunity}
|
||||
{#if showCommunity && community != undefined && subscribed}
|
||||
<Popover bind:open={popoverOpen} manual>
|
||||
<button
|
||||
on:click={() => (popoverOpen = !popoverOpen)}
|
||||
class="relative cursor-pointer row-span-2 flex-shrink-0 pr-2 group/community"
|
||||
slot="target"
|
||||
>
|
||||
<Avatar
|
||||
url={community.icon}
|
||||
width={view == 'compact' ? 24 : 32}
|
||||
alt={community.name}
|
||||
class="group-hover/community:ring-2 transition-all ring-offset-0 ring-primary-900 dark:ring-primary-100"
|
||||
/>
|
||||
</button>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<div
|
||||
slot="popover"
|
||||
class="max-w-md rounded-2xl bg-white dark:bg-zinc-950"
|
||||
on:click|stopPropagation={() => {}}
|
||||
>
|
||||
<CommunityHeader bind:community bind:subscribed />
|
||||
</div>
|
||||
{#snippet target()}
|
||||
<button
|
||||
onclick={() => (popoverOpen = !popoverOpen)}
|
||||
class="relative cursor-pointer row-span-2 flex-shrink-0 pr-2 group/community"
|
||||
>
|
||||
<Avatar
|
||||
url={community?.icon}
|
||||
width={view == 'compact' ? 24 : 32}
|
||||
alt={community?.name}
|
||||
class="group-hover/community:ring-2 transition-all ring-offset-0 ring-primary-900 dark:ring-primary-100"
|
||||
/>
|
||||
</button>
|
||||
{/snippet}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
{#snippet popover()}
|
||||
{#if community && subscribed}
|
||||
<div
|
||||
class="max-w-md rounded-2xl bg-white dark:bg-zinc-950"
|
||||
onclick={stopPropagation(() => {})}
|
||||
>
|
||||
<CommunityHeader bind:community bind:subscribed />
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Popover>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
{/if}
|
||||
{#if showCommunity && community}
|
||||
<CommunityLink
|
||||
@@ -174,14 +196,14 @@
|
||||
avatar={!showCommunity}
|
||||
class="flex-shrink "
|
||||
>
|
||||
<svelte:fragment slot="badges">
|
||||
{#snippet extraBadges()}
|
||||
{#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>
|
||||
{/snippet}
|
||||
</UserLink>
|
||||
</address>
|
||||
{/if}
|
||||
@@ -213,13 +235,13 @@
|
||||
style={tag.color ? `--tag-color: ${tag.color};` : ''}
|
||||
>
|
||||
<Badge class={tag.color ? 'badge-tag-color' : ''}>
|
||||
<svelte:fragment slot="icon">
|
||||
{#snippet icon()}
|
||||
{#if tag.icon}
|
||||
<Icon src={tag.icon} micro size="14" />
|
||||
{:else}
|
||||
<Icon src={Tag} micro size="14" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
{tag.content}
|
||||
</Badge>
|
||||
</a>
|
||||
@@ -227,7 +249,9 @@
|
||||
{/if}
|
||||
{#if badges.nsfw}
|
||||
<Badge label={$t('post.badges.nsfw')} color="red-subtle" allowIconOnly>
|
||||
<Icon src={ExclamationTriangle} size="14" micro slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={ExclamationTriangle} size="14" micro />
|
||||
{/snippet}
|
||||
{$t('post.badges.nsfw')}
|
||||
</Badge>
|
||||
{/if}
|
||||
@@ -237,7 +261,9 @@
|
||||
color="yellow-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
<Icon src={Bookmark} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Bookmark} micro size="14" />
|
||||
{/snippet}
|
||||
{$t('post.badges.saved')}
|
||||
</Badge>
|
||||
{/if}
|
||||
@@ -247,19 +273,25 @@
|
||||
color="yellow-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
<Icon src={LockClosed} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={LockClosed} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.locked')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if badges.removed}
|
||||
<Badge label={$t('post.badges.removed')} color="red-subtle" allowIconOnly>
|
||||
<Icon src={Trash} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Trash} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.removed')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if badges.deleted}
|
||||
<Badge label={$t('post.badges.deleted')} color="red-subtle" allowIconOnly>
|
||||
<Icon src={Trash} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Trash} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.deleted')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
@@ -269,11 +301,13 @@
|
||||
color="green-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
<Icon src={Megaphone} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Megaphone} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.featured')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
<slot name="badges" />
|
||||
{@render extraBadges?.()}
|
||||
</div>
|
||||
</header>
|
||||
{#if title && id}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
export const voteColor = (vote: number, border: boolean = false) =>
|
||||
vote == 1
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
export const shouldShowVoteColor = (
|
||||
vote: number,
|
||||
type: 'upvotes' | 'downvotes'
|
||||
type: 'upvotes' | 'downvotes',
|
||||
): string =>
|
||||
(vote == -1 && type == 'downvotes') || (vote == 1 && type == 'upvotes')
|
||||
? voteColor(vote)
|
||||
@@ -29,15 +29,27 @@
|
||||
import { t } from '$lib/translations'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
|
||||
export let post: Post
|
||||
export let vote: number = 0
|
||||
export let score: number
|
||||
export let upvotes: number = 0
|
||||
export let downvotes: number = 0
|
||||
interface Props {
|
||||
post: Post
|
||||
vote?: number
|
||||
score: number
|
||||
upvotes?: number
|
||||
downvotes?: number
|
||||
showCounts?: boolean
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
}
|
||||
|
||||
export let showCounts: boolean = true
|
||||
let {
|
||||
post,
|
||||
vote = $bindable(0),
|
||||
score = $bindable(),
|
||||
upvotes = $bindable(0),
|
||||
downvotes = $bindable(0),
|
||||
showCounts = true,
|
||||
children,
|
||||
}: Props = $props()
|
||||
|
||||
let loading = false
|
||||
let loading = $state(false)
|
||||
|
||||
let oldScore = score
|
||||
|
||||
@@ -58,7 +70,7 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<slot {vote} {score}>
|
||||
{#if children}{@render children({ vote, score })}{:else}
|
||||
<div
|
||||
class="{buttonColor.ghost} rounded-full h-full font-medium flex items-center *:p-2
|
||||
hover:bg-white hover:dark:bg-zinc-900 overflow-hidden transition-colors flex-shrink-0
|
||||
@@ -70,7 +82,7 @@
|
||||
aria-label={$t('aria.vote.group')}
|
||||
>
|
||||
<button
|
||||
on:click={() => castVote(vote == 1 ? 0 : 1)}
|
||||
onclick={() => castVote(vote == 1 ? 0 : 1)}
|
||||
class="flex items-center gap-0.5 transition-colors relative z-0
|
||||
{vote == 1
|
||||
? shouldShowVoteColor(vote, 'upvotes')
|
||||
@@ -96,7 +108,7 @@
|
||||
</button>
|
||||
{#if $site?.site_view.local_site.enable_downvotes ?? true}
|
||||
<button
|
||||
on:click={() => castVote(vote == -1 ? 0 : -1)}
|
||||
onclick={() => castVote(vote == -1 ? 0 : -1)}
|
||||
class="flex items-center flex-row-reverse gap-0.5 transition-colors
|
||||
{vote == -1
|
||||
? shouldShowVoteColor(vote, 'downvotes')
|
||||
@@ -122,4 +134,4 @@
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</slot>
|
||||
{/if}
|
||||
@@ -9,14 +9,26 @@
|
||||
import { fly, slide } from 'svelte/transition'
|
||||
import { combineCrossposts } from './crosspost'
|
||||
|
||||
export let posts: PostView[]
|
||||
export let community: boolean = false
|
||||
export let feedData: any
|
||||
let etc = $$restProps
|
||||
interface Props {
|
||||
posts: PostView[]
|
||||
community?: boolean
|
||||
feedData: any
|
||||
children?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
$: combinedPosts = combineCrossposts(posts)
|
||||
let {
|
||||
posts = $bindable(),
|
||||
community = false,
|
||||
feedData,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
let etc = rest
|
||||
|
||||
let viewPost: number = -1
|
||||
let combinedPosts = $derived(combineCrossposts(posts))
|
||||
|
||||
let viewPost: number = $state(-1)
|
||||
</script>
|
||||
|
||||
<ul
|
||||
@@ -32,7 +44,9 @@
|
||||
description="There are no posts that match this filter."
|
||||
>
|
||||
<Button href="/communities">
|
||||
<Icon src={Plus} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Plus} size="16" mini />
|
||||
{/snippet}
|
||||
<span>Follow some communities</span>
|
||||
</Button>
|
||||
</Placeholder>
|
||||
@@ -53,10 +67,10 @@
|
||||
posts = posts.toSpliced(index, 1)
|
||||
}}
|
||||
>
|
||||
<svelte:fragment slot="badges">
|
||||
{#snippet badges()}
|
||||
{#if post.withCrossposts}
|
||||
<button
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
if (viewPost == post.post.id) viewPost = -1
|
||||
else viewPost = post.post.id
|
||||
}}
|
||||
@@ -76,7 +90,7 @@
|
||||
: 's'}
|
||||
</Badge>
|
||||
</button>{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</Post>
|
||||
{#if post.withCrossposts && viewPost == post.post.id}
|
||||
<div
|
||||
@@ -104,5 +118,5 @@
|
||||
{/if}
|
||||
{/each}
|
||||
{/if}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</ul>
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
@@ -20,7 +22,7 @@
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fly, slide } from 'svelte/transition'
|
||||
import { browser } from '$app/environment'
|
||||
import { afterUpdate, onMount, tick, type SvelteComponent } from 'svelte'
|
||||
import { onMount, tick, type SvelteComponent } from 'svelte'
|
||||
import {
|
||||
createVirtualizer,
|
||||
createWindowVirtualizer,
|
||||
@@ -39,12 +41,28 @@
|
||||
import type { Readable } from 'svelte/motion'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
|
||||
export let posts: PostView[]
|
||||
export let community: boolean = false
|
||||
export let feedId: PostFeedID
|
||||
let virtualItemEls: HTMLElement[] = $state([])
|
||||
let virtualListEl: HTMLElement | undefined = $state(undefined)
|
||||
|
||||
let virtualItemEls: HTMLElement[] = []
|
||||
let virtualListEl: HTMLElement | undefined = undefined
|
||||
afterNavigate(() => {
|
||||
$virtualizer.scrollToIndex($postFeeds[feedId]?.lastSeen ?? 0)
|
||||
})
|
||||
|
||||
interface Props {
|
||||
posts: PostView[]
|
||||
community?: boolean
|
||||
feedId: PostFeedID
|
||||
feedData: PostFeed['data']
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
posts = $bindable(),
|
||||
community = false,
|
||||
feedId,
|
||||
feedData = $bindable(),
|
||||
children,
|
||||
}: Props = $props()
|
||||
|
||||
const virtualizer = createWindowVirtualizer({
|
||||
count: posts.length,
|
||||
@@ -55,27 +73,9 @@
|
||||
},
|
||||
})
|
||||
|
||||
$: items = $virtualizer.getVirtualItems()
|
||||
|
||||
$: if (virtualItemEls.length) {
|
||||
virtualItemEls.forEach($virtualizer.measureElement)
|
||||
}
|
||||
|
||||
$: if (posts.length && virtualListEl)
|
||||
$virtualizer.setOptions({
|
||||
scrollMargin: virtualListEl?.offsetTop,
|
||||
count: posts.length,
|
||||
})
|
||||
|
||||
afterNavigate(() => {
|
||||
$virtualizer.scrollToIndex($postFeeds[feedId]?.lastSeen ?? 0)
|
||||
})
|
||||
|
||||
export let feedData: PostFeed['data']
|
||||
|
||||
let error: any = undefined
|
||||
let loading = false
|
||||
let hasMore = true
|
||||
let error: any = $state(undefined)
|
||||
let loading = $state(false)
|
||||
let hasMore = $state(true)
|
||||
|
||||
async function loadMore() {
|
||||
if (!hasMore || loading) return
|
||||
@@ -181,6 +181,19 @@
|
||||
await tick()
|
||||
$virtualizer.measure()
|
||||
})
|
||||
let items = $derived($virtualizer.getVirtualItems())
|
||||
run(() => {
|
||||
if (virtualItemEls.length) {
|
||||
virtualItemEls.forEach($virtualizer.measureElement)
|
||||
}
|
||||
})
|
||||
run(() => {
|
||||
if (posts.length && virtualListEl)
|
||||
$virtualizer.setOptions({
|
||||
scrollMargin: virtualListEl?.offsetTop,
|
||||
count: posts.length,
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<!-- <svelte:window on:keydown={handleKeydown} /> -->
|
||||
@@ -198,7 +211,9 @@
|
||||
description="There are no posts that match this filter."
|
||||
>
|
||||
<Button href="/communities">
|
||||
<Icon src={Plus} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Plus} size="16" mini />
|
||||
{/snippet}
|
||||
<span>Follow some communities</span>
|
||||
</Button>
|
||||
</Placeholder>
|
||||
@@ -284,16 +299,20 @@
|
||||
// @ts-ignore
|
||||
community_name: feedData.community_name ?? 'undefined',
|
||||
})}
|
||||
<Button slot="action" color="tertiary">
|
||||
<Icon src={ChevronDoubleUp} size="16" micro slot="prefix" />
|
||||
{$t('routes.post.scrollToTop')}
|
||||
</Button>
|
||||
{#snippet action()}
|
||||
<Button color="tertiary">
|
||||
{#snippet prefix()}
|
||||
<Icon src={ChevronDoubleUp} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('routes.post.scrollToTop')}
|
||||
</Button>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</div>
|
||||
{/if}
|
||||
<InfiniteScroll window threshold={1000} on:loadMore={loadMore} />
|
||||
{/if}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</ul>
|
||||
|
||||
<style lang="postcss">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { userSettings } from "$lib/settings"
|
||||
import type { PostView } from "lemmy-js-client"
|
||||
import { get } from "svelte/store"
|
||||
import { userSettings } from '$lib/settings.svelte'
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export type PostViewWithCrossposts = PostView & {
|
||||
withCrossposts: true
|
||||
@@ -54,4 +54,4 @@ export const combineCrossposts = (
|
||||
})
|
||||
|
||||
return results
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
|
||||
import { client, site } from '$lib/lemmy.js'
|
||||
import type { Community, Post, PostView } from 'lemmy-js-client'
|
||||
@@ -33,46 +35,56 @@
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import FreeTextInput from '$lib/components/input/FreeTextInput.svelte'
|
||||
|
||||
export let edit = false
|
||||
|
||||
/**
|
||||
* The post to edit
|
||||
*/
|
||||
export let editingPost: Post | undefined = undefined
|
||||
|
||||
export let passedCommunity: Community | undefined = undefined
|
||||
|
||||
export let data: {
|
||||
community: Community | null
|
||||
title: string
|
||||
body: string
|
||||
image: FileList | null
|
||||
thumbnail?: string
|
||||
url?: string
|
||||
nsfw: boolean
|
||||
loading: boolean
|
||||
alt_text?: string
|
||||
language_id?: number
|
||||
} = {
|
||||
community: null,
|
||||
title: '',
|
||||
body: '',
|
||||
image: null,
|
||||
thumbnail: undefined,
|
||||
url: undefined,
|
||||
nsfw: false,
|
||||
loading: false,
|
||||
alt_text: undefined,
|
||||
language_id: undefined,
|
||||
interface Props {
|
||||
edit?: boolean
|
||||
/**
|
||||
* The post to edit
|
||||
*/
|
||||
editingPost?: Post | undefined
|
||||
passedCommunity?: Community | undefined
|
||||
data?: {
|
||||
community: Community | null
|
||||
title: string
|
||||
body: string
|
||||
image: FileList | null
|
||||
thumbnail?: string
|
||||
url?: string
|
||||
nsfw: boolean
|
||||
loading: boolean
|
||||
alt_text?: string
|
||||
language_id?: number
|
||||
}
|
||||
formtitle?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
edit = false,
|
||||
editingPost = undefined,
|
||||
passedCommunity = undefined,
|
||||
data = $bindable({
|
||||
community: null,
|
||||
title: '',
|
||||
body: '',
|
||||
image: null,
|
||||
thumbnail: undefined,
|
||||
url: undefined,
|
||||
nsfw: false,
|
||||
loading: false,
|
||||
alt_text: undefined,
|
||||
language_id: undefined,
|
||||
}),
|
||||
formtitle,
|
||||
}: Props = $props()
|
||||
// weird select menu language handling
|
||||
// @ts-ignore
|
||||
$: if (data.language_id === '') data.language_id = undefined
|
||||
run(() => {
|
||||
if (data.language_id === '') data.language_id = undefined
|
||||
})
|
||||
|
||||
let saveDraft = edit ? false : true
|
||||
let communitySearch = passedCommunity?.name ?? ''
|
||||
let communitySearch = $state(passedCommunity?.name ?? '')
|
||||
|
||||
let communities: Community[] = []
|
||||
let communities: Community[] = $state([])
|
||||
|
||||
const dispatcher = createEventDispatcher<{ submit: PostView }>()
|
||||
|
||||
@@ -179,7 +191,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
let uploadingImage = false
|
||||
let uploadingImage = $state(false)
|
||||
|
||||
const generateTitle = async (url: string | undefined) => {
|
||||
if (!url) return
|
||||
@@ -224,15 +236,17 @@
|
||||
return true
|
||||
}
|
||||
|
||||
let generation = {
|
||||
let generation = $state({
|
||||
loading: false,
|
||||
generatable: false,
|
||||
title: '',
|
||||
}
|
||||
})
|
||||
|
||||
let addAltText = false
|
||||
let addAltText = $state(false)
|
||||
|
||||
$: generation.generatable = canGenerateTitle(data.url)
|
||||
run(() => {
|
||||
generation.generatable = canGenerateTitle(data.url)
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if uploadingImage}
|
||||
@@ -248,12 +262,12 @@
|
||||
{/await}
|
||||
{/if}
|
||||
|
||||
<form on:submit|preventDefault={submit} class="flex flex-col gap-4 h-full">
|
||||
<slot name="formtitle">
|
||||
<form onsubmit={preventDefault(submit)} class="flex flex-col gap-4 h-full">
|
||||
{#if formtitle}{@render formtitle()}{:else}
|
||||
<Header class="font-bold text-xl">
|
||||
{edit ? $t('form.post.edit') : $t('form.post.create')}
|
||||
</Header>
|
||||
</slot>
|
||||
{/if}
|
||||
<ErrorContainer scope="post-form" />
|
||||
{#if !edit && data}
|
||||
{#if !data.community}
|
||||
@@ -285,12 +299,13 @@
|
||||
alignment="left"
|
||||
size="sm"
|
||||
>
|
||||
<Avatar
|
||||
url={data.community.icon}
|
||||
alt={data.community.name}
|
||||
width={24}
|
||||
slot="prefix"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Avatar
|
||||
url={data.community.icon}
|
||||
alt={data.community.name}
|
||||
width={24}
|
||||
/>
|
||||
{/snippet}
|
||||
<div class="flex flex-col gap-0">
|
||||
<span class="text-xs">{data.community.name}</span>
|
||||
<span class="text-[10px] leading-3">
|
||||
@@ -326,7 +341,9 @@
|
||||
<div
|
||||
class="border border-slate-100 rounded-xl h-6 w-6 grid place-items-center"
|
||||
>
|
||||
<Icon src={Plus} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Plus} size="16" micro />
|
||||
{/snippet}
|
||||
</div>
|
||||
{#if data.url}
|
||||
<Button
|
||||
@@ -336,12 +353,9 @@
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon
|
||||
src={ChatBubbleBottomCenterText}
|
||||
size="15"
|
||||
micro
|
||||
slot="prefix"
|
||||
/>{$t('form.post.altText')}
|
||||
{#snippet prefix()}
|
||||
<Icon src={ChatBubbleBottomCenterText} size="15" micro />
|
||||
{/snippet}{$t('form.post.altText')}
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
@@ -351,7 +365,9 @@
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon src={Photo} size="15" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Photo} size="15" micro />
|
||||
{/snippet}
|
||||
{$t('form.post.uploadImage')}
|
||||
</Button>
|
||||
{#if generation.generatable}
|
||||
@@ -363,7 +379,9 @@
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon src={Sparkles} size="15" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Sparkles} size="15" micro />
|
||||
{/snippet}
|
||||
{$t('form.post.generateTitle')}
|
||||
</Button>
|
||||
{/if}
|
||||
@@ -433,7 +451,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
<div class="mt-auto" />
|
||||
<div class="mt-auto"></div>
|
||||
<div class="flex flex-row items-center gap-2 w-full">
|
||||
<Button
|
||||
submit
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { client, getInstance } from '$lib/lemmy.js'
|
||||
import type { View } from '$lib/settings'
|
||||
import type { View } from '$lib/settings.svelte'
|
||||
import { isImage, isVideo } from '$lib/ui/image'
|
||||
import { canParseUrl, findClosestNumber } from '$lib/util'
|
||||
import type { CommentView, PersonView, Post, PostView } from 'lemmy-js-client'
|
||||
@@ -10,7 +10,7 @@ export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
||||
export const bestImageURL = (
|
||||
post: Post,
|
||||
compact: boolean = true,
|
||||
width: number = 1024
|
||||
width: number = 1024,
|
||||
) => {
|
||||
if (post.thumbnail_url) return optimizeImageURL(post.thumbnail_url, width)
|
||||
else if (post.url) return optimizeImageURL(post.url, width)
|
||||
@@ -20,7 +20,7 @@ export const bestImageURL = (
|
||||
|
||||
export const optimizeImageURL = (
|
||||
urlStr: string,
|
||||
width: number = 1024
|
||||
width: number = 1024,
|
||||
): string => {
|
||||
try {
|
||||
const url = new URL(urlStr)
|
||||
@@ -32,8 +32,8 @@ export const optimizeImageURL = (
|
||||
'thumbnail',
|
||||
findClosestNumber(
|
||||
[128, 196, 256, 512, 728, 1024, 1536],
|
||||
width
|
||||
).toString()
|
||||
width,
|
||||
).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ export const iframeType = (url: string): IframeType => {
|
||||
export async function hidePost(
|
||||
id: number,
|
||||
hide: boolean,
|
||||
jwt: string
|
||||
jwt: string,
|
||||
): Promise<boolean> {
|
||||
const res = await client({ auth: jwt }).hidePost({
|
||||
hide: hide,
|
||||
|
||||
@@ -12,14 +12,25 @@
|
||||
import { t } from '$lib/translations'
|
||||
import type { View } from '$lib/settings'
|
||||
|
||||
export let url: string
|
||||
export let thumbnail_url: string | undefined = undefined
|
||||
export let nsfw: boolean = false
|
||||
export let embed_title: string | undefined = undefined
|
||||
export let embed_description: string | undefined = undefined
|
||||
export let view: View = 'cozy'
|
||||
interface Props {
|
||||
url: string
|
||||
thumbnail_url?: string | undefined
|
||||
nsfw?: boolean
|
||||
embed_title?: string | undefined
|
||||
embed_description?: string | undefined
|
||||
view?: View
|
||||
}
|
||||
|
||||
$: richURL = parseURL(url)
|
||||
let {
|
||||
url,
|
||||
thumbnail_url = undefined,
|
||||
nsfw = false,
|
||||
embed_title = undefined,
|
||||
embed_description = undefined,
|
||||
view = 'cozy',
|
||||
}: Props = $props()
|
||||
|
||||
let richURL = $derived(parseURL(url))
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -105,37 +116,39 @@
|
||||
rounded-full flex p-1 relative -top-7 min-[384px]:mx-3 mt-8 min-[384px]:mt-0 mx-auto -mb-7 w-max max-w-full overflow-auto"
|
||||
>
|
||||
<PostLinkSources {url}>
|
||||
<Button
|
||||
color="tertiary"
|
||||
slot="target"
|
||||
size="sm"
|
||||
class="w-max text-slate-600 dark:text-zinc-400 block
|
||||
text-xs flex-shrink-0"
|
||||
rounding="pill"
|
||||
>
|
||||
<Icon src={LinkIcon} size="16" micro class="flex-shrink-0" />
|
||||
{$t('post.actions.link.actions')}
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
color="tertiary"
|
||||
size="sm"
|
||||
class="w-max text-slate-600 dark:text-zinc-400 block
|
||||
text-xs flex-shrink-0"
|
||||
rounding="pill"
|
||||
>
|
||||
<Icon src={LinkIcon} size="16" micro class="flex-shrink-0" />
|
||||
{$t('post.actions.link.actions')}
|
||||
</Button>
|
||||
{/snippet}
|
||||
</PostLinkSources>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex space-x-1">
|
||||
<PostLinkSources {url}>
|
||||
<Button
|
||||
color="ghost"
|
||||
slot="target"
|
||||
size="xs"
|
||||
rounding="pill"
|
||||
class="p-0.5 px-1 w-max mt-auto text-slate-600 dark:text-zinc-400 block
|
||||
text-xs"
|
||||
>
|
||||
<div class="mr-0.5" style="width: 8px;">
|
||||
<Icon src={LinkIcon} size="16" micro />
|
||||
</div>
|
||||
<div class="mr-1" style="width: 8px;">
|
||||
<Icon src={ChevronDown} size="16" micro />
|
||||
</div>
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
color="ghost"
|
||||
size="xs"
|
||||
rounding="pill"
|
||||
class="p-0.5 px-1 w-max mt-auto text-slate-600 dark:text-zinc-400 block
|
||||
text-xs"
|
||||
>
|
||||
<div class="mr-0.5" style="width: 8px;">
|
||||
<Icon src={LinkIcon} size="16" micro />
|
||||
</div>
|
||||
<div class="mr-1" style="width: 8px;">
|
||||
<Icon src={ChevronDown} size="16" micro />
|
||||
</div>
|
||||
</Button>
|
||||
{/snippet}
|
||||
</PostLinkSources>
|
||||
<Button
|
||||
href={url}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
const sources: {
|
||||
getLink: (url: string) => string
|
||||
name: string
|
||||
@@ -43,12 +43,20 @@
|
||||
import type { MediaType } from '../helpers'
|
||||
import { Icon, Share } from 'svelte-hero-icons'
|
||||
|
||||
export let url: string
|
||||
export let type: MediaType = 'embed'
|
||||
interface Props {
|
||||
url: string
|
||||
type?: MediaType
|
||||
target?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let { url, type = 'embed', target, ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
<Menu {...$$restProps}>
|
||||
<slot name="target" slot="target" />
|
||||
<Menu {...rest}>
|
||||
{#snippet target()}
|
||||
{@render target?.()}
|
||||
{/snippet}
|
||||
|
||||
<MenuDivider>{$t('post.actions.link.title')}</MenuDivider>
|
||||
{#each sources as source}
|
||||
@@ -66,7 +74,9 @@
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
>
|
||||
<Icon src={Share} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.share')}
|
||||
</MenuButton>
|
||||
</Menu>
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
const youtubeDomain = (place: 'youtube' | 'invidious' | 'piped') => {
|
||||
switch (place) {
|
||||
case 'youtube': {
|
||||
@@ -37,12 +37,6 @@
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export let type: IframeType = 'none'
|
||||
export let thumbnail: string | undefined = undefined
|
||||
export let url: string
|
||||
export let opened = !$userSettings.embeds.clickToView
|
||||
export let autoplay: boolean = $userSettings.embeds.clickToView
|
||||
|
||||
const urlToEmbed = (inputUrl: string) => {
|
||||
if (type == 'video') {
|
||||
return inputUrl
|
||||
@@ -56,7 +50,7 @@
|
||||
if (autoplay) url.searchParams.set('autoplay', '1')
|
||||
|
||||
return `https://${youtubeDomain(
|
||||
$userSettings.embeds.youtube
|
||||
$userSettings.embeds.youtube,
|
||||
)}/embed/${videoID}?${url.searchParams.toString()}`
|
||||
}
|
||||
|
||||
@@ -64,7 +58,7 @@
|
||||
}
|
||||
|
||||
const typeData = (
|
||||
type: IframeType
|
||||
type: IframeType,
|
||||
): {
|
||||
icon: IconSource
|
||||
text: string
|
||||
@@ -91,11 +85,26 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: data = typeData(type)
|
||||
$: embedUrl = urlToEmbed(url)
|
||||
interface Props {
|
||||
type?: IframeType
|
||||
thumbnail?: string | undefined
|
||||
url: string
|
||||
opened?: any
|
||||
autoplay?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
type = 'none',
|
||||
thumbnail = undefined,
|
||||
url,
|
||||
opened = $bindable(!$userSettings.embeds.clickToView),
|
||||
autoplay = $userSettings.embeds.clickToView,
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
let data = $derived(typeData(type))
|
||||
let embedUrl = $derived(urlToEmbed(url))
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -104,7 +113,7 @@
|
||||
-->
|
||||
{#if opened}
|
||||
{#if type == 'video'}
|
||||
<!-- svelte-ignore a11y-media-has-caption -->
|
||||
<!-- svelte-ignore a11y_media_has_caption -->
|
||||
<video {autoplay} controls class="rounded-xl aspect-video {clazz}">
|
||||
<source src={url} />
|
||||
</video>
|
||||
@@ -116,11 +125,11 @@
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
allowfullscreen
|
||||
class="aspect-video rounded-xl dark:bg-zinc-900 {clazz ?? ''}"
|
||||
/>
|
||||
></iframe>
|
||||
{/if}
|
||||
{:else}
|
||||
<button
|
||||
on:click={() => (opened = true)}
|
||||
onclick={() => (opened = true)}
|
||||
class="aspect-video w-full h-full z-0 overflow-hidden relative rounded-xl flex flex-col gap-2 items-center justify-center text-white"
|
||||
>
|
||||
{#if thumbnail}
|
||||
@@ -132,7 +141,7 @@
|
||||
{:else}
|
||||
<div
|
||||
class="absolute blur-3xl -z-10 top-0 left-0 w-full h-full bg-gradient-to-br from-green-800 via-blue-900 via-20% to-red-700"
|
||||
/>
|
||||
></div>
|
||||
{/if}
|
||||
<Icon src={data.icon} solid size="48" />
|
||||
<h1 class="font-bold text-xl">{data.text}</h1>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { stopPropagation } from 'svelte/legacy'
|
||||
|
||||
import { userSettings, type View } from '$lib/settings'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import { bestImageURL, postLink } from '../helpers'
|
||||
@@ -6,10 +8,14 @@
|
||||
import { Button, modal } from 'mono-svelte'
|
||||
import { onMount } from 'svelte'
|
||||
|
||||
export let post: Post
|
||||
export let blur: boolean = false
|
||||
interface Props {
|
||||
post: Post
|
||||
blur?: boolean
|
||||
}
|
||||
|
||||
let imageLoaded: boolean | null = null
|
||||
let { post, blur = false }: Props = $props()
|
||||
|
||||
let imageLoaded: boolean | null = $state(null)
|
||||
|
||||
onMount(() => {
|
||||
imageLoaded = false
|
||||
@@ -23,11 +29,11 @@
|
||||
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900"
|
||||
data-sveltekit-preload-data="off"
|
||||
aria-label={post.name}
|
||||
on:click={() => showImage(bestImageURL(post, false, -1))}
|
||||
onclick={() => showImage(bestImageURL(post, false, -1))}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
loading="lazy"
|
||||
fetchpriority="auto"
|
||||
@@ -52,7 +58,7 @@
|
||||
srcset={bestImageURL(post, false, 1512)}
|
||||
media="(max-width: 1512px)"
|
||||
/>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
src={bestImageURL(post, false, -1)}
|
||||
loading="lazy"
|
||||
@@ -63,16 +69,16 @@
|
||||
height={300}
|
||||
class:blur-[64px]={blur}
|
||||
alt={post.alt_text ?? ''}
|
||||
on:load={() => (imageLoaded = true)}
|
||||
onload={() => (imageLoaded = true)}
|
||||
/>
|
||||
</picture>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="absolute bottom-0 left-0 right-0 flex justify-between items-center
|
||||
rounded-full ml-auto w-max m-2 p-0 gap-1
|
||||
*:bg-white *:border *:border-slate-200 *:dark:border-zinc-800 *:dark:bg-zinc-900"
|
||||
on:click|stopPropagation={() => {}}
|
||||
onclick={stopPropagation(() => {})}
|
||||
>
|
||||
{#if post.alt_text}
|
||||
<Button
|
||||
|
||||
@@ -18,11 +18,21 @@
|
||||
import { ArrowDownTray, Icon } from 'svelte-hero-icons'
|
||||
import PostImage from './PostImage.svelte'
|
||||
|
||||
export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy'
|
||||
export let post: Post
|
||||
export let type: MediaType = 'none'
|
||||
export let opened: boolean | undefined = undefined
|
||||
export let blur: boolean = post.nsfw && $userSettings.nsfwBlur
|
||||
interface Props {
|
||||
view?: 'card' | 'cozy' | 'list' | 'compact'
|
||||
post: Post
|
||||
type?: MediaType
|
||||
opened?: boolean | undefined
|
||||
blur?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
view = 'cozy',
|
||||
post,
|
||||
type = 'none',
|
||||
opened = undefined,
|
||||
blur = post.nsfw && $userSettings.nsfwBlur,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<!--
|
||||
|
||||
@@ -18,19 +18,28 @@
|
||||
ExclamationTriangle,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
export let post: Post
|
||||
export let type: MediaType = 'none'
|
||||
export let view: View = 'cozy'
|
||||
export let blur: boolean = post.nsfw && $userSettings.nsfwBlur
|
||||
|
||||
const thumbnailSize = (view: View) =>
|
||||
view == 'compact' ? 'w-22 h-22 sm:w-28' : 'w-24 h-24 sm:w-32'
|
||||
|
||||
$: size = thumbnailSize(view)
|
||||
interface Props {
|
||||
post: Post
|
||||
type?: MediaType
|
||||
view?: View
|
||||
blur?: boolean
|
||||
style?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
post,
|
||||
type = 'none',
|
||||
view = 'cozy',
|
||||
blur = post.nsfw && $userSettings.nsfwBlur,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
let size = $derived(thumbnailSize(view))
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -43,15 +52,16 @@
|
||||
openOnHover
|
||||
placement={$userSettings.leftAlign ? 'bottom-start' : 'bottom-end'}
|
||||
>
|
||||
<Material
|
||||
slot="target"
|
||||
padding="none"
|
||||
rounding="full"
|
||||
elevation="high"
|
||||
class="w-max absolute bottom-0 left-0 py-0.5 px-1.5 m-1 font-bold"
|
||||
>
|
||||
ALT
|
||||
</Material>
|
||||
{#snippet target()}
|
||||
<Material
|
||||
padding="none"
|
||||
rounding="full"
|
||||
elevation="high"
|
||||
class="w-max absolute bottom-0 left-0 py-0.5 px-1.5 m-1 font-bold"
|
||||
>
|
||||
ALT
|
||||
</Material>
|
||||
{/snippet}
|
||||
<div class="max-w-sm">
|
||||
{post.alt_text}
|
||||
</div>
|
||||
@@ -60,7 +70,7 @@
|
||||
<svelte:element
|
||||
this={!$userSettings.expandImages || type != 'image' ? 'a' : 'button'}
|
||||
href={postLink(post)}
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
if (type == 'image') {
|
||||
showImage(bestImageURL(post, false, -1))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user