mirror of
https://github.com/nagaoo0/HabbitGrid.git
synced 2026-01-11 23:44:55 +00:00
fix duplicates
This commit is contained in:
@@ -51,7 +51,7 @@ const AddEditHabitPage = () => {
|
|||||||
}
|
}
|
||||||
}, [id, isEdit, navigate, toast]);
|
}, [id, isEdit, navigate, toast]);
|
||||||
|
|
||||||
const handleSubmit = (e) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (!name.trim()) {
|
if (!name.trim()) {
|
||||||
@@ -78,8 +78,7 @@ const AddEditHabitPage = () => {
|
|||||||
description: "Your habit has been updated successfully.",
|
description: "Your habit has been updated successfully.",
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Add to localStorage for instant UI
|
// Single source of truth: delegate to datastore; it will handle local or remote as needed
|
||||||
const habits = JSON.parse(localStorage.getItem('habitgrid_data') || '[]');
|
|
||||||
const newHabit = {
|
const newHabit = {
|
||||||
id: generateUUID(),
|
id: generateUUID(),
|
||||||
name: name.trim(),
|
name: name.trim(),
|
||||||
@@ -90,11 +89,8 @@ const AddEditHabitPage = () => {
|
|||||||
longestStreak: 0,
|
longestStreak: 0,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
updatedAt: new Date().toISOString(),
|
updatedAt: new Date().toISOString(),
|
||||||
sortOrder: habits.length,
|
|
||||||
};
|
};
|
||||||
habits.push(newHabit);
|
await saveHabit(newHabit);
|
||||||
localStorage.setItem('habitgrid_data', JSON.stringify(habits));
|
|
||||||
saveHabit(newHabit); // background sync
|
|
||||||
toast({
|
toast({
|
||||||
title: "✅ Habit created",
|
title: "✅ Habit created",
|
||||||
description: "Your new habit is ready to track!",
|
description: "Your new habit is ready to track!",
|
||||||
|
|||||||
Reference in New Issue
Block a user