feat(DailyPageClient): add pending refresh trigger for daily dates updates

- Introduced a new state variable `pendingRefreshTrigger` to manage refresh actions for daily dates.
- Updated relevant functions to increment the trigger upon checkbox actions and date refreshes, ensuring UI updates reflect the latest data.
This commit is contained in:
Julien Froidefond
2025-10-23 13:02:13 +02:00
parent 87acb3709d
commit b60e74b1ff

View File

@@ -60,6 +60,7 @@ export function DailyPageClient({
} = useDaily(initialDate, initialDailyView); } = useDaily(initialDate, initialDailyView);
const [dailyDates, setDailyDates] = useState<string[]>(initialDailyDates); const [dailyDates, setDailyDates] = useState<string[]>(initialDailyDates);
const [pendingRefreshTrigger, setPendingRefreshTrigger] = useState(0);
// Fonction pour rafraîchir la liste des dates avec des dailies // Fonction pour rafraîchir la liste des dates avec des dailies
const refreshDailyDates = async () => { const refreshDailyDates = async () => {
@@ -90,6 +91,7 @@ export function DailyPageClient({
await addTodayCheckbox(text, type); await addTodayCheckbox(text, type);
// Recharger aussi les dates pour le calendrier // Recharger aussi les dates pour le calendrier
await refreshDailyDates(); await refreshDailyDates();
setPendingRefreshTrigger((prev) => prev + 1);
}; };
const handleAddYesterdayCheckbox = async ( const handleAddYesterdayCheckbox = async (
@@ -99,6 +101,7 @@ export function DailyPageClient({
await addYesterdayCheckbox(text, type); await addYesterdayCheckbox(text, type);
// Recharger aussi les dates pour le calendrier // Recharger aussi les dates pour le calendrier
await refreshDailyDates(); await refreshDailyDates();
setPendingRefreshTrigger((prev) => prev + 1);
}; };
// Raccourcis clavier globaux pour la page Daily // Raccourcis clavier globaux pour la page Daily
@@ -110,12 +113,14 @@ export function DailyPageClient({
const handleToggleCheckbox = async (checkboxId: string) => { const handleToggleCheckbox = async (checkboxId: string) => {
await toggleCheckbox(checkboxId); await toggleCheckbox(checkboxId);
setPendingRefreshTrigger((prev) => prev + 1);
}; };
const handleDeleteCheckbox = async (checkboxId: string) => { const handleDeleteCheckbox = async (checkboxId: string) => {
await deleteCheckbox(checkboxId); await deleteCheckbox(checkboxId);
// Refresh dates après suppression pour mettre à jour le calendrier // Refresh dates après suppression pour mettre à jour le calendrier
await refreshDailyDates(); await refreshDailyDates();
setPendingRefreshTrigger((prev) => prev + 1);
}; };
const handleUpdateCheckbox = async ( const handleUpdateCheckbox = async (
@@ -135,6 +140,7 @@ export function DailyPageClient({
if (date) { if (date) {
await refreshDailyDates(); await refreshDailyDates();
} }
setPendingRefreshTrigger((prev) => prev + 1);
}; };
const handleReorderCheckboxes = async (date: Date, checkboxIds: string[]) => { const handleReorderCheckboxes = async (date: Date, checkboxIds: string[]) => {
@@ -408,7 +414,7 @@ export function DailyPageClient({
onToggleCheckbox={handleToggleCheckbox} onToggleCheckbox={handleToggleCheckbox}
onDeleteCheckbox={handleDeleteCheckbox} onDeleteCheckbox={handleDeleteCheckbox}
onRefreshDaily={refreshDailySilent} onRefreshDaily={refreshDailySilent}
refreshTrigger={0} refreshTrigger={pendingRefreshTrigger}
initialPendingTasks={initialPendingTasks} initialPendingTasks={initialPendingTasks}
/> />