bug fixing

This commit is contained in:
2025-10-18 14:24:45 +02:00
parent 3dd34f4f17
commit 39f7bbd96f
2 changed files with 38 additions and 24 deletions

View File

@@ -40,6 +40,8 @@ const HabitGrid = ({ habit, onUpdate, fullView = false }) => {
const handleCellClick = async (date) => { const handleCellClick = async (date) => {
const dateStr = formatDate(date); const dateStr = formatDate(date);
const user = await getAuthUser();
if (user) {
// Optimistically update completions for instant UI // Optimistically update completions for instant UI
const habits = JSON.parse(localStorage.getItem('habitgrid_data') || '[]'); const habits = JSON.parse(localStorage.getItem('habitgrid_data') || '[]');
const idx = habits.findIndex(h => h.id === habit.id); const idx = habits.findIndex(h => h.id === habit.id);
@@ -53,6 +55,11 @@ const HabitGrid = ({ habit, onUpdate, fullView = false }) => {
onUpdate(); onUpdate();
// Sync in background // Sync in background
toggleCompletion(habit.id, dateStr); toggleCompletion(habit.id, dateStr);
} else {
// Local-only: just call toggleCompletion, then update UI
await toggleCompletion(habit.id, dateStr);
onUpdate();
}
}; };
return ( return (

View File

@@ -69,6 +69,8 @@ const MiniGrid = ({ habit, onUpdate }) => {
const dateStr = formatDate(date); const dateStr = formatDate(date);
const isTodayCell = isToday(date); const isTodayCell = isToday(date);
const wasCompleted = habit.completions.includes(dateStr); const wasCompleted = habit.completions.includes(dateStr);
const user = await getAuthUser();
if (user) {
// Optimistically update completions for instant UI // Optimistically update completions for instant UI
const habits = JSON.parse(localStorage.getItem('habitgrid_data') || '[]'); const habits = JSON.parse(localStorage.getItem('habitgrid_data') || '[]');
const idx = habits.findIndex(h => h.id === habit.id); const idx = habits.findIndex(h => h.id === habit.id);
@@ -82,6 +84,11 @@ const MiniGrid = ({ habit, onUpdate }) => {
onUpdate(); onUpdate();
// Sync in background // Sync in background
toggleCompletion(habit.id, dateStr); toggleCompletion(habit.id, dateStr);
} else {
// Local-only: just call toggleCompletion, then update UI
await toggleCompletion(habit.id, dateStr);
onUpdate();
}
// Only show encouragement toast if validating (adding) today's dot // Only show encouragement toast if validating (adding) today's dot
if (isTodayCell && !wasCompleted) { if (isTodayCell && !wasCompleted) {
try { try {