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,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 (
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user