Fix loading state stuck when API calls fail on startup

Add try/catch to all onMount API calls so the UI recovers
gracefully when the server isn't ready yet instead of hanging
on the loading skeleton forever.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
mariosemes
2026-03-26 21:41:17 +01:00
parent 6e740d3db4
commit c24b06215b
3 changed files with 17 additions and 5 deletions

View File

@@ -10,7 +10,9 @@
let selectedGroup = $state(''); let selectedGroup = $state('');
onMount(async () => { onMount(async () => {
try {
[categories, groups] = await Promise.all([getCategories(), getGroups()]); [categories, groups] = await Promise.all([getCategories(), getGroups()]);
} catch { /* server may not be ready yet */ }
}); });
function handleSearch(e) { function handleSearch(e) {

View File

@@ -7,8 +7,13 @@
let syncMessage = $state(''); let syncMessage = $state('');
onMount(async () => { onMount(async () => {
try {
stores = await getStores(); stores = await getStores();
} catch (err) {
console.error('Failed to load stores:', err);
} finally {
loading = false; loading = false;
}
}); });
async function handleToggle(id) { async function handleToggle(id) {

View File

@@ -16,8 +16,13 @@
let editingCat = $state(null); let editingCat = $state(null);
onMount(async () => { onMount(async () => {
try {
[categories, groups, stores] = await Promise.all([getCategories(), getGroups(), getStores()]); [categories, groups, stores] = await Promise.all([getCategories(), getGroups(), getStores()]);
} catch (err) {
console.error('Failed to load data:', err);
} finally {
loading = false; loading = false;
}
}); });
async function handleAddCategory() { async function handleAddCategory() {