fix: edit function of markdown

This commit is contained in:
h z
2024-12-07 12:03:23 +00:00
parent 7eaf37223c
commit a31cec7ef0
6 changed files with 82 additions and 15 deletions

View File

@@ -5,6 +5,7 @@ import "./PathManager.css";
const PathManager = ({ currentPathId = 1, onPathChange }) => {
const [currentPath, setCurrentPath] = useState([{ name: "Root", id: 1 }]);
//const [currentPath, setCurrentPath] = useState(buildPath(currentPathId));
const [currentId, setCurrentId] = useState(currentPathId);
const [subPaths, setSubPaths] = useState([]);
const [searchTerm, setSearchTerm] = useState("");
@@ -13,13 +14,41 @@ const PathManager = ({ currentPathId = 1, onPathChange }) => {
const inputRef = useRef();
const buildPath = async (path_id) => {
const path = [];
let current_id = path_id;
while (current_id) {
const pathData = await fetch_(`${config.BACKEND_HOST}/api/path/${current_id}`, {},{
use_cache: true,
use_token: false,
});
current_id = pathData.parent_id;
path.unshift(pathData);
}
return path;
}
useEffect(() => {
fetchSubPaths(currentId);
}, [currentId]);
useEffect(() => {
const init = async () => {
const pth = await buildPath(currentPathId);
setCurrentPath(pth);
};
init();
}, [currentPathId]);
const fetchSubPaths = (pathId) => {
setLoading(true);
fetch_(`${config.BACKEND_HOST}/api/path/parent/${pathId}`, {}, { use_cache: false, use_token: true })
fetch_(`${config.BACKEND_HOST}/api/path/parent/${pathId}`, {}, {
use_cache: false,
use_token: true
})
.then((data) => setSubPaths(data))
.catch((error) => console.error("Failed to fetch subdirectories:", error))
.finally(() => setLoading(false));
@@ -71,6 +100,7 @@ const PathManager = ({ currentPathId = 1, onPathChange }) => {
);
return (
<div className="path-manager">
<div className="path-manager-header">
<div className="current-path">