Migrates to svelte 5

This commit is contained in:
Christian Beutel
2025-01-24 17:46:13 +01:00
parent 7571f6e9b9
commit 3721b7f537
106 changed files with 5524 additions and 4232 deletions

View File

@@ -1,6 +1,6 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { page } from "$app/stores";
import { page } from "$app/state";
import type { Notification } from "$lib/models/notification";
import {
notifications_index,
@@ -16,24 +16,23 @@
import emptyStateNotificationLight from "$lib/assets/svgs/empty_states/empty_state_notification_light.svg";
import { theme } from "$lib/stores/theme_store";
let notifications: Notification[] = [];
let notifications: Notification[] = $state([]);
const pagination = {
page: $page.data.notifications.page,
totalPages: $page.data.notifications.totalPages,
page: page.data.notifications.page,
totalPages: page.data.notifications.totalPages,
};
let loadingNextPage: boolean = false;
let isOpen = false;
let loadingNextPage: boolean = $state(false);
let isOpen = $state(false);
$: unreadCount = notifications.reduce(
(value, n) => (value += n.seen ? 0 : 1),
0,
let unreadCount = $derived(
notifications.reduce((value, n) => (value += n.seen ? 0 : 1), 0),
);
onMount(() => {
if (!notifications.length && $page.data.notifications?.items?.length) {
notifications = $page.data.notifications.items;
if (!notifications.length && page.data.notifications?.items?.length) {
notifications = page.data.notifications.items;
}
});
@@ -88,18 +87,21 @@
loadingNextPage = false;
}
async function handleNotificationClick(e: CustomEvent) {
await notifications_mark_as_seen(e.detail.notification);
e.detail.notification.seen = true;
async function handleNotificationClick(data: {
notification: Notification;
link: string | null;
}) {
await notifications_mark_as_seen(data.notification);
data.notification.seen = true;
notifications = notifications;
if (e.detail.link) {
goto(e.detail.link);
if (data.link) {
goto(data.link);
}
}
</script>
<svelte:window on:mouseup={handleWindowClick} />
<svelte:window onmouseup={handleWindowClick} />
<div class="dropdown relative">
{#if unreadCount > 0}
@@ -110,7 +112,11 @@
</div>
{/if}
<div class="dropdown-toggle">
<button on:click={toggleMenu} class="btn-icon">
<button
aria-label="Toggle notification dropdown"
onclick={toggleMenu}
class="btn-icon"
>
<i class="fa fa-bell"></i>
</button>
</div>
@@ -119,7 +125,7 @@
<ul
class="menu absolute bg-menu-background border border-input-border rounded-l-xl rounded-b-xl shadow-md right-0 overflow-scroll mt-4 max-h-96 w-72"
class:none={isOpen}
on:scroll={onListScroll}
onscroll={onListScroll}
style="z-index: 1001"
in:fly={{ y: -10, duration: 150 }}
out:fly={{ y: -10, duration: 150 }}
@@ -131,13 +137,14 @@
{:else if notifications.length}
{#each notifications as notification}
<NotificationCard
on:click={handleNotificationClick}
onclick={(data) => handleNotificationClick(data)}
{notification}
></NotificationCard>
{/each}
{:else}
<div class="text-center p-8">
<img class="mx-auto"
<img
class="mx-auto"
src={$theme === "light"
? emptyStateNotificationLight
: emptyStateNotificationDark}