Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

refactor(filetree): update navigation

Marc Seitzc8b821bbba67
diff --git a/components/datarooms/folders/sidebar-tree.tsx b/components/datarooms/folders/sidebar-tree.tsx
index 220817b1..515cab8c 100644
--- a/components/datarooms/folders/sidebar-tree.tsx
+++ b/components/datarooms/folders/sidebar-tree.tsx
@@ -47,6 +47,14 @@ const FolderComponent = memo(
[folder.childFolders, dataroomId],
);
+ const handleFolderClick = () => {
+ router.push(`/datarooms/${dataroomId}/documents${folder.path}`);
+ };
+
+ const handleChevronClick = (e: React.MouseEvent) => {
+ e.stopPropagation(); // Prevent navigation
+ };
+
return (
<FileTree.Folder
name={folder.name}
@@ -55,9 +63,8 @@ const FolderComponent = memo(
folder.path === "/" + (router.query.name as string[])?.join("/")
}
childActive={router.query.name?.includes(folder.name)}
- onToggle={() =>
- router.push(`/datarooms/${dataroomId}/documents${folder.path}`)
- }
+ onToggle={handleFolderClick}
+ onChevronClick={handleChevronClick} // Pass the new handler
>
{childFolders}
{documents}
diff --git a/components/ui/nextra-filetree.tsx b/components/ui/nextra-filetree.tsx
index 2bd402f7..0c8dd602 100644
--- a/components/ui/nextra-filetree.tsx
+++ b/components/ui/nextra-filetree.tsx
@@ -7,17 +7,14 @@ import { createContext, memo, useCallback, useContext, useState } from "react";
import type { ReactElement, ReactNode } from "react";
import {
+ ChevronRightIcon,
FileIcon,
- FolderClosedIcon,
FolderIcon,
FolderOpenIcon,
} from "lucide-react";
import { cn } from "@/lib/utils";
-import ChevronDown from "../shared/icons/chevron-down";
-import ChevronRight from "../shared/icons/chevron-right";
-
const ctx = createContext(0);
function useIndent() {
@@ -32,6 +29,7 @@ interface FolderProps {
active?: boolean;
childActive?: boolean;
onToggle?: (open: boolean) => void;
+ onChevronClick?: (e: React.MouseEvent) => void; // New prop
children: ReactNode;
}
@@ -71,50 +69,50 @@ const Folder = memo<FolderProps>(
childActive,
defaultOpen = false,
onToggle,
+ onChevronClick,
}) => {
const indent = useIndent();
const [isOpen, setIsOpen] = useState(defaultOpen || active || childActive);
- const toggle = useCallback(() => {
- onToggle?.(!isOpen);
- setIsOpen(!isOpen);
- }, [isOpen, onToggle]);
+ const toggle = useCallback(
+ (e: React.MouseEvent) => {
+ e.stopPropagation();
+ onToggle?.(!isOpen);
+ },
+ [isOpen, onToggle],
+ );
const isFolderOpen = open === undefined ? isOpen : open;
return (
<li className="flex w-full list-none flex-col">
- <button
- onClick={toggle}
+ <div
title={name}
className={cn(
"inline-flex w-full cursor-pointer items-center",
- "rounded-md text-foreground duration-100 hover:bg-gray-200 hover:dark:bg-muted",
+ "rounded-md text-foreground duration-100 hover:bg-gray-100 hover:dark:bg-muted",
"px-3 py-1.5 leading-6",
- active && "bg-gray-200 font-semibold dark:bg-muted",
+ "group",
+ active && "bg-gray-100 font-semibold dark:bg-muted",
)}
+ onClick={toggle}
>
<Ident />
- <ChevronRight
- className={cn(
- "chevron mr-1 h-4 w-4 shrink-0 transition-transform duration-150",
- isFolderOpen && "rotate-90",
- )}
- />
- {/* <svg width="2em" height="1em" viewBox="0 0 24 24">
- <path
- fill="none"
- stroke="currentColor"
- strokeLinecap="round"
- strokeLinejoin="round"
- strokeWidth="2"
- d={
- isFolderOpen
- ? "M5 19a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h4l2 2h4a2 2 0 0 1 2 2v1M5 19h14a2 2 0 0 0 2-2v-5a2 2 0 0 0-2-2H9a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2Z"
- : "M3 7v10a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-6l-2-2H5a2 2 0 0 0-2 2Z"
- }
+ <div
+ className="mr-2 rounded p-1 hover:bg-gray-300 group-hover:bg-gray-300 dark:group-hover:bg-muted"
+ onClick={(e) => {
+ e.stopPropagation();
+ onChevronClick?.(e); // Call the new prop if provided
+ setIsOpen(!isOpen);
+ }}
+ >
+ <ChevronRightIcon
+ className={cn(
+ "chevron h-4 w-4 shrink-0 transition-transform duration-150 ",
+ isFolderOpen && "rotate-90",
+ )}
/>
- </svg> */}
+ </div>
{isFolderOpen ? (
<FolderOpenIcon className="h-5 w-5 shrink-0" aria-hidden="true" />
) : (
@@ -126,7 +124,7 @@ const Folder = memo<FolderProps>(
>
{label ?? name}
</span>
- </button>
+ </div>
{isFolderOpen && (
<ul>
<ctx.Provider value={indent + 1}>{children}</ctx.Provider>
@@ -147,9 +145,9 @@ const File = memo<FileProps>(({ label, name, active, onToggle }) => {
<li
className={cn(
"flex list-none",
- "rounded-md text-foreground duration-100 hover:bg-gray-200 hover:dark:bg-muted",
+ "rounded-md text-foreground duration-100 hover:bg-gray-100 hover:dark:bg-muted",
"px-3 py-1.5 leading-6",
- active && "bg-gray-200 font-semibold dark:bg-muted",
+ active && "bg-gray-100 font-semibold dark:bg-muted",
)}
>
<span
@@ -157,16 +155,6 @@ const File = memo<FileProps>(({ label, name, active, onToggle }) => {
onClick={toggle}
>
<Ident />
- {/* <svg width="1em" height="1em" viewBox="0 0 24 24">
- <path
- fill="none"
- stroke="currentColor"
- strokeLinecap="round"
- strokeLinejoin="round"
- strokeWidth="2"
- d="M9 12h6m-6 4h6m2 5H7a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5.586a1 1 0 0 1 .707.293l5.414 5.414a1 1 0 0 1 .293.707V19a2 2 0 0 1-2 2Z"
- />
- </svg> */}
<FileIcon className="h-5 w-5 shrink-0" aria-hidden="true" />
<span className="ml-2 w-fit truncate" title={(label ?? name) as string}>
{label ?? name}