update to svelte 5

This commit is contained in:
Max Nuding 2024-10-29 16:26:07 +01:00
parent d39ccba927
commit 66f09cf5a3
No known key found for this signature in database
9 changed files with 558 additions and 1244 deletions

1668
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,8 +15,8 @@
},
"devDependencies": {
"@sveltejs/adapter-node": "^5.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@sveltejs/kit": "^2.7.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@types/node": "^22.6.1",
"@types/sqlite3": "^3.0.0",
"@types/ws": "^8.5.0",
@ -25,12 +25,12 @@
"@zerodevx/svelte-toast": "^0.9.3",
"eslint": "^9.11.1",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-svelte": "^2.0.0",
"prettier": "^3.0.0",
"prettier-plugin-svelte": "^3.0.0",
"svelte": "^4.0.0",
"eslint-plugin-svelte": "^2.45.1",
"prettier": "^3.1.0",
"prettier-plugin-svelte": "^3.2.6",
"svelte": "^5",
"svelte-check": "^4.0.0",
"tslib": "^2.4.1",
"tslib": "^2.0.0",
"typescript": "^5.0.0",
"vite": "^5.0.0"
},

View File

@ -1,7 +1,11 @@
<script lang="ts">
import type { Account } from '$lib/mastodon/response';
export let account: Account;
interface Props {
account: Account;
}
let { account }: Props = $props();
</script>
<a href={account.url} target="_blank">{account.display_name} @{account.acct}</a>

View File

@ -1,11 +1,13 @@
<script lang="ts">
import type { Account } from '$lib/mastodon/response';
export let account: Account;
let avatarDescription: string;
let sourceSetHtml: string;
$: avatarDescription = `Avatar for ${account.acct}`;
$: {
interface Props {
account: Account;
}
let { account }: Props = $props();
let avatarDescription: string = $derived(`Avatar for ${account.acct}`);
let sourceSetHtml: string = $derived.by(() => {
// Sort thumbnails by file type. This is important, because the order of the srcset entries matter.
// We need the best format to be first
const formatPriority = new Map<string, number>([
@ -33,8 +35,8 @@
const srcset = entry[1].join(', ');
html += `<source srcset="${srcset}" type="${entry[0]}" />`;
}
sourceSetHtml = html;
}
return html;
});
</script>
<picture>

View File

@ -1,33 +1,34 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
import LoadingSpinnerComponent from '$lib/components/LoadingSpinnerComponent.svelte';
export let moreAvailable = false;
export let isLoading = false;
let displayText = '';
let title = '';
let disabled: boolean;
interface Props {
moreAvailable?: boolean;
isLoading?: boolean;
loadOlderPosts: any;
}
$: if (isLoading) {
displayText = 'Loading...';
let { moreAvailable = false, isLoading = false, loadOlderPosts }: Props = $props();
let displayText = $derived.by(() => {
if (isLoading) {
return 'Loading...';
} else if (!moreAvailable) {
displayText = 'You reached the end';
} else {
displayText = 'Load More';
return 'You reached the end';
}
$: disabled = !moreAvailable || isLoading;
$: title = moreAvailable ? 'Load More' : 'There be dragons!';
return 'Load More';
});
let title = $derived(moreAvailable ? 'Load More' : 'There be dragons!');
let disabled: boolean = $derived(!moreAvailable || isLoading);
const dispatch = createEventDispatcher<{
/*const dispatch = createEventDispatcher<{
loadOlderPosts: string;
}>();
}>();
function loadOlderPosts() {
function loadOlderPosts() {
dispatch('loadOlderPosts');
}
}*/
</script>
<button on:click={loadOlderPosts} {disabled} {title}>
<button onclick={() => loadOlderPosts()} {disabled} {title}>
<div class="loading" class:collapsed={!isLoading}>
<LoadingSpinnerComponent size="0.5em" thickness="6px" />
</div>

View File

@ -1,9 +1,13 @@
<script lang="ts">
export let size = '64px';
export let thickness = '6px';
interface Props {
size?: string;
thickness?: string;
}
let { size = '64px', thickness = '6px' }: Props = $props();
</script>
<div class="lds-dual-ring" style="--size: {size}; --thickness: {thickness}" />
<div class="lds-dual-ring" style="--size: {size}; --thickness: {thickness}"></div>
<style>
.lds-dual-ring {

View File

@ -6,15 +6,21 @@
import { secondsSince, relativeTime } from '$lib/relativeTime';
import { onMount } from 'svelte';
export let post: Post;
let displayRelativeTime = false;
const absoluteDate = new Date(post.created_at).toLocaleString();
let dateCreated = absoluteDate;
const timePassed = secondsSince(new Date(post.created_at));
$: if (displayRelativeTime) {
dateCreated = relativeTime($timePassed) ?? absoluteDate;
interface Props {
post: Post;
}
let { post }: Props = $props();
let displayRelativeTime = $state(false);
const absoluteDate = new Date(post.created_at).toLocaleString();
const timePassed = secondsSince(new Date(post.created_at));
let dateCreated = $derived.by(() => {
if (displayRelativeTime) {
return relativeTime($timePassed) ?? absoluteDate;
}
return absoluteDate;
});
const songs = filterDuplicates(post.songs ?? []);
function filterDuplicates(songs: SongInfo[]): SongInfo[] {

View File

@ -1,6 +1,11 @@
<script lang="ts">
import FooterComponent from '$lib/components/FooterComponent.svelte';
import { SvelteToast } from '@zerodevx/svelte-toast';
interface Props {
children?: import('svelte').Snippet;
}
let { children }: Props = $props();
const options = {
pausable: true,
@ -8,7 +13,7 @@
};
</script>
<slot />
{@render children?.()}
<SvelteToast {options} />
<div class="footer">
<FooterComponent />

View File

@ -12,7 +12,11 @@
import { cubicInOut } from 'svelte/easing';
import { errorToast } from '$lib/errorToast';
export let data: PageData;
interface Props {
data: PageData;
}
let { data = $bindable() }: Props = $props();
interface FetchOptions {
since?: string;
@ -26,8 +30,8 @@
const refreshInterval = parseInt(PUBLIC_REFRESH_INTERVAL);
let interval: ReturnType<typeof setTimeout> | null = null;
let moreOlderPostsAvailable = true;
let loadingOlderPosts = false;
let moreOlderPostsAvailable = $state(true);
let loadingOlderPosts = $state(false);
// Needed, so that edgeFly() can do its thing:
// To determine whether a newly loaded post is older than the existing ones, is required to know what the oldest
@ -152,7 +156,7 @@
</svelte:head>
<h2>{PUBLIC_MASTODON_INSTANCE_DISPLAY_NAME} music list</h2>
<div class="wrapper">
<div />
<div></div>
<div class="posts">
{#if data.posts.length === 0}
Sorry, no posts recommending music have been found yet
@ -171,12 +175,12 @@
</div>
{/each}
<LoadMoreComponent
on:loadOlderPosts={loadOlderPosts}
{loadOlderPosts}
moreAvailable={moreOlderPostsAvailable}
isLoading={loadingOlderPosts}
/>
</div>
<div />
<div></div>
</div>
<style>