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:
@@ -10,7 +10,9 @@
|
|||||||
let selectedGroup = $state('');
|
let selectedGroup = $state('');
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
[categories, groups] = await Promise.all([getCategories(), getGroups()]);
|
try {
|
||||||
|
[categories, groups] = await Promise.all([getCategories(), getGroups()]);
|
||||||
|
} catch { /* server may not be ready yet */ }
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleSearch(e) {
|
function handleSearch(e) {
|
||||||
|
|||||||
@@ -7,8 +7,13 @@
|
|||||||
let syncMessage = $state('');
|
let syncMessage = $state('');
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
stores = await getStores();
|
try {
|
||||||
loading = false;
|
stores = await getStores();
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to load stores:', err);
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async function handleToggle(id) {
|
async function handleToggle(id) {
|
||||||
|
|||||||
@@ -16,8 +16,13 @@
|
|||||||
let editingCat = $state(null);
|
let editingCat = $state(null);
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
[categories, groups, stores] = await Promise.all([getCategories(), getGroups(), getStores()]);
|
try {
|
||||||
loading = false;
|
[categories, groups, stores] = await Promise.all([getCategories(), getGroups(), getStores()]);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to load data:', err);
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async function handleAddCategory() {
|
async function handleAddCategory() {
|
||||||
|
|||||||
Reference in New Issue
Block a user