add: bind path to index markdown

This commit is contained in:
h z
2024-12-06 23:35:36 +00:00
parent a1473e51e7
commit 20f205ba59
2 changed files with 32 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, {useEffect, useState} from "react";
import { Link } from "react-router-dom";
import PermissionGuard from "../PermissionGuard";
import config from "../../config";
@@ -12,6 +12,20 @@ const PathNode = ({ path, isRoot = false, onDelete, onSave }) => {
const [loading, setLoading] = useState(false);
const [isEditing, setIsEditing] = useState(false);
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 = () => {
if (onSave) {
@@ -46,10 +60,15 @@ const PathNode = ({ path, isRoot = false, onDelete, onSave }) => {
`${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))
.finally(() => setLoading(false));
}
};
return (
@@ -66,7 +85,16 @@ const PathNode = ({ path, isRoot = false, onDelete, onSave }) => {
</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"]}>

View File

@@ -69,7 +69,7 @@ const SideNavigation = () => {
key={path.id}
path={path}
isRoot={false}
onSave={handleSave} // Ensure this is passed
onSave={handleSave}
onDelete={handleDelete}
/>
))}