diff --git a/src/App.jsx b/src/App.jsx index 90b3e8c..a001173 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -6,6 +6,8 @@ import Save from "./pages/save-local"; import Publish from "./pages/publish"; import Note from "./pages/note"; import Notes from "./pages/notes"; +import PubNote from "./pages/pubNote"; +import PubError from "./pages/pubError"; function App() { Storage.prototype.setObj = function (key, obj) { @@ -24,6 +26,8 @@ function App() { } /> } /> } /> + } /> + } /> О сервисе} diff --git a/src/components/notePlaceholder.jsx b/src/components/notePlaceholder.jsx deleted file mode 100644 index 4dae934..0000000 --- a/src/components/notePlaceholder.jsx +++ /dev/null @@ -1,14 +0,0 @@ -function NotePlaceholder() { - return ( -
-
- Название... -
-
- Описание... -
-
- ); -} - -export default NotePlaceholder; diff --git a/src/pages/note.jsx b/src/pages/note.jsx index f00f136..98441ed 100644 --- a/src/pages/note.jsx +++ b/src/pages/note.jsx @@ -1,5 +1,4 @@ import ReactMarkdown from "react-markdown"; -import { useState, useEffect } from "react"; import { useParams } from "react-router-dom"; import printDate from "../components/utils"; import { ChevronDoubleLeftIcon } from "@heroicons/react/24/outline"; @@ -7,11 +6,8 @@ import { Button, IconWithButton } from "../components/button"; function Note() { let params = useParams(); - const [note, setNote] = useState(false); - useEffect(() => { - setNote(localStorage.getObj("Notes")[params.id]); - }, []); + let note = localStorage.getObj("Notes")[params.id]; if (note) { return ( diff --git a/src/pages/pubError.jsx b/src/pages/pubError.jsx new file mode 100644 index 0000000..0f03e34 --- /dev/null +++ b/src/pages/pubError.jsx @@ -0,0 +1,34 @@ +import printDate from "../components/utils"; +import { ChevronDoubleLeftIcon } from "@heroicons/react/24/outline"; +import { Button, IconWithButton } from "../components/button"; + +function PubError() { + return ( +
+ +
+
+

+ Ошибка в публикации заметки +

+
+ {printDate(Date.now())} +
+
+
+ Заметка не была опубликована из-за неизвестной ошибки +
+
+
+ ); +} + +export default PubError; diff --git a/src/pages/pubNote.jsx b/src/pages/pubNote.jsx new file mode 100644 index 0000000..b347460 --- /dev/null +++ b/src/pages/pubNote.jsx @@ -0,0 +1,66 @@ +import ReactMarkdown from "react-markdown"; +import { useState } from "react"; +import { useParams } from "react-router-dom"; +import printDate from "../components/utils"; +import { ChevronDoubleLeftIcon } from "@heroicons/react/24/outline"; +import { Button, IconWithButton } from "../components/button"; + +function PubNote() { + let params = useParams(); + + let [note, setNote] = useState(); + + if (!note) + fetch(`/get-note/${params.id}`) + .then((data) => { + data + .json() + .then((data) => { + console.log("awdawd"); + setNote(data); + }) + .catch(() => { + setNote({ + text: "Такой публичной заметки не сущуествует", + name: "Меня не существует", + time: Date.now(), + }); + }); + }) + .catch(() => { + setNote({ + text: "Такой публичной заметки не сущуествует", + name: "Меня не существует", + time: Date.now(), + }); + }); + + return ( +
+ +
+
+

+ {note?.name || "Загрузка..."} +

+
+ {printDate(note?.time || Date.now())} +
+
+
+ {note?.text || "Загрузка..."} +
+
+
+ ); +} + +export default PubNote;