1 parent
2902f30327
commit
e259ed4582
7 files changed
+142
-47
No files matched your search
@@ -0,0 +1 @@
|
||||
<slot {...$$restProps} />
|
||||
@@ -8,6 +8,9 @@
|
||||
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
|
||||
import { Material, toast } from 'mono-svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
|
||||
import { bestImageURL, postLink } from '$lib/components/lemmy/post/helpers.js'
|
||||
import Empty from '$lib/components/helper/Empty.svelte'
|
||||
|
||||
export let post: PostView
|
||||
export let actions: boolean = true
|
||||
@@ -54,36 +57,42 @@
|
||||
{#if !$userSettings.showCompactPosts}
|
||||
{#if isImage(post.post.url)}
|
||||
<!--disabled preloads here since most people will hover over every image while scrolling-->
|
||||
<a
|
||||
href="/post/{getInstance()}/{post.post.id}"
|
||||
class="self-start overflow-hidden z-10 relative bg-slate-200 dark:bg-zinc-800 rounded-md max-w-full"
|
||||
data-sveltekit-preload-data="off"
|
||||
aria-label={post.post.name}
|
||||
<svelte:component
|
||||
this={$userSettings.expandImages ? ExpandableImage : Empty}
|
||||
url={bestImageURL(post.post, false, 2048)}
|
||||
>
|
||||
<picture
|
||||
class="rounded-md overflow-hidden max-h-[min(50vh,500px)] w-full max-w-full"
|
||||
<svelte:element
|
||||
this={$userSettings.expandImages ? 'div' : 'a'}
|
||||
href={postLink(post.post)}
|
||||
class="self-start overflow-hidden z-10 relative bg-slate-200 dark:bg-zinc-800 rounded-md max-w-full"
|
||||
data-sveltekit-preload-data="off"
|
||||
aria-label={post.post.name}
|
||||
>
|
||||
<source
|
||||
srcset="{post.post.url}?thumbnail=256&format=webp"
|
||||
media="(max-width: 256px)"
|
||||
/>
|
||||
<source
|
||||
srcset="{post.post.url}?thumbnail=512&format=webp"
|
||||
media="(max-width: 512px)"
|
||||
/>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src="{post.post.url}?thumbnail=512&format=webp"
|
||||
loading="lazy"
|
||||
class="max-w-full object-cover rounded-md max-h-[80vh] h-auto z-30 opacity-0 transition-opacity duration-300"
|
||||
class:opacity-100={loaded}
|
||||
width={512}
|
||||
height={300}
|
||||
class:blur-3xl={post.post.nsfw && $userSettings.nsfwBlur}
|
||||
on:load={() => (loaded = true)}
|
||||
/>
|
||||
</picture>
|
||||
</a>
|
||||
<picture
|
||||
class="rounded-md overflow-hidden max-h-[min(50vh,500px)] w-full max-w-full"
|
||||
>
|
||||
<source
|
||||
srcset={bestImageURL(post.post, false, 512)}
|
||||
media="(max-width: 256px)"
|
||||
/>
|
||||
<source
|
||||
srcset={bestImageURL(post.post, false, 512)}
|
||||
media="(max-width: 512px)"
|
||||
/>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={bestImageURL(post.post, false, 1024)}
|
||||
loading="lazy"
|
||||
class="max-w-full object-cover rounded-md max-h-[80vh] h-auto z-30 opacity-0 transition-opacity duration-300"
|
||||
class:opacity-100={loaded}
|
||||
width={512}
|
||||
height={300}
|
||||
class:blur-3xl={post.post.nsfw && $userSettings.nsfwBlur}
|
||||
on:load={() => (loaded = true)}
|
||||
/>
|
||||
</picture>
|
||||
</svelte:element>
|
||||
</svelte:component>
|
||||
{:else if post.post.url}
|
||||
<PostLink
|
||||
url={post.post.url}
|
||||
@@ -113,23 +122,29 @@
|
||||
</div>
|
||||
{#if $userSettings.showCompactPosts && (post.post.thumbnail_url || isImage(post.post.url))}
|
||||
<div class="flex-none w-24 h-24">
|
||||
<a href="/post/{getInstance()}/{post.post.id}">
|
||||
{#if post.post.thumbnail_url}
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src="{post.post.thumbnail_url}?thumbnail=256&format=webp"
|
||||
loading="lazy"
|
||||
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
|
||||
/>
|
||||
{:else}
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src="{post.post.url}?thumbnail=256&format=webp"
|
||||
loading="lazy"
|
||||
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
|
||||
/>
|
||||
{/if}
|
||||
</a>
|
||||
{#if !$userSettings.expandImages || (post.post.thumbnail_url && !isImage(post.post.url))}
|
||||
<a href={postLink(post.post)}>
|
||||
{#if post.post.thumbnail_url}
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={bestImageURL(post.post, true)}
|
||||
loading="lazy"
|
||||
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
|
||||
/>
|
||||
{/if}
|
||||
</a>
|
||||
{:else}
|
||||
<ExpandableImage url={bestImageURL(post.post, false)}>
|
||||
{#if post.post.thumbnail_url}
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={bestImageURL(post.post, true)}
|
||||
loading="lazy"
|
||||
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
|
||||
/>
|
||||
{/if}
|
||||
</ExpandableImage>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,26 @@
|
||||
import type { CommentView, PersonView, PostView } from 'lemmy-js-client'
|
||||
import { getInstance } from '$lib/lemmy.js'
|
||||
import type { CommentView, PersonView, Post, PostView } from 'lemmy-js-client'
|
||||
|
||||
export const isMutable = (post: PostView, me: PersonView) =>
|
||||
(me.person.admin && post.post.local) || me.person.id == post.creator.id
|
||||
|
||||
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
||||
me.person.id == comment.creator.id
|
||||
|
||||
export const bestImageURL = (
|
||||
post: Post,
|
||||
compact: boolean = true,
|
||||
width: number = 1024
|
||||
) => {
|
||||
if (compact && post.thumbnail_url)
|
||||
return `${post.thumbnail_url}?thumbnail=256&format=webp`
|
||||
else if (compact && post.url) return `${post.url}?thumbnail=256&format=webp`
|
||||
|
||||
if (post.url) return `${post.url}?thumbnail=${width}&format=webp`
|
||||
else if (post.thumbnail_url)
|
||||
return `${post.thumbnail_url}?thumbnail=${width}&format=webp`
|
||||
|
||||
return post.url ?? ''
|
||||
}
|
||||
|
||||
export const postLink = (post: Post) => `/post/${getInstance()}/${post.id}`
|
||||
@@ -0,0 +1,49 @@
|
||||
<script lang="ts">
|
||||
import { Button } from 'mono-svelte'
|
||||
import { Icon, XMark } from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fade, scale } from 'svelte/transition'
|
||||
|
||||
/**
|
||||
* The full-resolution image URL
|
||||
*/
|
||||
export let url: string
|
||||
export let alt: string = ''
|
||||
export let open: boolean = false
|
||||
</script>
|
||||
|
||||
<svelte:body
|
||||
on:keydown={(e) => {
|
||||
if (open && e.code == 'Escape') open = false
|
||||
}}
|
||||
/>
|
||||
|
||||
{#if open}
|
||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-positive-tabindex -->
|
||||
<div
|
||||
class="fixed top-0 left-0 w-screen h-screen overflow-auto bg-black/50 flex flex-col z-[100]"
|
||||
transition:fade={{ duration: 200 }}
|
||||
on:click={() => (open = false)}
|
||||
>
|
||||
<Button
|
||||
size="square-md"
|
||||
class="absolute z-[110] top-0 right-0 m-4"
|
||||
on:click={() => (open = false)}
|
||||
>
|
||||
<Icon src={XMark} size="16" mini slot="prefix" />
|
||||
</Button>
|
||||
<img
|
||||
src={url}
|
||||
class="w-full h-full object-contain max-w-screen-sm mx-auto my-auto"
|
||||
transition:scale={{ start: 0.9, easing: expoOut }}
|
||||
{alt}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<button on:click={() => (open = !open)} class="w-max">
|
||||
<slot />
|
||||
</button>
|
||||
@@ -54,6 +54,7 @@ interface Settings {
|
||||
modlogCardView: boolean | undefined
|
||||
debugInfo: boolean
|
||||
systemUI: boolean
|
||||
expandImages: boolean
|
||||
}
|
||||
|
||||
export const defaultSettings: Settings = {
|
||||
@@ -93,6 +94,7 @@ export const defaultSettings: Settings = {
|
||||
modlogCardView: toBool(env.PUBLIC_MODLOG_CARD_VIEW) ?? undefined,
|
||||
debugInfo: false,
|
||||
systemUI: true,
|
||||
expandImages: true,
|
||||
}
|
||||
|
||||
export const userSettings = writable(defaultSettings)
|
||||
|
||||
@@ -145,6 +145,15 @@
|
||||
</Checkbox>
|
||||
<span slot="description">Alternate vote design</span>
|
||||
</Setting>
|
||||
<Setting>
|
||||
<Checkbox bind:checked={$userSettings.expandImages} slot="title">
|
||||
Expand Images
|
||||
</Checkbox>
|
||||
<span slot="description">
|
||||
Clicking on an image brings you to an expanded view rather than sending
|
||||
you to the post page.
|
||||
</span>
|
||||
</Setting>
|
||||
|
||||
<SectionTitle class="mt-4">Instances</SectionTitle>
|
||||
<Setting>
|
||||
|
||||
Reference in new issue
Block a user