diff --git a/src/pages/note.jsx b/src/pages/note.jsx index 50fab77..d176d9d 100644 --- a/src/pages/note.jsx +++ b/src/pages/note.jsx @@ -18,6 +18,7 @@ import { useParams } from "react-router-dom"; import { ChevronDoubleLeftIcon, + ChevronDoubleRightIcon, PencilIcon, TrashIcon, } from "@heroicons/react/24/outline"; @@ -93,6 +94,12 @@ function NotePage() { setEdit(!edit); }} /> + {!edit && ( { - if (!done) { - done = true; + let err = false; - let err = false; - const note = { + let note; + + if (searchParams.get("local_id")) { + let localNote = + localStorage.getObj("Notes")[searchParams.get("local_id")]; + note = { + name: localNote.name, + text: localNote.text, + }; + } else { + note = { name: localStorage.getItem("NoteName"), text: localStorage.getItem("NoteText"), }; - - if (!note.name) { - err = locals.PubErrorMsgNoName; - } - if (!note.text) { - err = locals.PubErrorMsgNoText; - } - - fetch(`/publish`, { - method: "POST", - headers: { - "Content-Type": "application/json;charset=utf-8", - }, - body: JSON.stringify(note), - }) - .then((data) => { - data - .json() - .then((data) => { - localStorage.removeItem("NoteName"); - localStorage.removeItem("NoteText"); - navigate(`/pubNotesSafe/${data.id}`, { replace: true }); - }) - .catch(() => { - if (err == false) { - navigate(`/pubError`, { replace: true }); - } else navigate(`/pubError?err=${err}`, { replace: true }); - }); - }) - .catch(() => { - navigate(`/pubError`, { replace: true }); - }); } - }, []); + + if (!note.name) { + err = locals.PubErrorMsgNoName; + } + if (!note.text) { + err = locals.PubErrorMsgNoText; + } + + fetch(`/publish`, { + method: "POST", + headers: { + "Content-Type": "application/json;charset=utf-8", + }, + body: JSON.stringify(note), + }) + .then((data) => { + data + .json() + .then((data) => { + localStorage.removeItem("NoteName"); + localStorage.removeItem("NoteText"); + navigate(`/pubNotesSafe/${data.id}`, { replace: true }); + }) + .catch(() => { + if (err == false) { + navigate(`/pubError`, { replace: true }); + } else navigate(`/pubError?err=${err}`, { replace: true }); + }); + }) + .catch(() => { + navigate(`/pubError`, { replace: true }); + }); + }); return
; }