feat: complete daily checkbox actions and cleanup
- Marked all daily checkbox actions as complete in TODO.md. - Removed outdated mutation methods from `daily-client.ts`, now managed by server actions in `actions/daily.ts`. - Deleted unused API routes for checkbox management, streamlining the codebase. - Updated `useDaily.ts` to utilize server actions with `useTransition`, enhancing performance and user experience.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { httpClient } from './base/http-client';
|
||||
import { DailyCheckbox, DailyView, CreateDailyCheckboxData, UpdateDailyCheckboxData, Task } from '@/lib/types';
|
||||
import { DailyCheckbox, DailyView, Task } from '@/lib/types';
|
||||
|
||||
// Types pour les réponses API (avec dates en string)
|
||||
interface ApiCheckbox {
|
||||
@@ -35,11 +35,16 @@ export interface DailySearchFilters {
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
// Types conservés pour la compatibilité des hooks d'historique et de recherche
|
||||
export interface ReorderCheckboxesData {
|
||||
date: Date;
|
||||
checkboxIds: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Client HTTP pour les données Daily (lecture seule)
|
||||
* Les mutations sont gérées par les server actions dans actions/daily.ts
|
||||
*/
|
||||
export class DailyClient {
|
||||
/**
|
||||
* Récupère la vue daily d'aujourd'hui (hier + aujourd'hui)
|
||||
@@ -88,81 +93,6 @@ export class DailyClient {
|
||||
return result.map((cb: ApiCheckbox) => this.transformCheckboxDates(cb));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajoute une checkbox
|
||||
*/
|
||||
async addCheckbox(data: CreateDailyCheckboxData): Promise<DailyCheckbox> {
|
||||
const payload = {
|
||||
...data,
|
||||
date: this.formatDateForAPI(data.date)
|
||||
};
|
||||
try {
|
||||
const result = await httpClient.post<ApiCheckbox>('/daily', payload);
|
||||
// Transformer les dates string en objets Date
|
||||
return this.transformCheckboxDates(result);
|
||||
} catch (error) {
|
||||
console.error('❌ DailyClient addCheckbox error:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajoute une checkbox pour aujourd'hui
|
||||
*/
|
||||
async addTodayCheckbox(text: string, taskId?: string): Promise<DailyCheckbox> {
|
||||
return this.addCheckbox({
|
||||
date: new Date(),
|
||||
text,
|
||||
taskId
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajoute une checkbox pour hier
|
||||
*/
|
||||
async addYesterdayCheckbox(text: string, taskId?: string): Promise<DailyCheckbox> {
|
||||
const yesterday = new Date();
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
|
||||
return this.addCheckbox({
|
||||
date: yesterday,
|
||||
text,
|
||||
taskId
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour une checkbox
|
||||
*/
|
||||
async updateCheckbox(checkboxId: string, data: UpdateDailyCheckboxData): Promise<DailyCheckbox> {
|
||||
const result = await httpClient.patch<ApiCheckbox>(`/daily/checkboxes/${checkboxId}`, data);
|
||||
return this.transformCheckboxDates(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime une checkbox
|
||||
*/
|
||||
async deleteCheckbox(checkboxId: string): Promise<void> {
|
||||
return httpClient.delete(`/daily/checkboxes/${checkboxId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Réordonne les checkboxes d'une date
|
||||
*/
|
||||
async reorderCheckboxes(data: ReorderCheckboxesData): Promise<void> {
|
||||
return httpClient.post('/daily/checkboxes', {
|
||||
date: this.formatDateForAPI(data.date),
|
||||
checkboxIds: data.checkboxIds
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Coche/décoche une checkbox (raccourci)
|
||||
*/
|
||||
async toggleCheckbox(checkboxId: string, isChecked: boolean): Promise<DailyCheckbox> {
|
||||
return this.updateCheckbox(checkboxId, { isChecked });
|
||||
}
|
||||
|
||||
/**
|
||||
* Formate une date pour l'API (évite les décalages timezone)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user