mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 22:21:10 +02:00
fix(zitare): add error feedback for silent API failures
Show toast notifications when list CRUD operations and favorite toggling fail, instead of silently swallowing errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
96ff16b7a7
commit
326acf0eaa
2 changed files with 20 additions and 5 deletions
|
|
@ -4,6 +4,7 @@
|
|||
import { favoritesStore } from '$lib/stores/favorites.svelte';
|
||||
import { authStore } from '$lib/stores/auth.svelte';
|
||||
import { ZitareEvents } from '@manacore/shared-utils/analytics';
|
||||
import { toast } from '$lib/stores/toast.svelte';
|
||||
import { _ } from 'svelte-i18n';
|
||||
|
||||
interface Props {
|
||||
|
|
@ -49,11 +50,15 @@
|
|||
async function toggleFavorite() {
|
||||
if (!authStore.isAuthenticated) return;
|
||||
const wasFavorite = isFavorite;
|
||||
await favoritesStore.toggle(quote.id);
|
||||
if (wasFavorite) {
|
||||
ZitareEvents.quoteUnfavorited();
|
||||
} else {
|
||||
ZitareEvents.quoteFavorited(quote.category);
|
||||
try {
|
||||
await favoritesStore.toggle(quote.id);
|
||||
if (wasFavorite) {
|
||||
ZitareEvents.quoteUnfavorited();
|
||||
} else {
|
||||
ZitareEvents.quoteFavorited(quote.category);
|
||||
}
|
||||
} catch {
|
||||
toast.error($_('common.error'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
import { goto } from '$app/navigation';
|
||||
import { _ } from 'svelte-i18n';
|
||||
import { authStore } from '$lib/stores/auth.svelte';
|
||||
import { toast } from '$lib/stores/toast.svelte';
|
||||
import { ZitareEvents } from '@manacore/shared-utils/analytics';
|
||||
|
||||
interface QuoteList {
|
||||
|
|
@ -51,9 +52,12 @@
|
|||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
lists = data.lists || [];
|
||||
} else {
|
||||
toast.error($_('common.error'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch lists:', error);
|
||||
toast.error($_('common.error'));
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
|
|
@ -86,9 +90,12 @@
|
|||
showCreateModal = false;
|
||||
newListName = '';
|
||||
newListDescription = '';
|
||||
} else {
|
||||
toast.error($_('common.error'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to create list:', error);
|
||||
toast.error($_('common.error'));
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
|
|
@ -110,9 +117,12 @@
|
|||
if (response.ok) {
|
||||
lists = lists.filter((l) => l.id !== listId);
|
||||
ZitareEvents.listDeleted();
|
||||
} else {
|
||||
toast.error($_('lists.detail.toast.deleteError'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to delete list:', error);
|
||||
toast.error($_('lists.detail.toast.deleteError'));
|
||||
} finally {
|
||||
deletingId = null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue