feat: publish local notes

This commit is contained in:
Artemy 2023-04-29 10:16:04 +03:00
parent f8365ce2ee
commit 3963e435e8
2 changed files with 54 additions and 38 deletions

View file

@ -18,6 +18,7 @@
import { useParams } from "react-router-dom";
import {
ChevronDoubleLeftIcon,
ChevronDoubleRightIcon,
PencilIcon,
TrashIcon,
} from "@heroicons/react/24/outline";
@ -93,6 +94,12 @@ function NotePage() {
setEdit(!edit);
}}
/>
<ButtonWithIcon
className="mt-4"
text={locals.Publish}
icon={ChevronDoubleRightIcon}
href={`/notes/publish?local_id=${params.id}`}
/>
{!edit && (
<ButtonWithIcon
className="mt-4"

View file

@ -17,20 +17,30 @@
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { useSearchParams } from "react-router-dom";
function Publish() {
const navigate = useNavigate();
let done = false;
const [searchParams] = useSearchParams();
useEffect(() => {
if (!done) {
done = true;
let err = false;
const note = {
let note;
if (searchParams.get("local_id")) {
let localNote =
localStorage.getObj("Notes")[searchParams.get("local_id")];
note = {
name: localNote.name,
text: localNote.text,
};
} else {
note = {
name: localStorage.getItem("NoteName"),
text: localStorage.getItem("NoteText"),
};
}
if (!note.name) {
err = locals.PubErrorMsgNoName;
@ -63,8 +73,7 @@ function Publish() {
.catch(() => {
navigate(`/pubError`, { replace: true });
});
}
}, []);
});
return <div />;
}