misc: split post media into separate component
This commit is contained in:
1 parent
c1c138680d
commit
9d48198f95
5 files changed
+141
-121
No files matched your search
@@ -0,0 +1,97 @@
|
||||
<script lang="ts">
|
||||
import Empty from '$lib/components/helper/Empty.svelte'
|
||||
import PostLink from '$lib/components/lemmy/post/PostLink.svelte'
|
||||
import { bestImageURL, postLink } from '$lib/components/lemmy/post/helpers.js'
|
||||
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { isImage, isVideo } from '$lib/ui/image'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import { Icon, VideoCamera } from 'svelte-hero-icons'
|
||||
|
||||
export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy'
|
||||
export let post: Post
|
||||
</script>
|
||||
|
||||
{#if isImage(post.url)}
|
||||
{#if view == 'card' || view == 'cozy'}
|
||||
<!--disabled preloads here since most people will hover over every image while scrolling-->
|
||||
<svelte:component
|
||||
this={$userSettings.expandImages ? ExpandableImage : Empty}
|
||||
url={bestImageURL(post, false, 2048)}
|
||||
class="container mx-auto w-fit"
|
||||
>
|
||||
<svelte:element
|
||||
this={$userSettings.expandImages ? 'div' : 'a'}
|
||||
href={postLink(post)}
|
||||
class="container mx-auto z-10 transition-colors rounded-xl max-h-[60vh] relative overflow-hidden"
|
||||
data-sveltekit-preload-data="off"
|
||||
aria-label={post.name}
|
||||
>
|
||||
<picture
|
||||
class="absolute top-1/2 -translate-y-1/2 left-0 w-full
|
||||
opacity-30 object-cover scale-[1.2] blur-3xl -z-10"
|
||||
>
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 512)}
|
||||
media="(max-width: 256px)"
|
||||
/>
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 512)}
|
||||
media="(max-width: 512px)"
|
||||
/>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={bestImageURL(post, false, 1024)}
|
||||
loading="lazy"
|
||||
class="w-full h-full object-cover rounded-xl blur-3xl z-50"
|
||||
width={512}
|
||||
height={300}
|
||||
/>
|
||||
</picture>
|
||||
<picture class="max-h-[inherit]">
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 512)}
|
||||
media="(max-width: 256px)"
|
||||
/>
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 512)}
|
||||
media="(max-width: 512px)"
|
||||
/>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={bestImageURL(post, false, 1024)}
|
||||
loading="lazy"
|
||||
class="max-h-[inherit] max-w-full h-auto z-30
|
||||
transition-opacity duration-300 object-contain mx-auto"
|
||||
width={512}
|
||||
height={300}
|
||||
class:blur-3xl={post.nsfw && $userSettings.nsfwBlur}
|
||||
/>
|
||||
</picture>
|
||||
</svelte:element>
|
||||
</svelte:component>
|
||||
{/if}
|
||||
{:else if isVideo(post.url) && (view == 'cozy' || view == 'card')}
|
||||
<a
|
||||
href={postLink(post)}
|
||||
style="height: 300px;"
|
||||
class="w-full rounded-xl flex flex-col items-center justify-center relative z-0 overflow-hidden
|
||||
text-white p-4"
|
||||
>
|
||||
<div
|
||||
class="absolute blur-xl -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"
|
||||
/>
|
||||
<Icon src={VideoCamera} solid size="48" />
|
||||
<span class="font-bold text-2xl">Video</span>
|
||||
<p class="text-base">Go to the post to view this video.</p>
|
||||
</a>
|
||||
{:else if post.url}
|
||||
<PostLink
|
||||
url={post.url}
|
||||
thumbnail_url={post.thumbnail_url}
|
||||
nsfw={post.nsfw}
|
||||
embed_description={post.embed_description}
|
||||
embed_title={post.embed_title}
|
||||
compact={view == 'compact'}
|
||||
/>
|
||||
{/if}
|
||||
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { bestImageURL, postLink } from '$lib/components/lemmy/post/helpers.js'
|
||||
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { isImage } from '$lib/ui/image'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
|
||||
export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy'
|
||||
export let post: Post
|
||||
</script>
|
||||
|
||||
{#if (view == 'list' || view == 'compact') && !post.embed_title && (post.thumbnail_url || isImage(post.url))}
|
||||
<div class="flex-shrink-0 w-24 h-24">
|
||||
{#if !$userSettings.expandImages || (post.thumbnail_url && !isImage(post.url))}
|
||||
<a href={postLink(post)}>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={bestImageURL(post, true)}
|
||||
loading="lazy"
|
||||
class="object-cover bg-slate-100 dark:bg-zinc-800 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
|
||||
/>
|
||||
</a>
|
||||
{:else}
|
||||
<ExpandableImage url={bestImageURL(post, false, 2048)}>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={bestImageURL(post, true)}
|
||||
loading="lazy"
|
||||
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
|
||||
/>
|
||||
</ExpandableImage>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
Reference in new issue
Block a user