Merge branch 'main' into listview-selfpost-thumbnail
This commit is contained in:
53 files changed
+2061
-441
No files matched your search
@@ -16,6 +16,7 @@
|
||||
class="items-center flex flex-row gap-2 hover:underline max-w-full min-w-0 {$$props.class ||
|
||||
''}"
|
||||
href="/c/{community.name}@{new URL(community.actor_id).hostname}"
|
||||
data-sveltekit-preload-data="tap"
|
||||
>
|
||||
{#if avatar}
|
||||
<Avatar
|
||||
@@ -28,7 +29,7 @@
|
||||
|
||||
{#if name}
|
||||
<span class="flex gap-0 items-center max-w-full min-w-0 flex-shrink">
|
||||
<span class="font-medium">{community.title}</span>
|
||||
<span class="font-medium username-text">{community.title}</span>
|
||||
{#if showInstance}
|
||||
<span
|
||||
class="text-slate-500 dark:text-zinc-500 font-normal
|
||||
@@ -47,5 +48,12 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 100%;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.username-text {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
</style>
|
||||
@@ -5,7 +5,10 @@
|
||||
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import PostLink from '$lib/components/lemmy/post/PostLink.svelte'
|
||||
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
|
||||
import PostMeta, {
|
||||
parseTags,
|
||||
type Tag,
|
||||
} from '$lib/components/lemmy/post/PostMeta.svelte'
|
||||
import { Badge, Material, toast } from 'mono-svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
|
||||
@@ -34,6 +37,10 @@
|
||||
export let view = $userSettings.view
|
||||
|
||||
$: type = mediaType(post.post.url, view)
|
||||
|
||||
$: tags = parseTags(post.post.name)
|
||||
$: rule = getTagRule(tags.tags)
|
||||
|
||||
$: hideTitle =
|
||||
$userSettings.posts.deduplicateEmbed &&
|
||||
post.post.embed_title == post.post.name &&
|
||||
@@ -45,6 +52,19 @@
|
||||
post.post.embed_description == post.post.body &&
|
||||
view != 'compact'
|
||||
|
||||
function getTagRule(tags: Tag[]): 'blur' | 'hide' | undefined {
|
||||
const tagContent = tags.map((t) => t.content.toLowerCase())
|
||||
|
||||
let rule: 'blur' | 'hide' | undefined
|
||||
tagContent.forEach((tag) => {
|
||||
if ($userSettings.tagRules?.[tag])
|
||||
rule = $userSettings.tagRules?.[tag] ?? rule
|
||||
if (rule == 'hide') return rule
|
||||
})
|
||||
|
||||
return rule
|
||||
}
|
||||
|
||||
function onClick(e: any) {
|
||||
const event = e as MouseEvent
|
||||
const parent = document.getElementById(post.post.id.toString())
|
||||
@@ -55,11 +75,16 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@component
|
||||
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 -->
|
||||
<Material
|
||||
color={view != 'card' ? 'none' : 'distinct'}
|
||||
class="relative max-w-full min-w-0 w-full group cursor-pointer
|
||||
class="post relative max-w-full min-w-0 w-full group cursor-pointer
|
||||
{view != 'card' ? 'bg-transparent !border-0' : 'p-5'} {view == 'compact'
|
||||
? 'py-4 list-type'
|
||||
: view == 'list'
|
||||
@@ -70,9 +95,11 @@
|
||||
on:click={(e) => {
|
||||
onClick(e)
|
||||
}}
|
||||
style={$$props.style ?? ''}
|
||||
>
|
||||
<PostMeta
|
||||
community={hideCommunity ? undefined : post.community}
|
||||
community={post.community}
|
||||
showCommunity={!hideCommunity}
|
||||
user={post.creator}
|
||||
published={publishedToDate(post.post.published)}
|
||||
badges={{
|
||||
@@ -91,9 +118,10 @@
|
||||
? 'Subscribed'
|
||||
: 'NotSubscribed'}
|
||||
id={post.post.id}
|
||||
title={hideTitle ? undefined : post.post.name}
|
||||
title={hideTitle ? undefined : tags?.title ? tags.title : post.post.name}
|
||||
read={post.read}
|
||||
style="grid-area: meta;"
|
||||
tags={tags?.tags}
|
||||
>
|
||||
<slot name="badges" slot="badges" />
|
||||
</PostMeta>
|
||||
@@ -102,12 +130,19 @@
|
||||
style="grid-area:embed;"
|
||||
class={view == 'list' || view == 'compact' ? '' : 'contents'}
|
||||
>
|
||||
<PostMedia bind:post={post.post} {view} {type} />
|
||||
{#if rule != 'hide'}
|
||||
<PostMedia
|
||||
bind:post={post.post}
|
||||
blur={rule == 'blur' ? true : undefined}
|
||||
{view}
|
||||
{type}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
{#if view == 'list' || view == 'compact'}
|
||||
<PostMediaCompact
|
||||
bind:post={post.post}
|
||||
bind:type={type}
|
||||
bind:type
|
||||
class="{$userSettings.leftAlign
|
||||
? 'mr-2'
|
||||
: 'ml-2'} flex-shrink no-list-margin"
|
||||
@@ -115,7 +150,7 @@
|
||||
/>
|
||||
{/if}
|
||||
{/key}
|
||||
{#if post.post.body && !post.post.nsfw && view != 'compact' && !hideBody}
|
||||
{#if post.post.body && !post.post.nsfw && view != 'compact' && !hideBody && rule != 'hide'}
|
||||
<PostBody body={post.post.body} {view} style="grid-area: body" />
|
||||
{/if}
|
||||
{#if actions}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
import { t } from '$lib/translations'
|
||||
import { slide } from 'svelte/transition'
|
||||
import { feature } from '$lib/version'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
|
||||
export let edit = false
|
||||
|
||||
@@ -140,7 +141,7 @@
|
||||
community_id: data.community!.id,
|
||||
name: data.title,
|
||||
body: data.body,
|
||||
url: data.url,
|
||||
url: data.url || undefined,
|
||||
nsfw: data.nsfw,
|
||||
custom_thumbnail: data.thumbnail,
|
||||
alt_text: data.alt_text,
|
||||
@@ -228,9 +229,9 @@
|
||||
|
||||
<form on:submit|preventDefault={submit} class="flex flex-col gap-4 h-full">
|
||||
<slot name="formtitle">
|
||||
<h1 class="font-bold text-xl">
|
||||
<Header class="font-bold text-xl">
|
||||
{edit ? $t('form.post.edit') : $t('form.post.create')}
|
||||
</h1>
|
||||
</Header>
|
||||
</slot>
|
||||
{#if !edit && data}
|
||||
{#if !data.community}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import Link, { parseURL } from '$lib/components/input/Link.svelte'
|
||||
import { Material } from 'mono-svelte'
|
||||
import { Button, Material } from 'mono-svelte'
|
||||
import { Icon, Link as LinkIcon } from 'svelte-hero-icons'
|
||||
import { optimizeImageURL } from './helpers'
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
$: richURL = parseURL(url)
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@component
|
||||
For embed-type posts. Displays embed card or a compact link.
|
||||
-->
|
||||
{#if embed_title && !compact}
|
||||
<Material color="distinct" class="flex flex-row gap-4">
|
||||
<div class="flex flex-col gap-2">
|
||||
@@ -60,12 +64,15 @@
|
||||
{/if}
|
||||
</Material>
|
||||
{:else}
|
||||
<Link
|
||||
<Button
|
||||
href={url}
|
||||
target="_blank"
|
||||
class="text-slate-700 dark:text-zinc-300 inline-flex items-center gap-1 text-sm"
|
||||
class="text-slate-700 dark:text-zinc-300 inline-flex items-center gap-1 text-xs overflow-hidden w-max max-w-full"
|
||||
size="sm"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
>
|
||||
<Icon src={LinkIcon} size="14" mini slot="icon" class="flex-shrink-0" />
|
||||
<Icon src={LinkIcon} size="14" mini slot="prefix" class="flex-shrink-0" />
|
||||
{#if richURL}
|
||||
<div class="flex max-w-full overflow-hidden">
|
||||
{richURL.hostname}
|
||||
@@ -76,7 +83,7 @@
|
||||
{:else}
|
||||
{url}
|
||||
{/if}
|
||||
</Link>
|
||||
</Button>
|
||||
{#if thumbnail_url && !compact}
|
||||
<a href={url} target="_blank">
|
||||
<img
|
||||
|
||||
@@ -1,3 +1,39 @@
|
||||
<script lang="ts" context="module">
|
||||
export interface Tag {
|
||||
content: string
|
||||
color?: string
|
||||
icon?: IconSource
|
||||
}
|
||||
|
||||
export const textToTag: Map<string, Tag> = new Map<string, Tag>([
|
||||
['OC', { content: 'OC', color: '#03A8F240' }],
|
||||
['NSFL', { content: 'NSFL', color: '#ff000040' }],
|
||||
['CW', { content: 'CW', color: '#ff000040' }],
|
||||
])
|
||||
|
||||
export const parseTags = (
|
||||
title?: string
|
||||
): { tags: Tag[]; title?: string } => {
|
||||
if (!title) return { tags: [] }
|
||||
|
||||
let extracted: Tag[] = []
|
||||
|
||||
title = title.replace(/\[(.*?)\]/g, (match, content) => {
|
||||
extracted.push(
|
||||
textToTag.get(content) ?? {
|
||||
content: content,
|
||||
}
|
||||
)
|
||||
return ''
|
||||
})
|
||||
|
||||
return {
|
||||
tags: extracted,
|
||||
title: title,
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
@@ -13,6 +49,7 @@
|
||||
LockClosed,
|
||||
Megaphone,
|
||||
Plus,
|
||||
Tag,
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import { getInstance } from '$lib/lemmy.js'
|
||||
@@ -22,8 +59,10 @@
|
||||
import { userSettings } from '$lib/settings'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import type { IconSource } from 'svelte-hero-icons'
|
||||
|
||||
export let community: Community | undefined = undefined
|
||||
export let showCommunity: boolean = true
|
||||
export let subscribed: SubscribedType | undefined = undefined
|
||||
|
||||
export let user: Person | undefined = undefined
|
||||
@@ -43,15 +82,29 @@
|
||||
moderator: false,
|
||||
admin: false,
|
||||
}
|
||||
|
||||
export let tags: Tag[] = []
|
||||
|
||||
$: {
|
||||
if (title && tags.length == 0) {
|
||||
const result = parseTags(title)
|
||||
tags = result.tags
|
||||
title = result.title
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@component
|
||||
This component will build two different things: a post's meta block and the title.
|
||||
-->
|
||||
<div
|
||||
class="grid w-full meta {community
|
||||
? 'grid-rows-2'
|
||||
: 'grid-rows-1'} text-xs min-w-0 max-w-full"
|
||||
style={$$props.style ?? ''}
|
||||
>
|
||||
{#if community}
|
||||
{#if showCommunity && community}
|
||||
<Subscribe let:subscribe let:subscribing>
|
||||
<button
|
||||
on:click={async () => {
|
||||
@@ -74,8 +127,8 @@
|
||||
class="absolute w-3.5 h-3.5 {subscribed == 'NotSubscribed'
|
||||
? 'bg-primary-900 dark:bg-primary-100 text-white dark:text-black'
|
||||
: 'bg-primary-100 dark:bg-primary-900 text-black dark:text-white'} rounded-full ring-2 box-border
|
||||
ring-slate-50 dark:ring-zinc-950
|
||||
-bottom-1 right-1 grid place-items-center transition-all"
|
||||
ring-slate-50 dark:ring-zinc-950 grid place-items-center transition-all
|
||||
right-0 -translate-x-1 -translate-y-2"
|
||||
>
|
||||
<Icon
|
||||
src={subscribed == 'NotSubscribed' ? Plus : Check}
|
||||
@@ -87,19 +140,19 @@
|
||||
</button>
|
||||
</Subscribe>
|
||||
{/if}
|
||||
{#if community}
|
||||
{#if showCommunity && community}
|
||||
<CommunityLink
|
||||
{community}
|
||||
style="grid-area: community;"
|
||||
class="flex-shrink"
|
||||
class="flex-shrink self-end"
|
||||
/>
|
||||
{/if}
|
||||
<span
|
||||
class="text-slate-600 dark:text-zinc-400 flex flex-row gap-2 items-center"
|
||||
class="text-slate-600 dark:text-zinc-400 flex flex-row gap-2 items-center self-start"
|
||||
style="grid-area: stats;"
|
||||
>
|
||||
{#if user}
|
||||
<UserLink avatarSize={20} {user} avatar={!community}>
|
||||
<UserLink avatarSize={20} {user} avatar={!showCommunity}>
|
||||
<svelte:fragment slot="badges">
|
||||
{#if badges.moderator}
|
||||
<ShieldIcon filled width={14} class="text-green-500" />
|
||||
@@ -115,9 +168,29 @@
|
||||
{/if}
|
||||
</span>
|
||||
<div
|
||||
class="flex flex-row items-center self-center flex-wrap gap-2 [&>*]:flex-shrink-0 badges"
|
||||
class="flex flex-row justify-end items-center self-center flex-wrap gap-2 [&>*]:flex-shrink-0 badges ml-2"
|
||||
style="grid-area: badges;"
|
||||
>
|
||||
{#if tags}
|
||||
{#each tags as tag}
|
||||
<a
|
||||
class="hover:brightness-110"
|
||||
href="/search?community={community?.id}&q=[{tag.content}]&type=Posts"
|
||||
style={tag.color ? `--tag-color: ${tag.color};` : ''}
|
||||
>
|
||||
<Badge class={tag.color ? 'badge-tag-color' : ''}>
|
||||
<svelte:fragment slot="icon">
|
||||
{#if tag.icon}
|
||||
<Icon src={tag.icon} micro size="14" />
|
||||
{:else}
|
||||
<Icon src={Tag} micro size="14" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{tag.content}
|
||||
</Badge>
|
||||
</a>
|
||||
{/each}
|
||||
{/if}
|
||||
{#if badges.nsfw}
|
||||
<Badge label={$t('post.badges.nsfw')} color="red-subtle" allowIconOnly>
|
||||
<Icon src={ExclamationTriangle} size="14" micro slot="icon" />
|
||||
@@ -180,9 +253,12 @@
|
||||
class:text-slate-600={$userSettings.markReadPosts && read}
|
||||
class:dark:text-zinc-400={$userSettings.markReadPosts && read}
|
||||
style="grid-area: title;"
|
||||
data-sveltekit-preload-data="tap"
|
||||
>
|
||||
<Markdown source={title} inline noStyle class="leading-[1.3]"></Markdown>
|
||||
</a>
|
||||
{:else}
|
||||
<div style="grid-area: title; margin: 0;"></div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
@@ -193,6 +269,10 @@
|
||||
'avatar stats badges';
|
||||
gap: 0;
|
||||
grid-template-rows: auto auto;
|
||||
grid-template-columns: auto 1fr auto;
|
||||
grid-template-columns: max-content minmax(0, auto) auto;
|
||||
}
|
||||
|
||||
:global(.badge-tag-color) {
|
||||
background-color: var(--tag-color) !important;
|
||||
}
|
||||
</style>
|
||||
+12
-9
@@ -7,6 +7,11 @@
|
||||
import { ArchiveBox, Icon, Minus, Plus } from 'svelte-hero-icons'
|
||||
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 { createWindowVirtualizer } from '@tanstack/svelte-virtual'
|
||||
import { afterNavigate, beforeNavigate } from '$app/navigation'
|
||||
import { _posts } from '../../../../../routes/+page.svelte'
|
||||
|
||||
type PostViewWithCrossposts = PostView & {
|
||||
withCrossposts: true
|
||||
@@ -98,16 +103,16 @@
|
||||
</Placeholder>
|
||||
</div>
|
||||
{:else}
|
||||
{#each combinedPosts as post, index (post.post.id)}
|
||||
{#each combinedPosts as post, index}
|
||||
{#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)}
|
||||
<li
|
||||
in:fly|global={{
|
||||
y: -8,
|
||||
duration: index < 4 ? 500 : 0,
|
||||
duration: 500,
|
||||
opacity: 0,
|
||||
delay: index < 4 ? index * 100 : 0,
|
||||
delay: 100 + index * 20,
|
||||
}}
|
||||
class="relative"
|
||||
class="relative post-container"
|
||||
>
|
||||
<Post
|
||||
hideCommunity={community}
|
||||
@@ -116,12 +121,9 @@
|
||||
? 'compact'
|
||||
: $userSettings.view}
|
||||
{post}
|
||||
class="transition-all duration-250 {post.withCrossposts &&
|
||||
viewPost != post.post.id
|
||||
? ''
|
||||
: ''}"
|
||||
class="transition-all duration-250"
|
||||
on:hide={() => {
|
||||
combinedPosts = combinedPosts.toSpliced(index, 1)
|
||||
posts = posts.toSpliced(index, 1)
|
||||
}}
|
||||
>
|
||||
<svelte:fragment slot="badges">
|
||||
@@ -175,4 +177,5 @@
|
||||
{/if}
|
||||
{/each}
|
||||
{/if}
|
||||
<slot />
|
||||
</ul>
|
||||
@@ -0,0 +1,222 @@
|
||||
<script lang="ts">
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import { Badge, Button } from 'mono-svelte'
|
||||
import { ArchiveBox, Icon, Minus, Plus } from 'svelte-hero-icons'
|
||||
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 { createWindowVirtualizer } from '@tanstack/svelte-virtual'
|
||||
import { afterNavigate, beforeNavigate } from '$app/navigation'
|
||||
import { _posts } from '../../../../../routes/+page.svelte'
|
||||
|
||||
type PostViewWithCrossposts = PostView & {
|
||||
withCrossposts: true
|
||||
crossposts: PostView[]
|
||||
}
|
||||
type PostViewWithoutCrossposts = PostView & { withCrossposts?: false }
|
||||
|
||||
export let posts: PostView[]
|
||||
export let community: boolean = false
|
||||
|
||||
const addCrosspostProperty = (
|
||||
post: PostView,
|
||||
crossposts: PostView[]
|
||||
): PostViewWithCrossposts => ({
|
||||
...post,
|
||||
crossposts: crossposts,
|
||||
withCrossposts: true,
|
||||
})
|
||||
|
||||
const combineCrossposts = (
|
||||
posts: PostView[]
|
||||
): (PostViewWithCrossposts | PostViewWithoutCrossposts)[] => {
|
||||
const urlMap = new Map<
|
||||
string,
|
||||
PostViewWithCrossposts | PostViewWithoutCrossposts
|
||||
>()
|
||||
const results: (PostViewWithCrossposts | PostViewWithoutCrossposts)[] = []
|
||||
const seenUrls = new Set<string>()
|
||||
|
||||
posts?.forEach((post) => {
|
||||
if (
|
||||
!post ||
|
||||
($userSettings.hidePosts.deleted && post.post.deleted) ||
|
||||
($userSettings.hidePosts.removed && post.post.removed)
|
||||
)
|
||||
return
|
||||
if (!post?.post?.url) {
|
||||
results.push(post)
|
||||
return
|
||||
}
|
||||
|
||||
let existing = urlMap.get(post.post.url)
|
||||
if (existing) {
|
||||
existing.withCrossposts = true
|
||||
if (existing.withCrossposts) {
|
||||
existing.crossposts = [...(existing.crossposts || []), post]
|
||||
}
|
||||
|
||||
urlMap.set(post.post.url, existing)
|
||||
} else {
|
||||
urlMap.set(post.post.url, post)
|
||||
results.push(post)
|
||||
}
|
||||
seenUrls.add(post.post.url)
|
||||
})
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
// $: combinedPosts = combineCrossposts(posts)
|
||||
|
||||
let viewPost: number = -1
|
||||
|
||||
const virtualizer = createWindowVirtualizer({
|
||||
count: posts.length,
|
||||
estimateSize: () => 150,
|
||||
})
|
||||
|
||||
$: if (posts.length)
|
||||
$virtualizer.setOptions({
|
||||
count: posts.length,
|
||||
})
|
||||
|
||||
let virtualItemEls: HTMLElement[] = []
|
||||
|
||||
$: items = $virtualizer.getVirtualItems()
|
||||
$: {
|
||||
if (virtualItemEls.length)
|
||||
virtualItemEls.forEach((el) => $virtualizer.measureElement(el))
|
||||
}
|
||||
|
||||
afterNavigate(() => {
|
||||
$virtualizer.scrollToIndex($_posts?.lastSeen)
|
||||
})
|
||||
</script>
|
||||
|
||||
<ul
|
||||
class="flex flex-col list-none {$userSettings.view == 'card'
|
||||
? 'gap-3 md:gap-4'
|
||||
: 'divide-y'} divide-slate-200 dark:divide-zinc-800"
|
||||
style={$userSettings.leftAlign
|
||||
? `--template-areas:
|
||||
'media meta'
|
||||
'media title'
|
||||
'media body'
|
||||
'embed embed'
|
||||
'actions actions'; --template-columns: auto 1fr;`
|
||||
: ``}
|
||||
>
|
||||
{#if posts?.length == 0}
|
||||
<div class="h-full grid place-items-center">
|
||||
<Placeholder
|
||||
icon={ArchiveBox}
|
||||
title="No posts"
|
||||
description="There are no posts that match this filter."
|
||||
>
|
||||
<Button href="/communities">
|
||||
<Icon src={Plus} size="16" mini slot="prefix" />
|
||||
<span>Follow some communities</span>
|
||||
</Button>
|
||||
</Placeholder>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- {#each combinedPosts as post, index} -->
|
||||
<!-- {#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)} -->
|
||||
<div
|
||||
style="position:relative; height: {browser
|
||||
? `${$virtualizer.getTotalSize()}px`
|
||||
: '100%'}; width: 100%;"
|
||||
>
|
||||
<div
|
||||
style="position: absolute; top: 0; left: 0; width: 100%; transform: translateY({items[0]
|
||||
? items[0].start
|
||||
: 0}px);"
|
||||
class="divide-y divide-slate-200 dark:divide-zinc-800"
|
||||
id="feed"
|
||||
>
|
||||
{#each items as row, index (row.index)}
|
||||
<li
|
||||
in:fly|global={{
|
||||
y: -8,
|
||||
duration: 300,
|
||||
opacity: 0,
|
||||
delay: 50 + index * 20,
|
||||
}}
|
||||
bind:this={virtualItemEls[index]}
|
||||
data-index={row.index}
|
||||
class="relative post-container"
|
||||
>
|
||||
<Post
|
||||
hideCommunity={community}
|
||||
view={(posts[row.index].post.featured_community ||
|
||||
posts[row.index].post.featured_local) &&
|
||||
$userSettings.posts.compactFeatured
|
||||
? 'compact'
|
||||
: $userSettings.view}
|
||||
post={posts[row.index]}
|
||||
class="transition-all duration-250"
|
||||
on:hide={() => {
|
||||
posts = posts.toSpliced(row.index, 1)
|
||||
}}
|
||||
>
|
||||
<svelte:fragment slot="badges">
|
||||
<!-- {#if posts[index].withCrossposts}
|
||||
<button
|
||||
on:click={() => {
|
||||
if (viewPost == posts[index].post.id) viewPost = -1
|
||||
else viewPost = posts[index].post.id
|
||||
}}
|
||||
>
|
||||
<Badge
|
||||
class="z-10 backdrop-blur-xl hover:brightness-110 cursor-pointer transition-all"
|
||||
color="gray-subtle"
|
||||
>
|
||||
{#if viewPost == posts[index].post.id}
|
||||
<Icon mini src={Minus} size="14" />
|
||||
{:else}
|
||||
<Icon mini src={Plus} size="14" />
|
||||
{/if}
|
||||
{posts[index].crossposts.length} crosspost{posts[index]
|
||||
.crossposts.length == 1
|
||||
? ''
|
||||
: 's'}
|
||||
</Badge>
|
||||
</button>{/if} -->
|
||||
</svelte:fragment>
|
||||
</Post>
|
||||
<!-- {#if posts[index].withCrossposts && viewPost == posts[index].post.id}
|
||||
<div
|
||||
transition:slide|global={{
|
||||
axis: 'y',
|
||||
duration: 500,
|
||||
easing: expoOut,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
class="text-sm flex flex-row gap-2 items-center"
|
||||
class:my-4={$userSettings.view == 'card'}
|
||||
>
|
||||
Crossposts <hr class="w-full dark:border-zinc-800" />
|
||||
{posts[index].crossposts.length}
|
||||
</span>
|
||||
{#each posts[index].crossposts as crosspost, index}
|
||||
<div class="w-full transition-all mb-4">
|
||||
<Post post={crosspost} view={$userSettings.view} />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if} -->
|
||||
</li>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
<!-- {/if} -->
|
||||
<!-- {/each} -->
|
||||
{/if}
|
||||
<slot />
|
||||
</ul>
|
||||
@@ -12,18 +12,19 @@ export const bestImageURL = (
|
||||
compact: boolean = true,
|
||||
width: number = 1024
|
||||
) => {
|
||||
if (width > 1024) {
|
||||
if (post.url) return `${post.url}?format=webp`
|
||||
else if (post.thumbnail_url) return `${post.thumbnail_url}?format=webp`
|
||||
}
|
||||
let fetchWidth =
|
||||
width > 1024
|
||||
? // -1 disables a small thumbnail
|
||||
-1
|
||||
: // set width to 512 if compact
|
||||
compact
|
||||
? 512
|
||||
: // otherwise, just use the original width
|
||||
width
|
||||
|
||||
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`
|
||||
if (post.thumbnail_url)
|
||||
return optimizeImageURL(post.thumbnail_url, fetchWidth)
|
||||
else if (post.url) return optimizeImageURL(post.url, fetchWidth)
|
||||
|
||||
return post.url ?? ''
|
||||
}
|
||||
@@ -34,11 +35,16 @@ export const optimizeImageURL = (
|
||||
): string => {
|
||||
try {
|
||||
const url = new URL(urlStr)
|
||||
|
||||
url.searchParams.append('format', 'webp')
|
||||
url.searchParams.append(
|
||||
'thumbnail',
|
||||
findClosestNumber([128, 256, 512, 1024], width).toString()
|
||||
)
|
||||
|
||||
if (width > 0) {
|
||||
url.searchParams.append(
|
||||
'thumbnail',
|
||||
findClosestNumber([128, 256, 512, 728, 1024, 1536], width).toString()
|
||||
)
|
||||
}
|
||||
|
||||
return url.toString()
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
|
||||
@@ -92,6 +92,10 @@
|
||||
$: embedUrl = urlToEmbed(url)
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@component
|
||||
Displays a video file or embedded video iframe.
|
||||
-->
|
||||
{#if opened}
|
||||
{#if type == 'video'}
|
||||
<!-- svelte-ignore a11y-media-has-caption -->
|
||||
|
||||
@@ -19,10 +19,17 @@
|
||||
export let post: Post
|
||||
export let type: MediaType = 'none'
|
||||
export let opened: boolean | undefined = undefined
|
||||
export let blur: boolean = post.nsfw && $userSettings.nsfwBlur
|
||||
|
||||
let showAltText = false
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@component
|
||||
This component will show either
|
||||
- A media item (pictures, videos) (large form factor posts only)
|
||||
- Embed link/card.
|
||||
-->
|
||||
{#if type == 'image'}
|
||||
{#if view == 'card' || view == 'cozy'}
|
||||
<!--disabled preloads here since most people will hover over every image while scrolling-->
|
||||
@@ -39,9 +46,9 @@
|
||||
>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={bestImageURL(post, false, 256)}
|
||||
src={bestImageURL(post, false, 64)}
|
||||
loading="lazy"
|
||||
class="-z-10 absolute top-0 left-0 w-full h-full object-cover blur-xl opacity-50"
|
||||
class="-z-10 absolute top-0 left-0 w-full h-full object-cover blur-xl opacity-40"
|
||||
/>
|
||||
<picture class="max-h-[inherit]">
|
||||
<source
|
||||
@@ -68,7 +75,7 @@
|
||||
transition-opacity duration-300 object-contain mx-auto"
|
||||
width={512}
|
||||
height={300}
|
||||
class:blur-3xl={post.nsfw && $userSettings.nsfwBlur}
|
||||
class:blur-3xl={blur}
|
||||
alt={post.alt_text ?? ''}
|
||||
/>
|
||||
</picture>
|
||||
|
||||
@@ -16,14 +16,43 @@
|
||||
export let type: MediaType = 'none'
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="w-24 sm:w-32 h-24 relative group/media {$$props.class ?? ''}"
|
||||
style={$$props.style ?? ''}
|
||||
>
|
||||
{#if post.alt_text}
|
||||
<Popover
|
||||
openOnHover
|
||||
placement={$userSettings.leftAlign ? 'bottom-start' : 'bottom-end'}
|
||||
<!--
|
||||
@component
|
||||
Thumbnails for compact and list view posts.
|
||||
-->
|
||||
<div
|
||||
class="w-24 sm:w-32 h-24 relative group/media {$$props.class ?? ''}"
|
||||
style={$$props.style ?? ''}
|
||||
>
|
||||
{#if post.alt_text}
|
||||
<Popover
|
||||
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>
|
||||
<div class="max-w-sm">
|
||||
{post.alt_text}
|
||||
</div>
|
||||
</Popover>
|
||||
{/if}
|
||||
<svelte:element
|
||||
this={!$userSettings.expandImages || type != 'image' ? 'a' : 'button'}
|
||||
href={postLink(post)}
|
||||
on:click={() => {
|
||||
if (type == 'image') {
|
||||
showImage(bestImageURL(post, false, 2048))
|
||||
}
|
||||
}}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<Material
|
||||
slot="target"
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
class="items-center flex flex-row gap-1 hover:underline max-w-full min-w-0 {$$props.class ??
|
||||
''}"
|
||||
href="/u/{user.name}@{new URL(user.actor_id).hostname}"
|
||||
data-sveltekit-preload-data="tap"
|
||||
>
|
||||
{#if avatar}
|
||||
<Avatar
|
||||
@@ -32,7 +33,7 @@
|
||||
class="flex gap-0 items-center flex-shrink max-w-full min-w-0"
|
||||
class:ml-0.5={avatar}
|
||||
>
|
||||
<span class:font-medium={showInstance}>
|
||||
<span class:font-medium={showInstance} class="username-text">
|
||||
{$userSettings.displayNames ? user.display_name || user.name : user.name}
|
||||
</span>
|
||||
{#if showInstance}
|
||||
@@ -62,6 +63,14 @@
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.username-text {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
</style>
|
||||
@@ -3,7 +3,7 @@
|
||||
import { createAvatar } from '@dicebear/core'
|
||||
import * as initials from '@dicebear/initials'
|
||||
|
||||
const sizes = [48, 64, 128, 256, 512]
|
||||
const sizes = [16, 32, 48, 64, 128, 256, 512]
|
||||
|
||||
export let url: string | undefined
|
||||
export let alt: string = ''
|
||||
|
||||
@@ -68,7 +68,11 @@
|
||||
|
||||
<svelte:window bind:innerWidth={screenWidth} />
|
||||
|
||||
<div class="shell {$$props.class}" style={colorsToVars($colors)}>
|
||||
<div
|
||||
{...$$restProps}
|
||||
class="shell {$$props.class}"
|
||||
style={colorsToVars($colors)}
|
||||
>
|
||||
<slot />
|
||||
<div
|
||||
class="
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
<h1 class="text-3xl font-bold flex items-center gap-2 {$$props.class ?? ''}">
|
||||
<script lang="ts">
|
||||
import { userSettings } from '$lib/settings'
|
||||
</script>
|
||||
|
||||
<h1
|
||||
class="text-3xl font-bold flex items-center gap-2 {$userSettings.font ==
|
||||
'satoshi/nunito'
|
||||
? 'font-display'
|
||||
: ''} {$$props.class ?? ''}"
|
||||
>
|
||||
<slot />
|
||||
</h1>
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { profile, profileData } from '$lib/auth.js'
|
||||
import { notifications, profile, profileData } from '$lib/auth.js'
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
|
||||
import {
|
||||
@@ -112,7 +112,7 @@
|
||||
class="relative"
|
||||
isSelectedFilter={(path) => path.startsWith('/admin')}
|
||||
>
|
||||
{#if ($profile?.user?.notifications.applications ?? 0) > 0}
|
||||
{#if ($notifications.applications ?? 0) > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
||||
/>
|
||||
@@ -125,7 +125,7 @@
|
||||
label={$t('nav.moderation')}
|
||||
class="relative"
|
||||
>
|
||||
{#if ($profile?.user?.notifications.reports ?? 0) > 0}
|
||||
{#if ($notifications.reports ?? 0) > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
||||
/>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth'
|
||||
import { notifications, profile } from '$lib/auth'
|
||||
|
||||
import {
|
||||
Badge,
|
||||
@@ -73,7 +73,7 @@
|
||||
alt={$profile.user.local_user_view.person.name}
|
||||
/>
|
||||
</div>
|
||||
{#if $profile.user.notifications.inbox > 0}
|
||||
{#if $notifications.inbox > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute top-0 left-0 z-10"
|
||||
/>
|
||||
@@ -104,9 +104,9 @@
|
||||
<MenuButton link href="/inbox">
|
||||
<Icon src={Inbox} mini width={16} slot="prefix" />
|
||||
{$t('profile.inbox')}
|
||||
{#if $profile.user.notifications.inbox > 0}
|
||||
{#if $notifications.inbox > 0}
|
||||
<Badge color="red-subtle" class="text-xs ml-auto font-bold !py-0.5">
|
||||
{$profile.user.notifications.inbox}
|
||||
{$notifications.inbox}
|
||||
</Badge>
|
||||
{/if}
|
||||
</MenuButton>
|
||||
|
||||
@@ -13,6 +13,9 @@ import {
|
||||
ServerStack,
|
||||
PencilSquare,
|
||||
MapPin,
|
||||
Fire,
|
||||
ArrowTrendingUp,
|
||||
Star,
|
||||
} from 'svelte-hero-icons'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
@@ -38,6 +41,22 @@ export const defaultLinks: Link[] = [
|
||||
url: '/?type=Subscribed',
|
||||
label: t.get('filter.location.subscribed'),
|
||||
},
|
||||
{
|
||||
url: '/?type=All&sort=Hot',
|
||||
label: t.get('filter.sort.hot'),
|
||||
},
|
||||
{
|
||||
url: '/?type=All&sort=Active',
|
||||
label: t.get('filter.sort.active'),
|
||||
},
|
||||
{
|
||||
url: '/?type=All&sort=TopDay',
|
||||
label: t.get('filter.sort.top.time.day'),
|
||||
},
|
||||
{
|
||||
url: '/?type=All&sort=New',
|
||||
label: t.get('filter.sort.new'),
|
||||
},
|
||||
{
|
||||
url: '/communities',
|
||||
label: t.get('nav.communities'),
|
||||
@@ -74,6 +93,14 @@ export const iconOfLink = (url: string): IconSource => {
|
||||
return Newspaper
|
||||
case '/?type=Local':
|
||||
return MapPin
|
||||
case '/?type=All&sort=Hot':
|
||||
return Fire
|
||||
case '/?type=All&sort=Active':
|
||||
return ArrowTrendingUp
|
||||
case '/?type=All&sort=TopDay':
|
||||
return ChartBar
|
||||
case '/?type=All&sort=New':
|
||||
return Star
|
||||
case '/communities':
|
||||
return GlobeAlt
|
||||
case '/search':
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
UserCircle,
|
||||
UserGroup,
|
||||
} from 'svelte-hero-icons'
|
||||
import { profile, profileData } from '$lib/auth.js'
|
||||
import { notifications, profile, profileData } from '$lib/auth.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
|
||||
import CommunityList from '$lib/components/ui/sidebar/CommunityList.svelte'
|
||||
@@ -70,12 +70,12 @@
|
||||
<SidebarButton icon={Inbox} href="/inbox">
|
||||
<span slot="label" class="flex items-center gap-2">
|
||||
{$t('profile.inbox')}
|
||||
{#if $profile?.user?.notifications.inbox}
|
||||
{#if $notifications.inbox}
|
||||
<Badge
|
||||
class="w-5 h-5 !p-0 grid place-items-center ml-auto"
|
||||
color="red-subtle"
|
||||
>
|
||||
{$profile?.user?.notifications.inbox}
|
||||
{$notifications.inbox}
|
||||
</Badge>
|
||||
{/if}
|
||||
</span>
|
||||
|
||||
Reference in new issue
Block a user