From 75d083f11f5bc4443b60267a3f11a99da45d1f6f Mon Sep 17 00:00:00 2001 From: hzhang Date: Sun, 29 Dec 2024 18:52:39 +0000 Subject: [PATCH] add: order paths & mds --- src/components/Footer.js | 2 +- src/components/Navigations/PathNode.js | 87 +++++++++++++++++--- src/components/Navigations/SideNavigation.js | 5 +- src/utils/markdown-queries.js | 18 +++- src/utils/path-queries.js | 20 ++++- webpack.config.js | 1 - 6 files changed, 116 insertions(+), 17 deletions(-) diff --git a/src/components/Footer.js b/src/components/Footer.js index b26df9c..8e04aea 100644 --- a/src/components/Footer.js +++ b/src/components/Footer.js @@ -32,7 +32,7 @@ const Footer = () => { git           - v0.0.6 + v0.0.7 )}

{ diff --git a/src/components/Navigations/PathNode.js b/src/components/Navigations/PathNode.js index bcb5fb7..faa9f81 100644 --- a/src/components/Navigations/PathNode.js +++ b/src/components/Navigations/PathNode.js @@ -2,8 +2,8 @@ import React, {useState} from "react"; import { Link } from "react-router-dom"; import PermissionGuard from "../PermissionGuard"; import "./PathNode.css"; -import {useDeletePath, usePaths, useUpdatePath} from "../../utils/path-queries"; -import {useIndexMarkdown, useMarkdownsByPath} from "../../utils/markdown-queries"; +import {useDeletePath, useMovePath, usePaths, useUpdatePath} from "../../utils/path-queries"; +import {useIndexMarkdown, useMarkdownsByPath, useMoveMarkdown} from "../../utils/markdown-queries"; const PathNode = ({ path, isRoot = false }) => { const [isExpanded, setIsExpanded] = useState(isRoot); @@ -17,6 +17,8 @@ const PathNode = ({ path, isRoot = false }) => { const {data: indexMarkdown, isLoading: isIndexLoading, error: indexMarkdownError} = useIndexMarkdown(path.id); + const movePath = useMovePath(); + const moveMarkdown = useMoveMarkdown(); const toggleExpand = () => { setIsExpanded(!isExpanded); @@ -40,18 +42,34 @@ const PathNode = ({ path, isRoot = false }) => { setIsEditing(true); }; + const handleMovePath = (pth, direction) => { + movePath.mutate({path: pth, direction: direction}, { + onError: () => alert("failed to move this path"), + }); + }; + const handleMoveMarkdown = (md, direction) => { + moveMarkdown.mutate({markdown: md, direction: direction}, { + onError: () => alert("failed to move this markdown"), + }) + }; + + const sortedPaths = childPaths + ? childPaths.slice().sort((a, b) => a.order.localeCompare(b.order)) + : []; + + const sortedMarkdowns = markdowns + ? markdowns.filter(md => md.title !== "index").sort((a, b) => a.order.localeCompare(b.order)) + : []; if(childError || markdownError){ return
  • Error...
  • ; } - return (
  • -
    +
    {isEditing ? ( -
    {
    ) : ( - + { indexMarkdown ? ( @@ -112,25 +133,67 @@ const PathNode = ({ path, isRoot = false }) => {

    +
    + + +
    {isExpanded && ( diff --git a/src/components/Navigations/SideNavigation.js b/src/components/Navigations/SideNavigation.js index da0a1be..8b77b6f 100644 --- a/src/components/Navigations/SideNavigation.js +++ b/src/components/Navigations/SideNavigation.js @@ -9,6 +9,9 @@ const SideNavigation = () => { const deletePath = useDeletePath(); const updatePath = useUpdatePath(); + 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, { @@ -47,7 +50,7 @@ const SideNavigation = () => {