add: bind path to index markdown
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from "react";
|
import React, {useEffect, useState} from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import PermissionGuard from "../PermissionGuard";
|
import PermissionGuard from "../PermissionGuard";
|
||||||
import config from "../../config";
|
import config from "../../config";
|
||||||
@@ -12,6 +12,20 @@ const PathNode = ({ path, isRoot = false, onDelete, onSave }) => {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const [newName, setNewName] = useState(path.name);
|
const [newName, setNewName] = useState(path.name);
|
||||||
|
const [indexMarkdownId, setIndexMarkdownId] = useState(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetch_(`${config.BACKEND_HOST}/api/markdown/get_index/${path.id}`, {}, {
|
||||||
|
use_cache: true,
|
||||||
|
use_token: false
|
||||||
|
}).then((data) => {
|
||||||
|
setIndexMarkdownId(data.id);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
setIndexMarkdownId(null);
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
}, [path]);
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
if (onSave) {
|
if (onSave) {
|
||||||
@@ -46,10 +60,15 @@ const PathNode = ({ path, isRoot = false, onDelete, onSave }) => {
|
|||||||
`${config.BACKEND_HOST}/api/markdown/by_path/${path.id}`
|
`${config.BACKEND_HOST}/api/markdown/by_path/${path.id}`
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then((markdownData) => setMarkdowns(markdownData))
|
.then((markdownData) => {
|
||||||
|
const filteredMarkdowns = markdownData
|
||||||
|
.filter(markdown => markdown.title !== "index");
|
||||||
|
setMarkdowns(filteredMarkdowns);
|
||||||
|
})
|
||||||
.catch((error) => console.error(error))
|
.catch((error) => console.error(error))
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -66,7 +85,16 @@ const PathNode = ({ path, isRoot = false, onDelete, onSave }) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
) : (
|
) : (
|
||||||
<span className="path-name has-text-weight-bold control">{path.name}</span>
|
<span className="path-name has-text-weight-bold control">
|
||||||
|
{
|
||||||
|
indexMarkdownId ? (
|
||||||
|
<Link to={`/markdown/${indexMarkdownId}`} className="is-link">
|
||||||
|
{path.name}
|
||||||
|
</Link>
|
||||||
|
) : path.name
|
||||||
|
}
|
||||||
|
|
||||||
|
</span>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<PermissionGuard rolesRequired={["admin"]}>
|
<PermissionGuard rolesRequired={["admin"]}>
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ const SideNavigation = () => {
|
|||||||
key={path.id}
|
key={path.id}
|
||||||
path={path}
|
path={path}
|
||||||
isRoot={false}
|
isRoot={false}
|
||||||
onSave={handleSave} // Ensure this is passed
|
onSave={handleSave}
|
||||||
onDelete={handleDelete}
|
onDelete={handleDelete}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in New Issue
Block a user