Revert "perf: improve efficiency and performance"

This commit is contained in:
Xylight authored and GitHub committed 2025-08-01 21:26:04 +00:00
1 parent 7e188f218a
commit 4177b42fc2
32 files changed
+470 -248

No files matched your search

+20 -1
View File
@@ -1,6 +1,7 @@
<script lang="ts">
import { goto } from '$app/navigation'
import { profile } from '$lib/auth.svelte'
import { mediaType } from '$lib/components/lemmy/post/helpers.js'
import { mediaType, postLink } from '$lib/components/lemmy/post/helpers.js'
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte'
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
@@ -27,6 +28,15 @@
return rule
}
function onClick(e: Event) {
const event = e as Event
const parent = document.getElementById(post.post.id.toString())
if (event.target == parent) {
goto(postLink(post.post))
}
}
interface Props {
post: PostView
actions?: boolean
@@ -76,6 +86,8 @@
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_no_noninteractive_tabindex -->
<div
class={[
'post relative max-w-full min-w-0 w-full cursor-pointer outline-hidden group',
@@ -85,6 +97,13 @@
clazz,
]}
id={post.post.id.toString()}
onclick={e => {
onClick(e)
}}
onkeydown={e => {
if (e.key == 'Enter') onClick(e)
}}
tabindex="0"
{style}
>
<PostMeta
@@ -6,6 +6,7 @@
isAdmin,
report,
} from '$lib/components/lemmy/moderation/moderation.js'
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
import TextProps from '$lib/components/ui/text/TextProps.svelte'
import { publishedToDate } from '$lib/components/util/date'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
@@ -45,7 +46,6 @@
Newspaper,
PencilSquare,
Share,
ShieldCheck,
Trash,
UserCircle,
XMark,
@@ -161,21 +161,14 @@
</Button>
{/if}
{#if profile.current?.user && (amMod(profile.current.user, post.community) || isAdmin(profile.current.user))}
{#await import('$lib/components/lemmy/moderation/ModerationMenu.svelte') then { default: ModerationMenu }}
<ModerationMenu bind:item={post}>
{#snippet target(acting)}
<Button
color="ghost"
rounding="pill"
loading={acting}
class={buttonSquare}
size="custom"
>
<Icon src={ShieldCheck} size="18" mini />
</Button>
{/snippet}
</ModerationMenu>
{/await}
<ModerationMenu
size="custom"
color="ghost"
rounding="pill"
class={buttonSquare}
bind:item={post}
community={post.community}
/>
{/if}
{#if profile.current?.jwt}
@@ -6,7 +6,7 @@
post: PostView
}
let { post }: Props = $props()
let { post } = $props()
</script>
<Post {post} class="py-0!" />
+75 -83
View File
@@ -1,14 +1,4 @@
<script lang="ts" module>
type BadgeType =
| 'nsfw'
| 'saved'
| 'featured'
| 'deleted'
| 'removed'
| 'locked'
| 'moderator'
| 'admin'
export interface Tag {
content: string
color?: string
@@ -66,11 +56,11 @@
import { settings, type View } from '$lib/settings.svelte'
import type { Community, Person, SubscribedType } from 'lemmy-js-client'
import { Badge, Popover } from 'mono-svelte'
import Material from 'mono-svelte/materials/Material.svelte'
import {
Bookmark,
ExclamationTriangle,
Icon,
LockClosed,
Megaphone,
PaperAirplane,
Pencil,
@@ -80,64 +70,7 @@
} from 'svelte-hero-icons'
import CommunityHeader from '../community/CommunityHeader.svelte'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
const badgeToData: Map<
BadgeType,
{
icon: IconSource
color: 'red-subtle' | 'yellow-subtle' | 'green-subtle'
label: string
}
> = new Map([
[
'nsfw',
{
icon: ExclamationTriangle,
color: 'red-subtle',
label: t.get('post.badges.nsfw'),
},
],
[
'saved',
{
icon: Bookmark,
color: 'yellow-subtle',
label: t.get('post.badges.saved'),
},
],
[
'featured',
{
icon: Megaphone,
color: 'green-subtle',
label: t.get('post.badges.featured'),
},
],
[
'removed',
{
icon: Trash,
color: 'green-subtle',
label: t.get('post.badges.removed'),
},
],
[
'deleted',
{
icon: Trash,
color: 'red-subtle',
label: t.get('post.badges.deleted'),
},
],
[
'locked',
{
icon: Lock,
color: 'yellow-subtle',
label: t.get('post.badges.locked'),
},
],
])
import Material from 'mono-svelte/materials/Material.svelte'
interface Props {
community?: Community
@@ -150,7 +83,17 @@
read?: boolean
edited?: string
view?: View
badges?: Record<BadgeType, boolean>
// Badges
badges?: {
nsfw: boolean
saved: boolean
featured: boolean
deleted: boolean
removed: boolean
locked: boolean
moderator: boolean
admin: boolean
}
tags?: Tag[]
style?: string
titleClass?: string
@@ -253,7 +196,10 @@
/>
{/if}
<div
class="flex flex-row gap-1.5 items-center no-list-margin"
class="flex flex-row gap-1.5 items-center
no-list-margin {view == 'compact' && showCommunity
? 'min-[480px]:mx-2'
: ''}"
style="grid-area: stats;"
>
{#if user}
@@ -263,7 +209,7 @@
src={PaperAirplane}
size="12"
micro
class="rotate-180 text-slate-400 dark:text-zinc-600 max-[480px]:hidden ml-2"
class="rotate-180 text-slate-400 dark:text-zinc-600 max-[480px]:hidden"
/>
{/if}
<UserLink
@@ -323,20 +269,66 @@
</a>
{/each}
{/if}
{#each Object.keys(badges)
// filter by ones that are true
.filter(i => badges[i as BadgeType] == true)
// get from predetermined map
.map(i => badgeToData.get(i as BadgeType))
// remove null
.filter(i => i != undefined) as badge}
<Badge label={badge.label} color={badge.color} allowIconOnly>
{#if badges.nsfw}
<Badge label={$t('post.badges.nsfw')} color="red-subtle" allowIconOnly>
{#snippet icon()}
<Icon src={badge.icon} micro size="14" />
<Icon src={ExclamationTriangle} size="14" micro />
{/snippet}
{badge.label}
{$t('post.badges.nsfw')}
</Badge>
{/each}
{/if}
{#if badges.saved}
<Badge
label={$t('post.badges.saved')}
color="yellow-subtle"
allowIconOnly
>
{#snippet icon()}
<Icon src={Bookmark} micro size="14" />
{/snippet}
{$t('post.badges.saved')}
</Badge>
{/if}
{#if badges.locked}
<Badge
label={$t('post.badges.locked')}
color="yellow-subtle"
allowIconOnly
>
{#snippet icon()}
<Icon src={LockClosed} micro size="14" />
{/snippet}
<span class="max-md:hidden">{$t('post.badges.locked')}</span>
</Badge>
{/if}
{#if badges.removed}
<Badge label={$t('post.badges.removed')} color="red-subtle" allowIconOnly>
{#snippet icon()}
<Icon src={Trash} micro size="14" />
{/snippet}
<span class="max-md:hidden">{$t('post.badges.removed')}</span>
</Badge>
{/if}
{#if badges.deleted}
<Badge label={$t('post.badges.deleted')} color="red-subtle" allowIconOnly>
{#snippet icon()}
<Icon src={Trash} micro size="14" />
{/snippet}
<span class="max-md:hidden">{$t('post.badges.deleted')}</span>
</Badge>
{/if}
{#if badges.featured}
<Badge
label={$t('post.badges.featured')}
color="green-subtle"
allowIconOnly
>
{#snippet icon()}
<Icon src={Megaphone} micro size="14" />
{/snippet}
<span class="max-md:hidden">{$t('post.badges.featured')}</span>
</Badge>
{/if}
{@render extraBadges?.()}
</div>
</header>
@@ -50,6 +50,7 @@
let hasMore = $state(true)
async function loadMore() {
console.log(hasMore, loading)
if (!hasMore || loading) return
try {
@@ -182,10 +183,10 @@
{#snippet item(row)}
<li
data-index={row}
style={row < 9 ? `--anim-delay: ${row * 50}ms` : ''}
style={row < 7 ? `--anim-delay: ${row * 50}ms` : ''}
class={[
'relative post-container px-3 sm:px-6',
row < 9 && 'pop-in opacity-0',
row < 7 && 'pop-in opacity-0',
]}
>
<Post
@@ -218,7 +219,12 @@
<Icon src={ExclamationTriangle} size="24" solid></Icon>
</div>
<pre class="py-0.5">{error}</pre>
<Button color="primary" {loading} onclick={loadMore}>
<Button
color="primary"
{loading}
disabled={loading}
onclick={() => loadMore()}
>
{$t('message.retry')}
</Button>
</div>
@@ -250,7 +256,14 @@
</EndPlaceholder>
</div>
{/if}
<InfiniteScroll window threshold={600} on:loadMore={loadMore} />
<InfiniteScroll
window
threshold={600}
on:loadMore={() => {
console.log('loadMore triggered')
loadMore()
}}
/>
{/if}
{@render children?.()}
</ul>
@@ -269,6 +282,6 @@
.pop-in {
animation: popIn 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) forwards
var(--anim-delay, 0ms);
var(--anim-delay);
}
</style>
@@ -1,6 +1,5 @@
import { settings } from '$lib/settings.svelte'
import type { PostView } from 'lemmy-js-client'
import { SvelteMap, SvelteSet } from 'svelte/reactivity'
export type PostViewWithCrossposts = PostView & {
withCrossposts: true
@@ -11,12 +10,12 @@ export type PostViewWithoutCrossposts = PostView & { withCrossposts?: false }
export const combineCrossposts = (
posts: PostView[],
): (PostViewWithCrossposts | PostViewWithoutCrossposts)[] => {
const urlMap = new SvelteMap<
const urlMap = new Map<
string,
PostViewWithCrossposts | PostViewWithoutCrossposts
>()
const results: (PostViewWithCrossposts | PostViewWithoutCrossposts)[] = []
const seenUrls = new SvelteSet<string>()
const seenUrls = new Set<string>()
posts?.forEach(post => {
if (
@@ -24,7 +24,7 @@
<svelte:element
this={settings.expandImages ? 'button' : 'a'}
href={postLink(post)}
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900 cursor-pointer"
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900"
data-sveltekit-preload-data="off"
aria-label={post.name}
onclick={() => showImage(bestImageURL(post, false, -1, null))}