2023-01-21 16:59:44 +03:00
|
|
|
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";
|
2023-01-21 16:59:44 +03:00
|
|
|
import { CopyToClipboard } from "../components/copytocb";
|
2023-04-03 15:23:41 +03:00
|
|
|
import Note from "../components/note";
|
2023-01-21 16:59:44 +03:00
|
|
|
|
|
|
|
function PubNoteSafe() {
|
|
|
|
let params = useParams();
|
|
|
|
|
2023-04-02 10:15:52 +03:00
|
|
|
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,
|
|
|
|
};
|
2023-01-21 16:59:44 +03:00
|
|
|
|
2023-04-02 10:15:52 +03:00
|
|
|
if (note === false)
|
2023-01-21 16:59:44 +03:00
|
|
|
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);
|
2023-01-21 16:59:44 +03:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {
|
2023-04-04 15:15:15 +03:00
|
|
|
setNote(nullNote);
|
2023-01-21 16:59:44 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
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}
|
|
|
|
/>
|
2023-01-21 16:59:44 +03:00
|
|
|
|
|
|
|
{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}
|
2023-01-21 16:59:44 +03:00
|
|
|
</h2>
|
|
|
|
<CopyToClipboard
|
|
|
|
text={`${window.location.origin}/pubNotes/${params.id}`}
|
|
|
|
></CopyToClipboard>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2023-04-03 15:23:41 +03:00
|
|
|
<Note note={note} />
|
2023-01-21 16:59:44 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PubNoteSafe;
|