🧼 Migrates svelte-modals to 2.0

This commit is contained in:
Rune Harlyk
2025-03-01 23:21:22 +01:00
committed by Rune Harlyk
parent 31dd7f7ba4
commit d90dbbcf21
9 changed files with 54 additions and 57 deletions
@@ -28,7 +28,6 @@
}); });
let message = $state('Preparing ...'); let message = $state('Preparing ...');
let timerId: number = $state();
$effect(() => { $effect(() => {
if ($telemetry.download_ota.status == 'progress') { if ($telemetry.download_ota.status == 'progress') {
@@ -39,7 +38,7 @@
message = 'Restarting ...'; message = 'Restarting ...';
progress = 0; progress = 0;
// Reload page after 5 sec // Reload page after 5 sec
timerId = setTimeout(() => { setTimeout(() => {
modals.closeAll(); modals.closeAll();
location.reload(); location.reload();
}, 5000); }, 5000);
@@ -90,7 +89,7 @@
class="btn btn-warning text-warning-content inline-flex flex-none items-center" class="btn btn-warning text-warning-content inline-flex flex-none items-center"
disabled={updating} disabled={updating}
onclick={() => { onclick={() => {
closeAllModals(); modals.closeAll();
location.reload(); location.reload();
}} }}
> >
+6 -1
View File
@@ -169,7 +169,12 @@
<div class="bg-base-200 text-base-content flex h-full w-80 flex-col p-4"> <div class="bg-base-200 text-base-content flex h-full w-80 flex-col p-4">
<LogoButton {appName} /> <LogoButton {appName} />
<MenuList {menuItems} select={updateMenu} class="flex-grow flex-nowrap overflow-y-auto" /> <MenuList
{menuItems}
select={updateMenu}
class="flex-grow flex-nowrap overflow-y-auto"
level="0"
/>
<div class="divider my-0"></div> <div class="divider my-0"></div>
@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { useFeatureFlags } from '$lib/stores'; import { useFeatureFlags } from '$lib/stores';
import { closeModal, openModal } from 'svelte-modals/legacy'; import { modals } from 'svelte-modals';
import ConfirmDialog from '$lib/components/ConfirmDialog.svelte'; import ConfirmDialog from '$lib/components/ConfirmDialog.svelte';
import { api } from '$lib/api'; import { api } from '$lib/api';
import { Cancel, Power } from '../icons'; import { Cancel, Power } from '../icons';
@@ -10,7 +10,7 @@
const postSleep = async () => await api.post('/api/system/sleep'); const postSleep = async () => await api.post('/api/system/sleep');
const confirmSleep = () => { const confirmSleep = () => {
openModal(ConfirmDialog, { modals.open(ConfirmDialog, {
title: 'Confirm Power Down', title: 'Confirm Power Down',
message: 'Are you sure you want to switch off the device?', message: 'Are you sure you want to switch off the device?',
labels: { labels: {
@@ -18,7 +18,7 @@
confirm: { label: 'Switch Off', icon: Power } confirm: { label: 'Switch Off', icon: Power }
}, },
onConfirm: () => { onConfirm: () => {
closeModal(); modals.close();
postSleep(); postSleep();
} }
}); });
@@ -1,9 +1,8 @@
<script lang="ts"> <script lang="ts">
import { page } from '$app/stores'; import { page } from '$app/state';
import { openModal, closeAllModals } from 'svelte-modals/legacy'; import { modals } from 'svelte-modals';
import { notifications } from '$lib/components/toasts/notifications'; import { notifications } from '$lib/components/toasts/notifications';
import ConfirmDialog from '$lib/components/ConfirmDialog.svelte'; import ConfirmDialog from '$lib/components/ConfirmDialog.svelte';
import GithubUpdateDialog from '$lib/components/GithubUpdateDialog.svelte'; import GithubUpdateDialog from '$lib/components/GithubUpdateDialog.svelte';
import { compareVersions } from 'compare-versions'; import { compareVersions } from 'compare-versions';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
@@ -20,8 +19,8 @@
let { update = $bindable(false) }: Props = $props(); let { update = $bindable(false) }: Props = $props();
let firmwareVersion: string = $state(); let firmwareVersion: string = $state('');
let firmwareDownloadLink: string = $state(); let firmwareDownloadLink: string = $state('');
async function getGithubAPI() { async function getGithubAPI() {
const headers = { const headers = {
@@ -29,7 +28,7 @@
'X-GitHub-Api-Version': '2022-11-28' 'X-GitHub-Api-Version': '2022-11-28'
}; };
const result = await api.get<GithubRelease>( const result = await api.get<GithubRelease>(
`https://api.github.com/repos/${$page.data.github}/releases/latest`, `https://api.github.com/repos/${page.data.github}/releases/latest`,
{ headers } { headers }
); );
if (result.inner.message === '404' || result.inner.message == 'Not Found') { if (result.inner.message === '404' || result.inner.message == 'Not Found') {
@@ -73,17 +72,12 @@
onMount(async () => { onMount(async () => {
if ($features.download_firmware) { if ($features.download_firmware) {
await getGithubAPI(); await getGithubAPI();
const interval = setInterval( setInterval(async () => await getGithubAPI(), 60 * 60 * 1000); // once per hour
async () => {
await getGithubAPI();
},
60 * 60 * 1000
); // once per hour
} }
}); });
function confirmGithubUpdate(url: string) { function confirmGithubUpdate(url: string) {
openModal(ConfirmDialog, { modals.open(ConfirmDialog, {
title: 'Confirm flashing new firmware to the device', title: 'Confirm flashing new firmware to the device',
message: 'Are you sure you want to overwrite the existing firmware with a new one?', message: 'Are you sure you want to overwrite the existing firmware with a new one?',
labels: { labels: {
@@ -92,8 +86,8 @@
}, },
onConfirm: () => { onConfirm: () => {
postGithubDownload(url); postGithubDownload(url);
openModal(GithubUpdateDialog, { modals.open(GithubUpdateDialog, {
onConfirm: () => closeAllModals() onConfirm: () => modals.closeAll()
}); });
} }
}); });
@@ -108,8 +102,9 @@
> >
<span <span
class="indicator-item indicator-top indicator-center badge badge-info badge-xs top-2 scale-75 lg:top-1" class="indicator-item indicator-top indicator-center badge badge-info badge-xs top-2 scale-75 lg:top-1"
>{firmwareVersion}</span
> >
{firmwareVersion}
</span>
<Firmware class="h-7 w-7" /> <Firmware class="h-7 w-7" />
</button> </button>
</div> </div>
+5 -5
View File
@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { onDestroy, onMount } from 'svelte'; import { onDestroy, onMount } from 'svelte';
import { page } from '$app/stores'; import { page } from '$app/state';
import { Modals, closeModal } from 'svelte-modals/legacy'; import { Modals, modals } from 'svelte-modals';
import Toast from '$lib/components/toasts/Toast.svelte'; import Toast from '$lib/components/toasts/Toast.svelte';
import { notifications } from '$lib/components/toasts/notifications'; import { notifications } from '$lib/components/toasts/notifications';
import { fade } from 'svelte/transition'; import { fade } from 'svelte/transition';
@@ -91,7 +91,7 @@
</script> </script>
<svelte:head> <svelte:head>
<title>{$page.data.title}</title> <title>{page.data.title}</title>
</svelte:head> </svelte:head>
<div class="drawer"> <div class="drawer">
@@ -106,7 +106,7 @@
<!-- Side Navigation --> <!-- Side Navigation -->
<div class="drawer-side z-30 shadow-lg"> <div class="drawer-side z-30 shadow-lg">
<label for="main-menu" class="drawer-overlay"></label> <label for="main-menu" class="drawer-overlay"></label>
<Menu on:menuClicked={() => (menuOpen = false)} /> <Menu menuClicked={() => (menuOpen = false)} />
</div> </div>
</div> </div>
@@ -117,7 +117,7 @@
<div <div
class="fixed inset-0 z-40 max-h-full max-w-full bg-black/20 backdrop-blur" class="fixed inset-0 z-40 max-h-full max-w-full bg-black/20 backdrop-blur"
transition:fade transition:fade
onclick={closeModal} onclick={modals.closeAll}
></div> ></div>
{/snippet} {/snippet}
</Modals> </Modals>
@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { onDestroy, onMount } from 'svelte'; import { onDestroy, onMount } from 'svelte';
import { openModal, closeModal } from 'svelte-modals/legacy'; import { modals } from 'svelte-modals';
import ConfirmDialog from '$lib/components/ConfirmDialog.svelte'; import ConfirmDialog from '$lib/components/ConfirmDialog.svelte';
import SettingsCard from '$lib/components/SettingsCard.svelte'; import SettingsCard from '$lib/components/SettingsCard.svelte';
import Spinner from '$lib/components/Spinner.svelte'; import Spinner from '$lib/components/Spinner.svelte';
@@ -60,7 +60,7 @@
const postRestart = async () => await api.post('/api/system/restart'); const postRestart = async () => await api.post('/api/system/restart');
function confirmRestart() { function confirmRestart() {
openModal(ConfirmDialog, { modals.open(ConfirmDialog, {
title: 'Confirm Restart', title: 'Confirm Restart',
message: 'Are you sure you want to restart the device?', message: 'Are you sure you want to restart the device?',
labels: { labels: {
@@ -68,14 +68,14 @@
confirm: { label: 'Restart', icon: Power } confirm: { label: 'Restart', icon: Power }
}, },
onConfirm: () => { onConfirm: () => {
closeModal(); modals.close();
postRestart(); postRestart();
} }
}); });
} }
function confirmReset() { function confirmReset() {
openModal(ConfirmDialog, { modals.open(ConfirmDialog, {
title: 'Confirm Factory Reset', title: 'Confirm Factory Reset',
message: 'Are you sure you want to reset the device to its factory defaults?', message: 'Are you sure you want to reset the device to its factory defaults?',
labels: { labels: {
@@ -83,14 +83,14 @@
confirm: { label: 'Factory Reset', icon: FactoryReset } confirm: { label: 'Factory Reset', icon: FactoryReset }
}, },
onConfirm: () => { onConfirm: () => {
closeModal(); modals.close();
postFactoryReset(); postFactoryReset();
} }
}); });
} }
function confirmSleep() { function confirmSleep() {
openModal(ConfirmDialog, { modals.open(ConfirmDialog, {
title: 'Confirm Going to Sleep', title: 'Confirm Going to Sleep',
message: 'Are you sure you want to put the device into sleep?', message: 'Are you sure you want to put the device into sleep?',
labels: { labels: {
@@ -98,7 +98,7 @@
confirm: { label: 'Sleep', icon: Sleep } confirm: { label: 'Sleep', icon: Sleep }
}, },
onConfirm: () => { onConfirm: () => {
closeModal(); modals.close();
postSleep(); postSleep();
} }
}); });
@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { page } from '$app/stores'; import { page } from '$app/state';
import { openModal, closeModal, closeAllModals } from 'svelte-modals/legacy'; import { modals } from 'svelte-modals';
import { slide } from 'svelte/transition'; import { slide } from 'svelte/transition';
import { cubicOut } from 'svelte/easing'; import { cubicOut } from 'svelte/easing';
import ConfirmDialog from '$lib/components/ConfirmDialog.svelte'; import ConfirmDialog from '$lib/components/ConfirmDialog.svelte';
@@ -21,7 +21,7 @@
accept: 'application/vnd.github+json', accept: 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28' 'X-GitHub-Api-Version': '2022-11-28'
}; };
const result = await api.get(`https://api.github.com/repos/${$page.data.github}/releases`, { const result = await api.get(`https://api.github.com/repos/${page.data.github}/releases`, {
headers headers
}); });
if (result.isErr()) { if (result.isErr()) {
@@ -53,17 +53,17 @@
} }
if (url === '') { if (url === '') {
// if no asset was found, use the first one // if no asset was found, use the first one
openModal(InfoDialog, { modals.open(InfoDialog, {
title: 'No matching firmware found', title: 'No matching firmware found',
message: message:
'No matching firmware was found for the current device. Upload the firmware manually or build from sources.', 'No matching firmware was found for the current device. Upload the firmware manually or build from sources.',
dismiss: { label: 'OK', icon: Check }, dismiss: { label: 'OK', icon: Check },
onDismiss: () => closeModal() onDismiss: () => modals.close()
}); });
return; return;
} }
openModal(ConfirmDialog, { modals.open(ConfirmDialog, {
title: 'Confirm flashing new firmware to the device', title: 'Confirm flashing new firmware to the device',
message: 'Are you sure you want to overwrite the existing firmware with a new one?', message: 'Are you sure you want to overwrite the existing firmware with a new one?',
labels: { labels: {
@@ -72,8 +72,8 @@
}, },
onConfirm: () => { onConfirm: () => {
postGithubDownload(url); postGithubDownload(url);
openModal(GithubUpdateDialog, { modals.open(GithubUpdateDialog, {
onConfirm: () => closeAllModals() onConfirm: () => modals.closeAll()
}); });
} }
}); });
@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { openModal, closeModal } from 'svelte-modals/legacy'; import { modals } from 'svelte-modals';
import ConfirmDialog from '$lib/components/ConfirmDialog.svelte'; import ConfirmDialog from '$lib/components/ConfirmDialog.svelte';
import SettingsCard from '$lib/components/SettingsCard.svelte'; import SettingsCard from '$lib/components/SettingsCard.svelte';
@@ -16,7 +16,7 @@
} }
function confirmBinUpload() { function confirmBinUpload() {
openModal(ConfirmDialog, { modals.open(ConfirmDialog, {
title: 'Confirm Flashing the Device', title: 'Confirm Flashing the Device',
message: 'Are you sure you want to overwrite the existing firmware with a new one?', message: 'Are you sure you want to overwrite the existing firmware with a new one?',
labels: { labels: {
@@ -24,7 +24,7 @@
confirm: { label: 'Upload', icon: OTA } confirm: { label: 'Upload', icon: OTA }
}, },
onConfirm: () => { onConfirm: () => {
closeModal(); modals.close();
uploadBIN(); uploadBIN();
} }
}); });
@@ -42,8 +42,8 @@
<Warning class="h-6 w-6 flex-shrink-0" /> <Warning class="h-6 w-6 flex-shrink-0" />
<span <span
>Uploading a new firmware (.bin) file will replace the existing firmware. You may upload >Uploading a new firmware (.bin) file will replace the existing firmware. You may upload
a (.md5) file first to verify the uploaded firmware.</span a (.md5) file first to verify the uploaded firmware.
> </span>
</div> </div>
<input <input
+7 -9
View File
@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { onMount, onDestroy } from 'svelte'; import { onMount, onDestroy } from 'svelte';
import { openModal, closeModal } from 'svelte-modals/legacy'; import { modals } from 'svelte-modals';
import { slide } from 'svelte/transition'; import { slide } from 'svelte/transition';
import { cubicOut } from 'svelte/easing'; import { cubicOut } from 'svelte/easing';
import { notifications } from '$lib/components/toasts/notifications'; import { notifications } from '$lib/components/toasts/notifications';
@@ -205,12 +205,12 @@
} }
function scanForNetworks() { function scanForNetworks() {
openModal(ScanNetworks, { modals.open(ScanNetworks, {
storeNetwork: (network: string) => { storeNetwork: (network: string) => {
addNetwork(); addNetwork();
networkEditable.ssid = network; networkEditable.ssid = network;
showNetworkEditor = true; showNetworkEditor = true;
closeModal(); modals.close();
} }
}); });
} }
@@ -236,7 +236,7 @@
} }
function confirmDelete(index: number) { function confirmDelete(index: number) {
openModal(ConfirmDialog, { modals.open(ConfirmDialog, {
title: 'Delete Network', title: 'Delete Network',
message: 'Are you sure you want to delete this network?', message: 'Are you sure you want to delete this network?',
labels: { labels: {
@@ -252,21 +252,19 @@
dndNetworkList.splice(index, 1); dndNetworkList.splice(index, 1);
dndNetworkList = [...dndNetworkList]; //Trigger reactivity dndNetworkList = [...dndNetworkList]; //Trigger reactivity
showNetworkEditor = false; showNetworkEditor = false;
closeModal(); modals.close();
} }
}); });
} }
function checkNetworkList() { function checkNetworkList() {
if (dndNetworkList.length >= 5) { if (dndNetworkList.length >= 5) {
openModal(InfoDialog, { modals.open(InfoDialog, {
title: 'Reached Maximum Networks', title: 'Reached Maximum Networks',
message: message:
'You have reached the maximum number of networks. Please delete one to add another.', 'You have reached the maximum number of networks. Please delete one to add another.',
dismiss: { label: 'OK', icon: Check }, dismiss: { label: 'OK', icon: Check },
onDismiss: () => { onDismiss: () => modals.close()
closeModal();
}
}); });
return false; return false;
} else { } else {