diff --git a/src/components/Navigations/PathNode.js b/src/components/Navigations/PathNode.js index 30e5806..aea7243 100644 --- a/src/components/Navigations/PathNode.js +++ b/src/components/Navigations/PathNode.js @@ -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 }) => { ) : ( - {path.name} + + { + indexMarkdownId ? ( + + {path.name} + + ) : path.name + } + + )} diff --git a/src/components/Navigations/SideNavigation.js b/src/components/Navigations/SideNavigation.js index 4e4c2fe..0ddc40a 100644 --- a/src/components/Navigations/SideNavigation.js +++ b/src/components/Navigations/SideNavigation.js @@ -69,7 +69,7 @@ const SideNavigation = () => { key={path.id} path={path} isRoot={false} - onSave={handleSave} // Ensure this is passed + onSave={handleSave} onDelete={handleDelete} /> ))}