fix: notes ids now incremental

This commit is contained in:
Artemy 2023-05-01 20:20:54 +03:00
parent c93062229d
commit 238af9ad69

View file

@ -18,17 +18,7 @@
import { Navigate } from "react-router-dom"; import { Navigate } from "react-router-dom";
import { timestamp2text } from "../components/utils"; import { timestamp2text } from "../components/utils";
function uuidv4() {
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
(
c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
).toString(16)
);
}
function Save() { function Save() {
let id = uuidv4();
let name = localStorage.getItem("NoteName"); let name = localStorage.getItem("NoteName");
let text = localStorage.getItem("NoteText"); let text = localStorage.getItem("NoteText");
let pubTime = Number(localStorage.getItem("NotePubTime")); let pubTime = Number(localStorage.getItem("NotePubTime"));
@ -36,6 +26,7 @@ function Save() {
if (!name || !text) return <Navigate to={`/notes`} replace={true} />; if (!name || !text) return <Navigate to={`/notes`} replace={true} />;
let notesObj = localStorage.getObj("Notes"); let notesObj = localStorage.getObj("Notes");
let id = Object.keys(notesObj).length;
let time = Date.now(); let time = Date.now();