mirror of
https://github.com/nagaoo0/HabbitGrid.git
synced 2026-01-11 15:34:54 +00:00
Fix duplicate habit creations when logged in DB
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
// UUID v4 generator (browser safe, duplicate of datastore.js for local use)
|
||||
function generateUUID() {
|
||||
if (window.crypto && window.crypto.randomUUID) return window.crypto.randomUUID();
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { motion } from 'framer-motion';
|
||||
@@ -73,7 +81,7 @@ const AddEditHabitPage = () => {
|
||||
// Add to localStorage for instant UI
|
||||
const habits = JSON.parse(localStorage.getItem('habitgrid_data') || '[]');
|
||||
const newHabit = {
|
||||
id: Date.now().toString(),
|
||||
id: generateUUID(),
|
||||
name: name.trim(),
|
||||
color,
|
||||
category: category.trim(),
|
||||
|
||||
Reference in New Issue
Block a user