AnoPaper/src/pages/pubNoteSafe.jsx

81 lines
2.2 KiB
React
Raw Normal View History

2023-04-21 13:18:00 +03:00
/*
Copyright (c) 2023 artegoser (Artemy Egorov)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { useState } from "react";
import { useParams } from "react-router-dom";
import { ChevronDoubleLeftIcon } from "@heroicons/react/24/outline";
2023-04-03 17:03:01 +03:00
import { ButtonWithIcon } from "../components/button";
import { CopyToClipboard } from "../components/copytocb";
2023-04-03 15:23:41 +03:00
import Note from "../components/note";
function PubNoteSafe() {
let params = useParams();
let [note, setNote] = useState(false);
2023-04-04 15:15:15 +03:00
let nullNote = {
text: locals.PubNoteNotExist,
name: locals.Idontexists,
time: Date.now(),
code: 0,
};
if (note === false)
fetch(`/get-note/safe/${params.id}`)
.then((data) => {
data
.json()
.then((data) => {
data.code = 1;
setNote(data);
})
.catch(() => {
2023-04-04 15:15:15 +03:00
setNote(nullNote);
});
})
.catch(() => {
2023-04-04 15:15:15 +03:00
setNote(nullNote);
});
return (
<div className="">
2023-04-03 17:03:01 +03:00
<ButtonWithIcon
className="mb-4"
href="/"
2023-04-04 15:15:15 +03:00
text={locals.Write}
2023-04-03 17:03:01 +03:00
icon={ChevronDoubleLeftIcon}
/>
{note?.code === 1 && (
<div className="p-4 mb-2">
<div className="grid grid-cols-1 lg:grid-cols-2">
<h2 className="font-medium text-center lg:text-left p-2">
2023-04-04 15:15:15 +03:00
{locals.PubUrlPlaceholder}
</h2>
<CopyToClipboard
text={`${window.location.origin}/pubNotes/${params.id}`}
></CopyToClipboard>
</div>
</div>
)}
2023-04-03 15:23:41 +03:00
<Note note={note} />
</div>
);
}
export default PubNoteSafe;