refactor: wait on WebSocket connection to refresh

This commit is contained in:
izzy 2025-10-31 17:42:01 +00:00
parent 2afbff36a3
commit 7b28284ddf
No known key found for this signature in database
GPG key ID: 5059F398521BB0F6
2 changed files with 22 additions and 22 deletions

View file

@ -1,5 +1,6 @@
<script lang="ts">
import { getServerConfig, startMaintenance } from '@immich/sdk';
import { websocketStore } from '$lib/stores/websocket';
import { startMaintenance } from '@immich/sdk';
import { Button } from '@immich/ui';
import { fade } from 'svelte/transition';
@ -10,17 +11,16 @@
let { disabled = false }: Props = $props();
async function enable() {
await startMaintenance();
let waiting = false;
websocketStore.connected.subscribe((connected) => {
if (!connected) {
waiting = true;
} else if (connected && waiting) {
location.href = '/';
}
});
// poll the server until it comes back online
setInterval(
() =>
void getServerConfig()
// eslint-disable-next-line no-self-assign
.then(() => (location.href = location.href))
.catch(() => {}),
1000,
);
await startMaintenance();
}
</script>

View file

@ -1,21 +1,21 @@
<script>
import AuthPageLayout from '$lib/components/layouts/AuthPageLayout.svelte';
import { user } from '$lib/stores/user.store';
import { endMaintenance, getServerConfig } from '@immich/sdk';
import { websocketStore } from '$lib/stores/websocket';
import { endMaintenance } from '@immich/sdk';
import { Button, Heading } from '@immich/ui';
async function exit() {
await endMaintenance();
let waiting = false;
websocketStore.connected.subscribe((connected) => {
if (!connected) {
waiting = true;
} else if (connected && waiting) {
location.href = '/';
}
});
// poll the server until it comes back online
setInterval(
() =>
void getServerConfig()
// eslint-disable-next-line no-self-assign
.then(() => (location.href = location.href))
.catch(() => {}),
1000,
);
await endMaintenance();
}
</script>