Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated folder tree view #438

Merged
merged 6 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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