mirror of
https://github.com/nagaoo0/HabbitGrid.git
synced 2026-01-11 23:44:55 +00:00
bug fixing
This commit is contained in:
@@ -40,9 +40,19 @@ const HabitGrid = ({ habit, onUpdate, fullView = false }) => {
|
|||||||
|
|
||||||
const handleCellClick = async (date) => {
|
const handleCellClick = async (date) => {
|
||||||
const dateStr = formatDate(date);
|
const dateStr = formatDate(date);
|
||||||
// Always call toggleCompletion (handles local/remote), then update UI
|
// Optimistically update completions for instant UI
|
||||||
await toggleCompletion(habit.id, dateStr);
|
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));
|
||||||
|
}
|
||||||
onUpdate();
|
onUpdate();
|
||||||
|
// Sync in background
|
||||||
|
toggleCompletion(habit.id, dateStr);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -69,8 +69,19 @@ 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);
|
||||||
await toggleCompletion(habit.id, dateStr);
|
// Optimistically update completions for instant UI
|
||||||
|
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));
|
||||||
|
}
|
||||||
onUpdate();
|
onUpdate();
|
||||||
|
// Sync in background
|
||||||
|
toggleCompletion(habit.id, dateStr);
|
||||||
// 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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user