fix: respect nsfw rules in compact mode

This commit is contained in:
Xylight committed 2024-10-07 17:46:31 -07:00
1 parent 1401e30a09
commit 6291e7e3d3
5 files changed
+64 -15

No files matched your search

@@ -1,7 +1,9 @@
<script lang="ts">
import Avatar from '$lib/components/ui/Avatar.svelte'
import { userSettings } from '$lib/settings.js'
import { t } from '$lib/translations'
import type { Community } from 'lemmy-js-client'
import { ExclamationTriangle, Icon } from 'svelte-hero-icons'
export let community: Community
@@ -10,6 +12,10 @@
export let avatarSize: number = 24
export let showInstance: boolean = $userSettings.showInstances.community
export let displayName: boolean = true
export let badges = {
nsfw: false,
}
</script>
<a
@@ -43,6 +49,17 @@
{/if}
</span>
{/if}
{#if badges}
{#if badges.nsfw}
<Icon
src={ExclamationTriangle}
size="14"
micro
title={$t('post.badges.nsfw')}
class="text-red-600 dark:text-red-400"
/>
{/if}
{/if}
</a>
<style>
+2 -1
View File
@@ -112,7 +112,7 @@
removed: post.post.removed,
locked: post.post.locked,
featured: post.post.featured_local || post.post.featured_community,
nsfw: post.post.nsfw,
nsfw: post.post.nsfw || post.community.nsfw,
saved: post.saved,
admin: post.creator_is_admin,
moderator: post.creator_is_moderator,
@@ -154,6 +154,7 @@
? 'mr-3'
: 'ml-3'} flex-shrink no-list-margin"
style="grid-area: media;"
blur={rule == 'blur' ? true : undefined}
{view}
/>
{/if}
@@ -144,6 +144,9 @@
{community}
style="grid-area: community;"
class="flex-shrink no-list-margin"
badges={{
nsfw: community.nsfw,
}}
/>
{/if}
<div
@@ -57,11 +57,11 @@
src={bestImageURL(post, false, -1)}
loading="lazy"
class="max-h-[inherit] max-w-full h-auto z-30
transition-opacity duration-500 object-contain mx-auto
transition-opacity duration-500 object-contain mx-auto blur-[64px]
{imageLoaded === false ? 'opacity-0' : 'opacity-100'}"
width={512}
height={300}
class:blur-3xl={blur}
class:blur-[64px]={blur}
alt={post.alt_text ?? ''}
on:load={() => (imageLoaded = true)}
/>
@@ -10,11 +10,18 @@
import { isImage } from '$lib/ui/image'
import type { Post } from 'lemmy-js-client'
import { Material, Popover } from 'mono-svelte'
import { DocumentText, Icon, Link, VideoCamera } from 'svelte-hero-icons'
import {
DocumentText,
Icon,
Link,
VideoCamera,
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'
@@ -61,20 +68,41 @@
tabindex="0"
>
{#if post.thumbnail_url || isImage(post.url)}
<img
src={optimizeImageURL(post.thumbnail_url || post.url || '', 196)}
loading="lazy"
class="object-cover overflow-hidden bg-slate-100 dark:bg-zinc-800 rounded-xl
<div class="relative overflow-hidden rounded-xl">
<picture class="relative">
<img
src={optimizeImageURL(post.thumbnail_url || post.url || '', 256)}
loading="lazy"
class="object-cover overflow-hidden bg-slate-100 dark:bg-zinc-800 rounded-xl
transition-colors {size}"
alt={post.name}
/>
{#if type != 'image'}
alt={post.name}
class:blur-xl={blur}
/>
{#if type != 'image'}
<div
class="absolute w-8 h-8 bottom-0 left-0 m-1 rounded-xl text-slate-800 dark:text-zinc-200
backdrop-blur-sm bg-slate-25/75 dark:bg-zinc-900/75 border border-slate-200/75 dark:border-zinc-700/75
grid place-items-center"
>
<Icon
src={type == 'iframe' ? VideoCamera : Link}
micro
size="16"
/>
</div>
{/if}
</picture>
</div>
{#if blur}
<div
class="absolute w-8 h-8 bottom-0 left-0 m-1 rounded-xl text-slate-800 dark:text-zinc-200
backdrop-blur-sm bg-slate-25/75 dark:bg-zinc-900/75 border border-slate-200/75 dark:border-zinc-700/75
grid place-items-center"
class="absolute w-full h-full grid place-items-center inset-0 z-30"
>
<Icon src={type == 'iframe' ? VideoCamera : Link} micro size="16" />
<Icon
src={ExclamationTriangle}
solid
size="32"
class="z-50 opacity-30"
/>
</div>
{/if}
{:else}