misc: add load prompt to images, close #511

This commit is contained in:
James Xylight committed 2025-03-19 19:23:22 -07:00
1 parent 0b4005743e
commit f18e5d09f2
5 files changed
+61 -20

No files matched your search

@@ -36,6 +36,9 @@
</div>
{/if}
<TextProps wrap="no-wrap">
<Markdown source={message.private_message.content} />
<Markdown
rendererOptions={{ autoloadImages: false }}
source={message.private_message.content}
/>
</TextProps>
</div>
@@ -112,6 +112,11 @@
<script lang="ts">
import SvelteMarkdown from 'svelte-markdown'
import { setContext } from 'svelte'
interface RendererOptions {
autoloadImages: boolean
}
interface Props {
source?: string
@@ -119,6 +124,7 @@
noStyle?: boolean
style?: string
class?: string
rendererOptions?: RendererOptions
}
let {
@@ -127,8 +133,13 @@
noStyle = false,
style = '',
class: clazz = '',
rendererOptions = {
autoloadImages: true,
},
}: Props = $props()
setContext('options', rendererOptions)
options.inline = inline
let tokens = $derived.by(() => marked.lexer(source))
@@ -6,6 +6,14 @@
optimizeImageURL,
} from '$lib/components/lemmy/post/helpers'
import PostIframe from '$lib/components/lemmy/post/media/PostIframe.svelte'
import { getContext } from 'svelte'
import { ArrowDown, ArrowDownTray, Icon } from 'svelte-hero-icons'
import { t } from '$lib/translations'
let loaded: boolean = $state(
(getContext('options') as { autoloadImages: boolean })?.autoloadImages ??
true,
)
interface Props {
href: string
@@ -22,26 +30,40 @@
class="w-auto h-auto max-h-96 rounded-2xl p-2 border border-slate-200 dark:border-zinc-800
inline-block"
>
{#if type == 'video' || type == 'embed' || type == 'iframe'}
<PostIframe
type={iframeType(href)}
url={href}
opened={true}
autoplay={false}
class="w-auto h-auto max-h-80 inline-block rounded-lg"
/>
{#if loaded}
{#if type == 'video' || type == 'embed' || type == 'iframe'}
<PostIframe
type={iframeType(href)}
url={href}
opened={true}
autoplay={false}
class="w-auto h-auto max-h-80 inline-block rounded-lg"
/>
{:else}
<button
class="inline"
onclick={() => showImage(optimizeImageURL(href, -1), text)}
>
<img
src={optimizeImageURL(href, 1024)}
{title}
alt={text}
width={300}
height={300}
class="object-contain w-auto h-auto max-h-80 inline rounded-lg"
/>
</button>
{/if}
{:else}
<button
class="inline"
onclick={() => showImage(optimizeImageURL(href, -1), text)}
onclick={() => (loaded = true)}
class="w-40 h-40 flex flex-col justify-center items-center gap-4 p-2 group"
title={$t('common.download')}
>
<img
src={optimizeImageURL(href, 1024)}
{title}
alt={text}
width={300}
height={300}
class="object-contain w-auto h-auto max-h-80 inline rounded-lg"
<Icon
src={ArrowDownTray}
size="24"
class="text-primary-900 dark:text-primary-100"
/>
</button>
{/if}