diff --git a/src/routes/settings/maintenance/+page.svelte b/src/routes/settings/maintenance/+page.svelte index 306b168..6a606c0 100644 --- a/src/routes/settings/maintenance/+page.svelte +++ b/src/routes/settings/maintenance/+page.svelte @@ -2,31 +2,15 @@ import Menu from "$components/ui/menu/Menu.svelte"; import MenuLink from "$components/ui/menu/MenuLink.svelte"; import {activeProfileStore, maintenanceProfilesStore} from "$stores/maintenance-profiles-store.js"; - import {onDestroy} from "svelte"; /** @type {import('$lib/extension/entities/MaintenanceProfile.js').default[]} */ let profiles = []; - /** @type {string|null} */ - let activeProfileId = null; - const unsubscribeFromProfiles = maintenanceProfilesStore.subscribe(updatedProfiles => { - profiles = updatedProfiles.sort( - (a, b) => b.settings.name.localeCompare(a.settings.name) - ); - }); - - const unsubscribeFromActiveProfile = activeProfileStore.subscribe(profileId => { - activeProfileId = profileId; - }); + $: profiles = $maintenanceProfilesStore.sort((a, b) => b.settings.name.localeCompare(a.settings.name)); function resetActiveProfile() { - activeProfileStore.set(null); + $activeProfileStore = null; } - - onDestroy(() => { - unsubscribeFromProfiles(); - unsubscribeFromActiveProfile(); - });
\ No newline at end of file + diff --git a/src/routes/settings/maintenance/[id]/+page.svelte b/src/routes/settings/maintenance/[id]/+page.svelte index 94721fe..fbf5fc0 100644 --- a/src/routes/settings/maintenance/[id]/+page.svelte +++ b/src/routes/settings/maintenance/[id]/+page.svelte @@ -16,34 +16,26 @@ goto('/maintenance/profiles/new/edit'); } - const unsubscribeFromProfiles = maintenanceProfilesStore.subscribe(profiles => { - const resolvedProfile = profiles.find(p => p.id === profileId); + $: { + const resolvedProfile = $maintenanceProfilesStore.find(profile => profile.id === profileId); if (resolvedProfile) { profile = resolvedProfile; - return; + } else { + console.warn(`Profile ${profileId} not found.`); + goto('/settings/maintenance'); } + } - console.warn(`Profile ${profileId} not found.`); - goto('/settings/maintenance'); - }); - - const unsubscribeFromActiveProfile = activeProfileStore.subscribe(activeProfileId => { - isActiveProfile = activeProfileId === profileId; - }) + $: isActiveProfile = $activeProfileStore === profileId; function activateProfile() { if (isActiveProfile) { return; } - activeProfileStore.set(profileId); + $activeProfileStore = profileId; } - - onDestroy(() => { - unsubscribeFromProfiles(); - unsubscribeFromActiveProfile(); - });