Save Markdowns

This commit is contained in:
h z
2024-12-06 15:13:20 +00:00
parent 6d96b658f0
commit ede31f85b5
3 changed files with 115 additions and 112 deletions

View File

@@ -39,7 +39,7 @@ const MarkdownEditor = () => {
}, [id]);
const handleSave = () => {
const url = id ? `${config.BACKEND_HOST}/api/markdown/${id}` : `${config.BACKEND_HOST}/api/markdown`;
const url = id ? `${config.BACKEND_HOST}/api/markdown/${id}` : `${config.BACKEND_HOST}/api/markdown/`;
const method = id ? "PUT" : "POST";
fetch_(url, {
method,
@@ -47,16 +47,12 @@ const MarkdownEditor = () => {
}, {
use_cache: false,
use_token: true,
}).then((res) => {
if (res.ok) {
navigate("/");
} else {
return res.json().then((data) => {
throw new Error(data.error || "Failed to save markdown");
});
}
}).then((data) => {
if(data.error)
throw new Error(data.error.message);
navigate("/");
}).catch((err) => {
console.error("Failed to save markdown", err);
console.error("Failed to load markdown", err);
});
};