Skip to content

Commit

Permalink
Merge pull request #438 from mfts/feat/new-dataroom-viewer
Browse files Browse the repository at this point in the history
feat: updated folder tree view
  • Loading branch information
mfts authored May 24, 2024
2 parents 4b191a4 + fc58c8f commit 480fa84
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 257 deletions.
121 changes: 0 additions & 121 deletions components/datarooms/add-dataroom-document-modal.tsx

This file was deleted.

52 changes: 31 additions & 21 deletions components/datarooms/folders/selection-tree.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { memo, useMemo } from "react";

import { TSelectedFolder } from "@/components/documents/move-folder-modal";
import { FileTree } from "@/components/ui/nextra-filetree";

import {
Expand All @@ -12,12 +13,12 @@ import { buildNestedFolderStructure } from "./utils";
const FolderComponentSelection = memo(
({
folder,
selectedFolderId,
setFolderId,
selectedFolder,
setSelectedFolder,
}: {
folder: DataroomFolderWithDocuments;
selectedFolderId: string;
setFolderId: React.Dispatch<React.SetStateAction<string>>;
selectedFolder: TSelectedFolder;
setSelectedFolder: React.Dispatch<React.SetStateAction<TSelectedFolder>>;
}) => {
// Recursively render child folders if they exist
const childFolders = useMemo(
Expand All @@ -26,25 +27,34 @@ const FolderComponentSelection = memo(
<FolderComponentSelection
key={childFolder.id}
folder={childFolder}
selectedFolderId={selectedFolderId}
setFolderId={setFolderId}
selectedFolder={selectedFolder}
setSelectedFolder={setSelectedFolder}
/>
)),
[folder.childFolders, selectedFolderId, setFolderId],
[folder.childFolders, selectedFolder, setSelectedFolder],
);

const isActive = folder.id === selectedFolder?.id;
const isChildActive = folder.childFolders.some(
(childFolder) => childFolder.id === selectedFolder?.id,
);

return (
<div
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
setFolderId(folder.id);
setSelectedFolder({ id: folder.id, name: folder.name });
}}
>
<FileTree.Folder
name={folder.name}
key={folder.id}
active={folder.id === selectedFolderId}
active={isActive}
childActive={isChildActive}
onToggle={() =>
setSelectedFolder({ id: folder.id, name: folder.name })
}
>
{childFolders}
</FileTree.Folder>
Expand All @@ -56,12 +66,12 @@ FolderComponentSelection.displayName = "FolderComponentSelection";

const SidebarFoldersSelectipon = ({
folders,
selectedFolderId,
setFolderId,
selectedFolder,
setSelectedFolder,
}: {
folders: DataroomFolderWithDocuments[];
selectedFolderId: string;
setFolderId: React.Dispatch<React.SetStateAction<string>>;
selectedFolder: TSelectedFolder;
setSelectedFolder: React.Dispatch<React.SetStateAction<TSelectedFolder>>;
}) => {
const nestedFolders = useMemo(() => {
if (folders) {
Expand All @@ -76,8 +86,8 @@ const SidebarFoldersSelectipon = ({
<FolderComponentSelection
key={folder.id}
folder={folder}
selectedFolderId={selectedFolderId}
setFolderId={setFolderId}
selectedFolder={selectedFolder}
setSelectedFolder={setSelectedFolder}
/>
))}
</FileTree>
Expand All @@ -86,12 +96,12 @@ const SidebarFoldersSelectipon = ({

export function SidebarFolderTreeSelection({
dataroomId,
selectedFolderId,
setFolderId,
selectedFolder,
setSelectedFolder,
}: {
dataroomId: string;
selectedFolderId: string;
setFolderId: React.Dispatch<React.SetStateAction<string>>;
selectedFolder: TSelectedFolder;
setSelectedFolder: React.Dispatch<React.SetStateAction<TSelectedFolder>>;
}) {
const { folders, error } = useDataroomFoldersTree({ dataroomId });

Expand All @@ -100,8 +110,8 @@ export function SidebarFolderTreeSelection({
return (
<SidebarFoldersSelectipon
folders={folders}
selectedFolderId={selectedFolderId}
setFolderId={setFolderId}
selectedFolder={selectedFolder}
setSelectedFolder={setSelectedFolder}
/>
);
}
27 changes: 20 additions & 7 deletions components/datarooms/folders/sidebar-tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,30 @@ const FolderComponent = memo(
[folder.childFolders, dataroomId],
);

const isActive =
folder.path === "/" + (router.query.name as string[])?.join("/");
const isChildActive = folder.childFolders.some(
(childFolder) =>
childFolder.path === "/" + (router.query.name as string[])?.join("/"),
);

const handleFolderClick = () => {
router.push(
`/datarooms/${dataroomId}/documents${folder.path}`,
`/datarooms/${dataroomId}/documents${folder.path}`,
{
scroll: false,
},
);
};

return (
<FileTree.Folder
name={folder.name}
key={folder.id}
active={
folder.path === "/" + (router.query.name as string[])?.join("/")
}
childActive={router.query.name?.includes(folder.name)}
onToggle={() =>
router.push(`/datarooms/${dataroomId}/documents${folder.path}`)
}
active={isActive}
childActive={isChildActive}
onToggle={handleFolderClick}
>
{childFolders}
{documents}
Expand Down
13 changes: 8 additions & 5 deletions components/datarooms/folders/view-tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ const FolderComponent = memo(
[folder.childFolders, folderId, setFolderId],
);

const isActive = folder.id === folderId;
const isChildActive = folder.childFolders.some(
(childFolder) => childFolder.id === folderId,
);

return (
<div
onClick={(e) => {
Expand All @@ -80,11 +85,9 @@ const FolderComponent = memo(
<FileTree.Folder
name={folder.name}
key={folder.id}
// childActive={folder.parentId === folderId}
active={folder.id === folderId}
// onToggle={() =>
// router.push(`/datarooms/${dataroomId}/documents${folder.path}`)
// }
active={isActive}
childActive={isChildActive}
onToggle={() => setFolderId(folder.id)}
>
{childFolders}
{documents}
Expand Down
Loading

0 comments on commit 480fa84

Please sign in to comment.