From a286f4a7df6425b8d2d7a87ec63b749b13ec66ed Mon Sep 17 00:00:00 2001 From: Artemy Date: Sat, 21 Jan 2023 16:59:44 +0300 Subject: [PATCH] feat: safe note view, public note deletion --- package.json | 2 +- src/App.jsx | 2 + src/components/copytocb.jsx | 37 ++++++++++++++++ src/pages/pubNote.jsx | 2 +- src/pages/pubNoteSafe.jsx | 84 +++++++++++++++++++++++++++++++++++++ src/pages/publish.jsx | 2 +- 6 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 src/components/copytocb.jsx create mode 100644 src/pages/pubNoteSafe.jsx diff --git a/package.json b/package.json index 1090488..d056075 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "dev": "vite", - "build": "vite build", + "build": "vite build --emptyOutDir", "preview": "vite preview" }, "dependencies": { diff --git a/src/App.jsx b/src/App.jsx index 7f82fd8..eee1c8b 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -8,6 +8,7 @@ import Note from "./pages/note"; import Notes from "./pages/notes"; import PubNote from "./pages/pubNote"; import PubError from "./pages/pubError"; +import PubNoteSafe from "./pages/pubNoteSafe"; function App() { Storage.prototype.setObj = function (key, obj) { @@ -27,6 +28,7 @@ function App() { } /> } /> } /> + } /> } /> { + console.log(copied); + if (copied === true) { + setTimeout(() => { + setCopied(false); + }, 1000); + } + }); + + return ( +
{ + navigator.clipboard.writeText(props.text); + setCopied(true); + }} + > +
{props.text}
+
+ {copied === true ? ( + + ) : ( + + )} +
+
+ ); +} + +export { CopyToClipboard }; diff --git a/src/pages/pubNote.jsx b/src/pages/pubNote.jsx index 5ed67ca..2a48a34 100644 --- a/src/pages/pubNote.jsx +++ b/src/pages/pubNote.jsx @@ -11,7 +11,7 @@ function PubNote() { let [note, setNote] = useState(); if (!note) - fetch(`/get-note/${params.id}`) + fetch(`/get-note/del/${params.id}`) .then((data) => { data .json() diff --git a/src/pages/pubNoteSafe.jsx b/src/pages/pubNoteSafe.jsx new file mode 100644 index 0000000..32b1de8 --- /dev/null +++ b/src/pages/pubNoteSafe.jsx @@ -0,0 +1,84 @@ +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"; +import { CopyToClipboard } from "../components/copytocb"; + +function PubNoteSafe() { + let params = useParams(); + + let [note, setNote] = useState(); + + if (!note) + fetch(`/get-note/safe/${params.id}`) + .then((data) => { + data + .json() + .then((data) => { + data.code = 1; + setNote(data); + }) + .catch(() => { + setNote({ + text: "Такой публичной заметки не сущуествует", + name: "Меня не существует", + time: Date.now(), + code: 0, + }); + }); + }) + .catch(() => { + setNote({ + text: "Такой публичной заметки не сущуествует", + name: "Меня не существует", + time: Date.now(), + code: 0, + }); + }); + + return ( +
+ + + {note?.code === 1 && ( +
+
+

+ Ссылка для отправки публичной заметки. При переходе на эту ссылку, + заметка исчезнет. +

+ +
+
+ )} + +
+
+

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

+
+ {printDate(note?.time || Date.now())} +
+
+
+ {note?.text || "Загрузка..."} +
+
+
+ ); +} + +export default PubNoteSafe; diff --git a/src/pages/publish.jsx b/src/pages/publish.jsx index 7d6764b..5e7258a 100644 --- a/src/pages/publish.jsx +++ b/src/pages/publish.jsx @@ -27,7 +27,7 @@ function Publish() { .then((data) => { localStorage.removeItem("NoteName"); localStorage.removeItem("NoteText"); - navigate(`/pubNotes/${data.id}`, { replace: true }); + navigate(`/pubNotesSafe/${data.id}`, { replace: true }); }) .catch(() => { navigate(`/pubError`, { replace: true });