mirror of
https://github.com/artegoser/AnoPaper.git
synced 2024-11-25 05:16:21 +03:00
feat: save pub notes locally
Notes are now also saved locally instead of just deleted
This commit is contained in:
parent
20a09255a3
commit
8bdc53f45d
4 changed files with 43 additions and 32 deletions
|
@ -48,7 +48,7 @@ function App() {
|
|||
|
||||
|
||||
\r* Публичные заметки доступны только по ссылке.
|
||||
\r* При переходе по ссылке заметка исчезает, прочесть ее можно только один раз.
|
||||
\r* При переходе по ссылке заметка сохраняется локально и удаляется с сервера.
|
||||
\r* Не публичные заметки сохраняются локально и не отправляются на сервер.`}
|
||||
</RenderMarkdown>
|
||||
</div>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import RenderMarkdown from "../components/markdown";
|
||||
import { useState } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { Navigate, useParams } from "react-router-dom";
|
||||
import printDate from "../components/utils";
|
||||
import { ChevronDoubleLeftIcon } from "@heroicons/react/24/outline";
|
||||
import { Button, IconWithText } from "../components/button";
|
||||
|
@ -8,9 +8,9 @@ import { Button, IconWithText } from "../components/button";
|
|||
function PubNote() {
|
||||
let params = useParams();
|
||||
|
||||
let [note, setNote] = useState();
|
||||
let [note, setNote] = useState(false);
|
||||
|
||||
if (!note)
|
||||
if (note === false)
|
||||
fetch(`/get-note/del/${params.id}`)
|
||||
.then((data) => {
|
||||
data
|
||||
|
@ -23,6 +23,7 @@ function PubNote() {
|
|||
text: "Такой публичной заметки не сущуествует",
|
||||
name: "Меня не существует",
|
||||
time: Date.now(),
|
||||
save: false,
|
||||
});
|
||||
});
|
||||
})
|
||||
|
@ -31,35 +32,43 @@ function PubNote() {
|
|||
text: "Такой публичной заметки не сущуествует",
|
||||
name: "Меня не существует",
|
||||
time: Date.now(),
|
||||
save: false,
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="">
|
||||
<Button className="mb-4" href="/">
|
||||
<IconWithText
|
||||
icon={
|
||||
<ChevronDoubleLeftIcon className="transform translate-z-0 h-7 w-7" />
|
||||
}
|
||||
>
|
||||
Писать
|
||||
</IconWithText>
|
||||
</Button>
|
||||
<div className="border border-blue-300 rounded-lg p-4">
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2">
|
||||
<h2 className="font-medium text-center lg:text-left leading-tight text-4xl mt-0 mb-2">
|
||||
{note?.name || "Загрузка..."}
|
||||
</h2>
|
||||
<div className="justify-self-center lg:justify-self-end">
|
||||
{printDate(note?.time || Date.now())}
|
||||
else {
|
||||
if (note.save !== false) {
|
||||
localStorage.setItem("NoteName", note.name);
|
||||
localStorage.setItem("NoteText", note.text);
|
||||
return <Navigate to="/notes/save-local" replace={true} />;
|
||||
} else {
|
||||
return (
|
||||
<div className="">
|
||||
<Button className="mb-4" href="/">
|
||||
<IconWithText
|
||||
icon={
|
||||
<ChevronDoubleLeftIcon className="transform translate-z-0 h-7 w-7" />
|
||||
}
|
||||
>
|
||||
Писать
|
||||
</IconWithText>
|
||||
</Button>
|
||||
<div className="border border-blue-300 rounded-lg p-4">
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2">
|
||||
<h2 className="font-medium text-center lg:text-left leading-tight text-4xl mt-0 mb-2">
|
||||
{note.name || "Загрузка..."}
|
||||
</h2>
|
||||
<div className="justify-self-center lg:justify-self-end">
|
||||
{printDate(note.time || Date.now())}
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full md break-words">
|
||||
<RenderMarkdown>{note.text || "Загрузка..."}</RenderMarkdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full md break-words">
|
||||
<RenderMarkdown>{note?.text || "Загрузка..."}</RenderMarkdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default PubNote;
|
||||
|
|
|
@ -9,9 +9,9 @@ import { CopyToClipboard } from "../components/copytocb";
|
|||
function PubNoteSafe() {
|
||||
let params = useParams();
|
||||
|
||||
let [note, setNote] = useState();
|
||||
let [note, setNote] = useState(false);
|
||||
|
||||
if (!note)
|
||||
if (note === false)
|
||||
fetch(`/get-note/safe/${params.id}`)
|
||||
.then((data) => {
|
||||
data
|
||||
|
|
|
@ -38,7 +38,9 @@ function Publish() {
|
|||
navigate(`/pubNotesSafe/${data.id}`, { replace: true });
|
||||
})
|
||||
.catch(() => {
|
||||
navigate(`/pubError?err=${err}`, { replace: true });
|
||||
if (err == false) {
|
||||
navigate(`/pubError`, { replace: true });
|
||||
} else navigate(`/pubError?err=${err}`, { replace: true });
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
|
|
Loading…
Add table
Reference in a new issue