migrate: convert most components to svelte 5

This commit is contained in:
Xylight committed 2024-10-25 19:33:27 -07:00
1 parent d670f39f0a
commit 10ef4123da
225 files changed
+5441 -3341

No files matched your search

@@ -9,14 +9,26 @@
import { fly, slide } from 'svelte/transition'
import { combineCrossposts } from './crosspost'
export let posts: PostView[]
export let community: boolean = false
export let feedData: any
let etc = $$restProps
interface Props {
posts: PostView[]
community?: boolean
feedData: any
children?: import('svelte').Snippet
[key: string]: any
}
$: combinedPosts = combineCrossposts(posts)
let {
posts = $bindable(),
community = false,
feedData,
children,
...rest
}: Props = $props()
let etc = rest
let viewPost: number = -1
let combinedPosts = $derived(combineCrossposts(posts))
let viewPost: number = $state(-1)
</script>
<ul
@@ -32,7 +44,9 @@
description="There are no posts that match this filter."
>
<Button href="/communities">
<Icon src={Plus} size="16" mini slot="prefix" />
{#snippet prefix()}
<Icon src={Plus} size="16" mini />
{/snippet}
<span>Follow some communities</span>
</Button>
</Placeholder>
@@ -53,10 +67,10 @@
posts = posts.toSpliced(index, 1)
}}
>
<svelte:fragment slot="badges">
{#snippet badges()}
{#if post.withCrossposts}
<button
on:click={() => {
onclick={() => {
if (viewPost == post.post.id) viewPost = -1
else viewPost = post.post.id
}}
@@ -76,7 +90,7 @@
: 's'}
</Badge>
</button>{/if}
</svelte:fragment>
{/snippet}
</Post>
{#if post.withCrossposts && viewPost == post.post.id}
<div
@@ -104,5 +118,5 @@
{/if}
{/each}
{/if}
<slot />
{@render children?.()}
</ul>
@@ -1,4 +1,6 @@
<script lang="ts">
import { run } from 'svelte/legacy'
import Post from '$lib/components/lemmy/post/Post.svelte'
import Placeholder from '$lib/components/ui/Placeholder.svelte'
import { userSettings } from '$lib/settings.js'
@@ -20,7 +22,7 @@
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 { onMount, tick, type SvelteComponent } from 'svelte'
import {
createVirtualizer,
createWindowVirtualizer,
@@ -39,12 +41,28 @@
import type { Readable } from 'svelte/motion'
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
export let posts: PostView[]
export let community: boolean = false
export let feedId: PostFeedID
let virtualItemEls: HTMLElement[] = $state([])
let virtualListEl: HTMLElement | undefined = $state(undefined)
let virtualItemEls: HTMLElement[] = []
let virtualListEl: HTMLElement | undefined = undefined
afterNavigate(() => {
$virtualizer.scrollToIndex($postFeeds[feedId]?.lastSeen ?? 0)
})
interface Props {
posts: PostView[]
community?: boolean
feedId: PostFeedID
feedData: PostFeed['data']
children?: import('svelte').Snippet
}
let {
posts = $bindable(),
community = false,
feedId,
feedData = $bindable(),
children,
}: Props = $props()
const virtualizer = createWindowVirtualizer({
count: posts.length,
@@ -55,27 +73,9 @@
},
})
$: items = $virtualizer.getVirtualItems()
$: if (virtualItemEls.length) {
virtualItemEls.forEach($virtualizer.measureElement)
}
$: if (posts.length && virtualListEl)
$virtualizer.setOptions({
scrollMargin: virtualListEl?.offsetTop,
count: posts.length,
})
afterNavigate(() => {
$virtualizer.scrollToIndex($postFeeds[feedId]?.lastSeen ?? 0)
})
export let feedData: PostFeed['data']
let error: any = undefined
let loading = false
let hasMore = true
let error: any = $state(undefined)
let loading = $state(false)
let hasMore = $state(true)
async function loadMore() {
if (!hasMore || loading) return
@@ -181,6 +181,19 @@
await tick()
$virtualizer.measure()
})
let items = $derived($virtualizer.getVirtualItems())
run(() => {
if (virtualItemEls.length) {
virtualItemEls.forEach($virtualizer.measureElement)
}
})
run(() => {
if (posts.length && virtualListEl)
$virtualizer.setOptions({
scrollMargin: virtualListEl?.offsetTop,
count: posts.length,
})
})
</script>
<!-- <svelte:window on:keydown={handleKeydown} /> -->
@@ -198,7 +211,9 @@
description="There are no posts that match this filter."
>
<Button href="/communities">
<Icon src={Plus} size="16" mini slot="prefix" />
{#snippet prefix()}
<Icon src={Plus} size="16" mini />
{/snippet}
<span>Follow some communities</span>
</Button>
</Placeholder>
@@ -284,16 +299,20 @@
// @ts-ignore
community_name: feedData.community_name ?? 'undefined',
})}
<Button slot="action" color="tertiary">
<Icon src={ChevronDoubleUp} size="16" micro slot="prefix" />
{$t('routes.post.scrollToTop')}
</Button>
{#snippet action()}
<Button color="tertiary">
{#snippet prefix()}
<Icon src={ChevronDoubleUp} size="16" micro />
{/snippet}
{$t('routes.post.scrollToTop')}
</Button>
{/snippet}
</EndPlaceholder>
</div>
{/if}
<InfiniteScroll window threshold={1000} on:loadMore={loadMore} />
{/if}
<slot />
{@render children?.()}
</ul>
<style lang="postcss">
@@ -1,6 +1,6 @@
import { userSettings } from "$lib/settings"
import type { PostView } from "lemmy-js-client"
import { get } from "svelte/store"
import { userSettings } from '$lib/settings.svelte'
import type { PostView } from 'lemmy-js-client'
import { get } from 'svelte/store'
export type PostViewWithCrossposts = PostView & {
withCrossposts: true
@@ -54,4 +54,4 @@ export const combineCrossposts = (
})
return results
}
}