added toast and modal confirmation

This commit is contained in:
2026-02-14 08:22:35 +01:00
parent 072f44c213
commit 1d5b730e11
17 changed files with 604 additions and 42 deletions

View File

@ -6,17 +6,21 @@ import DayMealCard from '@/components/today/DayMealCard.vue'
import DayTotalsCard from '@/components/today/DayTotalsCard.vue'
import { useDiaryStore } from '@/stores/diary'
import { useMealsStore } from '@/stores/meals'
import { useUIStore } from '@/stores/ui'
import { MEAL_TYPES, type MealType } from '@/types/domain'
import { todayISO } from '@/utils/date'
import { toErrorMessage } from '@/utils/error'
const route = useRoute()
const router = useRouter()
const diaryStore = useDiaryStore()
const mealsStore = useMealsStore()
const ui = useUIStore()
const { t } = useI18n()
const isWorking = ref(false)
const selectedDate = ref(todayISO())
const errorMessage = ref('')
const resolveDate = (): string => {
const dateFromRoute = typeof route.params.date === 'string' ? route.params.date : ''
@ -28,12 +32,16 @@ const mealTypeLabel = (mealType: MealType): string => t(`mealTypes.${mealType}`)
const reloadDay = async (date: string) => {
selectedDate.value = date
diaryStore.ensureCurrentDay(date)
errorMessage.value = ''
isWorking.value = true
try {
if (mealsStore.list.length <= 0) {
await mealsStore.loadMeals()
}
await diaryStore.loadDay(date)
} catch (error) {
errorMessage.value = toErrorMessage(error, t('ux.errors.loadDay'))
ui.error(errorMessage.value)
} finally {
isWorking.value = false
}
@ -55,11 +63,19 @@ const onDateChange = async () => {
}
const onSelectMeal = async (mealType: MealType, mealId: number | null) => {
if (mealId === null) {
await diaryStore.unsetMealForType(selectedDate.value, mealType)
return
try {
errorMessage.value = ''
if (mealId === null) {
await diaryStore.unsetMealForType(selectedDate.value, mealType)
ui.success(t('ux.toast.updated'))
return
}
await diaryStore.setMealForType(selectedDate.value, mealType, mealId)
ui.success(t('ux.toast.updated'))
} catch (error) {
errorMessage.value = toErrorMessage(error, t('ux.errors.updateDay'))
ui.error(errorMessage.value)
}
await diaryStore.setMealForType(selectedDate.value, mealType, mealId)
}
const dayMeals = computed(() => diaryStore.mealsByType)
@ -75,7 +91,8 @@ const dayTotals = computed(() => diaryStore.computedTotals)
</label>
</div>
<div v-if="isWorking || diaryStore.loading" class="card">{{ t('today.loadingDay') }}</div>
<div v-if="errorMessage" class="card card-state card-state--error">{{ errorMessage }}</div>
<div v-else-if="isWorking || diaryStore.loading" class="card card-state">{{ t('today.loadingDay') }}</div>
<template v-else>
<div class="grid-three">