diff --git a/src/components/Navigations/PathNode.js b/src/components/Navigations/PathNode.js
index 7b06993..6586020 100644
--- a/src/components/Navigations/PathNode.js
+++ b/src/components/Navigations/PathNode.js
@@ -2,7 +2,7 @@ import React, {useState} from "react";
import { Link } from "react-router-dom";
import PermissionGuard from "../PermissionGuard";
import "./PathNode.css";
-import {useDeletePath, useMovePath, usePaths, useUpdatePath} from "../../utils/path-queries";
+import {useDeletePath, useMovePath, usePath, usePaths, useUpdatePath} from "../../utils/path-queries";
import {useIndexMarkdown, useMarkdownsByPath, useMoveMarkdown} from "../../utils/markdown-queries";
import MarkdownNode from "./MarkdownNode";
@@ -11,8 +11,8 @@ const PathNode = ({ path, isRoot = false }) => {
const [isEditing, setIsEditing] = useState(false);
const [newName, setNewName] = useState(path.name);
- const { data: childPaths, isLoading: isChildLoading, error: childError } = usePaths(path.id);
- const { data: markdowns, isLoading: isMarkdownLoading, error: markdownError } = useMarkdownsByPath(path.id);
+// const { data: childPaths, isLoading: isChildLoading, error: childError } = usePaths(path.id);
+// const { data: markdowns, isLoading: isMarkdownLoading, error: markdownError } = useMarkdownsByPath(path.id);
const deletePath = useDeletePath();
const updatePath = useUpdatePath();
@@ -60,18 +60,40 @@ const PathNode = ({ path, isRoot = false }) => {
})
};
+ const childPaths = path.children.filter(x => x.type==="path");
const sortedPaths = childPaths
? childPaths.slice().sort((a, b) => a.order.localeCompare(b.order))
: [];
+ const markdowns = path.children.filter(x => x.type==="markdown");
const sortedMarkdowns = markdowns
? markdowns.filter(md => md.title !== "index").sort((a, b) => a.order.localeCompare(b.order))
: [];
- if(childError || markdownError){
+/* if(childError || markdownError){
return
Error...;
- }
+ }*/
+ if(isRoot)
+ return (
+
+ {sortedPaths.map((path) => (
+
+ ))}
+ {sortedMarkdowns.filter(md => md.title !== "index").map((markdown) => (
+
+ ))}
+
+ );
return (
@@ -167,7 +189,6 @@ const PathNode = ({ path, isRoot = false }) => {
{isExpanded && (
- {isChildLoading && Loading...
}
{sortedPaths.map((child) => (
{
- const {data: paths, isLoading, error } = usePaths(1);
+ const {data: tree, isLoading, error} = useTree();
const deletePath = useDeletePath();
const updatePath = useUpdatePath();
const [searchTerm, setSearchTerm] = React.useState("");
const [keyword, setKeyword] = React.useState("");
const [searchMode, setSearchMode] = React.useState(false);
-
- const {data: searchResults, isLoading: isSearching} = useSearchMarkdown(keyword, {
- enabled: searchMode && !!searchMode,
- });
- const sortedPaths = paths
- ? paths.slice().sort((a, b) => a.order.localeCompare(b.order))
- : [];
const handleDelete = (id) => {
if (window.confirm("Are you sure you want to delete this path?")){
deletePath.mutate(id, {
@@ -30,13 +22,30 @@ const SideNavigation = () => {
}
};
- const handleSearch = () => {
- setSearchMode(true);
- setKeyword(searchTerm);
- }
- const exitSearch = () => {
- setSearchMode(false);
- }
+
+ const filterTree = (t, k) => {
+ if(t === undefined)
+ return undefined;
+ if (t.type === "path") {
+ if (t.name.includes(k)) {
+ return { ...t };
+ }
+ const filteredChildren = (t.children || [])
+ .map(c => filterTree(c, k))
+ .filter(Boolean);
+
+ if (filteredChildren.length > 0) {
+ return { ...t, children: filteredChildren };
+ }
+ } else if (t.type === "markdown") {
+ if (t.title.includes(k)) {
+ return { ...t };
+ }
+ }
+ return undefined;
+ };
+
+ const filteredTree = filterTree(tree, keyword);
const handleSave = (id, newName) => {
updatePath.mutate({ id, data: {name: newName }} , {
@@ -45,55 +54,17 @@ const SideNavigation = () => {
}
});
};
- if(!searchMode && isLoading){
- return ;
- }
- if(searchMode && isSearching){
- return ;
- }
- if(error){
- return ;
- }
-
-
+ if (isLoading) return ;
+ if (error) return ;
return (