feat: enhance DailyClient and useDaily hook for improved checkbox handling

- Added new API response types (`ApiCheckbox`, `ApiDailyView`, `ApiHistoryItem`) for better type safety.
- Updated `getTodaysDailyView`, `getDailyView`, and `getHistory` methods to utilize new types and transform date strings into Date objects.
- Refactored `addCheckbox` and `updateCheckbox` methods to handle checkbox creation and updates with improved error handling.
- Optimized `DailyAddForm` for better UX by removing unnecessary loading states and implementing optimistic UI updates.
- Enhanced `useDaily` hook to support checkbox type management and rollback on errors during updates.
- Updated `DailyPageClient` to leverage new checkbox handling methods for adding tasks.
This commit is contained in:
Julien Froidefond
2025-09-15 22:30:56 +02:00
parent adfef551ab
commit 4b27047e63
4 changed files with 239 additions and 107 deletions

View File

@@ -29,7 +29,8 @@ export function DailyPageClient({
error,
saving,
currentDate,
refreshDailySilent,
addTodayCheckbox,
addYesterdayCheckbox,
toggleCheckbox,
updateCheckbox,
deleteCheckbox,
@@ -61,44 +62,15 @@ export function DailyPageClient({
}, [initialDailyDates.length]);
const handleAddTodayCheckbox = async (text: string, type: DailyCheckboxType) => {
try {
const { dailyClient } = await import('@/clients/daily-client');
await dailyClient.addCheckbox({
date: currentDate,
text,
type,
// Pas de taskId lors de l'ajout - sera ajouté via l'édition
isChecked: false
});
// Recharger silencieusement la vue daily (sans clignotement)
refreshDailySilent().catch(console.error);
// Recharger aussi les dates pour le calendrier
await refreshDailyDates();
} catch (error) {
console.error('Erreur lors de l\'ajout de la tâche:', error);
}
await addTodayCheckbox(text, type);
// Recharger aussi les dates pour le calendrier
await refreshDailyDates();
};
const handleAddYesterdayCheckbox = async (text: string, type: DailyCheckboxType) => {
try {
const yesterday = new Date(currentDate);
yesterday.setDate(yesterday.getDate() - 1);
const { dailyClient } = await import('@/clients/daily-client');
await dailyClient.addCheckbox({
date: yesterday,
text,
type,
// Pas de taskId lors de l'ajout - sera ajouté via l'édition
isChecked: false
});
// Recharger silencieusement la vue daily (sans clignotement)
refreshDailySilent().catch(console.error);
// Recharger aussi les dates pour le calendrier
await refreshDailyDates();
} catch (error) {
console.error('Erreur lors de l\'ajout de la tâche:', error);
}
await addYesterdayCheckbox(text, type);
// Recharger aussi les dates pour le calendrier
await refreshDailyDates();
};
const handleToggleCheckbox = async (checkboxId: string) => {