diff --git a/src/components/HabitGrid.jsx b/src/components/HabitGrid.jsx index 35b8615..69b1954 100644 --- a/src/components/HabitGrid.jsx +++ b/src/components/HabitGrid.jsx @@ -40,19 +40,7 @@ const HabitGrid = ({ habit, onUpdate, fullView = false }) => { const handleCellClick = async (date) => { const dateStr = formatDate(date); - // Only do optimistic localStorage write if logged in (remote-first). In local-only mode, let datastore handle it to avoid double-toggle. - const user = await getAuthUser(); - if (user) { - const habits = JSON.parse(localStorage.getItem('habitgrid_data') || '[]'); - const idx = habits.findIndex(h => h.id === habit.id); - if (idx !== -1) { - const completions = Array.isArray(habits[idx].completions) ? [...habits[idx].completions] : []; - const cidx = completions.indexOf(dateStr); - if (cidx > -1) completions.splice(cidx, 1); else completions.push(dateStr); - habits[idx].completions = completions; - localStorage.setItem('habitgrid_data', JSON.stringify(habits)); - } - } + // Always call toggleCompletion (handles local/remote), then update UI await toggleCompletion(habit.id, dateStr); onUpdate(); }; diff --git a/src/components/MiniGrid.jsx b/src/components/MiniGrid.jsx index 9dcb653..7e95a1e 100644 --- a/src/components/MiniGrid.jsx +++ b/src/components/MiniGrid.jsx @@ -69,19 +69,6 @@ const MiniGrid = ({ habit, onUpdate }) => { const dateStr = formatDate(date); const isTodayCell = isToday(date); const wasCompleted = habit.completions.includes(dateStr); - // Only optimistic write if logged in; in local-only mode, datastore handles it to avoid double-toggle - const user = await getAuthUser(); - if (user) { - const habits = JSON.parse(localStorage.getItem('habitgrid_data') || '[]'); - const idx = habits.findIndex(h => h.id === habit.id); - if (idx !== -1) { - const completions = Array.isArray(habits[idx].completions) ? [...habits[idx].completions] : []; - const cidx = completions.indexOf(dateStr); - if (cidx > -1) completions.splice(cidx, 1); else completions.push(dateStr); - habits[idx].completions = completions; - localStorage.setItem('habitgrid_data', JSON.stringify(habits)); - } - } await toggleCompletion(habit.id, dateStr); onUpdate(); // Only show encouragement toast if validating (adding) today's dot