kc token public key/token issue, path root set to 1
This commit is contained in:
@@ -10,7 +10,8 @@ import { okaidia } from "react-syntax-highlighter/dist/esm/styles/prism";
|
||||
import "katex/dist/katex.min.css";
|
||||
import "./MarkdownEditor.css";
|
||||
import config from "../../config";
|
||||
import {fetch_} from "../../utils/requestUtils";
|
||||
import { fetch_ } from "../../utils/requestUtils";
|
||||
import PathManager from "../PathManager";
|
||||
|
||||
const MarkdownEditor = () => {
|
||||
const { roles } = useContext(AuthContext);
|
||||
@@ -18,7 +19,7 @@ const MarkdownEditor = () => {
|
||||
const { id } = useParams();
|
||||
const [title, setTitle] = useState("");
|
||||
const [content, setContent] = useState("");
|
||||
const [path, setPath] = useState("");
|
||||
const [pathId, setPathId] = useState(1);
|
||||
|
||||
useEffect(() => {
|
||||
if (id) {
|
||||
@@ -29,10 +30,10 @@ const MarkdownEditor = () => {
|
||||
.then((data) => {
|
||||
setTitle(data.title);
|
||||
setContent(data.content);
|
||||
setPath(data.path);
|
||||
setPathId(data.path_id);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("failed to load markdown", err);
|
||||
console.error("Failed to load markdown", err);
|
||||
});
|
||||
}
|
||||
}, [id]);
|
||||
@@ -42,26 +43,27 @@ const MarkdownEditor = () => {
|
||||
const method = id ? "PUT" : "POST";
|
||||
fetch_(url, {
|
||||
method,
|
||||
body: JSON.stringify({ title, content, path }),
|
||||
body: JSON.stringify({ title, content, path_id: pathId }),
|
||||
}, {
|
||||
use_cache: false,
|
||||
use_token: true,
|
||||
}).then((res) => {
|
||||
if(res.ok)
|
||||
if (res.ok) {
|
||||
navigate("/");
|
||||
else
|
||||
} else {
|
||||
return res.json().then((data) => {
|
||||
throw new Error(data.error || "Failed to load markdown");
|
||||
throw new Error(data.error || "Failed to save markdown");
|
||||
});
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.error("failed to load markdown", err);
|
||||
})
|
||||
|
||||
console.error("Failed to save markdown", err);
|
||||
});
|
||||
};
|
||||
|
||||
const hasPermission = roles.includes("admin") || roles.includes("creator");
|
||||
if (!hasPermission)
|
||||
if (!hasPermission) {
|
||||
return <div className="notification is-danger">Permission Denied</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="container mt-5 markdown-editor-container">
|
||||
@@ -84,18 +86,13 @@ const MarkdownEditor = () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Path Field */}
|
||||
{/* PathManager Field */}
|
||||
<div className="field">
|
||||
<label className="label">Path</label>
|
||||
<div className="control">
|
||||
<input
|
||||
className="input"
|
||||
type="text"
|
||||
placeholder="Enter path"
|
||||
value={path}
|
||||
onChange={(e) => setPath(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<PathManager
|
||||
currentPathId={pathId}
|
||||
onPathChange={setPathId}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Content Field */}
|
||||
|
||||
Reference in New Issue
Block a user