-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathdataroom-search-results.tsx
More file actions
160 lines (150 loc) · 4.92 KB
/
dataroom-search-results.tsx
File metadata and controls
160 lines (150 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import Link from "next/link";
import { useRouter } from "next/router";
import { TeamContextType } from "@/context/team-context";
import { ChevronRight, FileIcon, FolderIcon } from "lucide-react";
import {
DataroomFolderDocumentWithPath,
DataroomFolderWithCountAndPath,
} from "@/lib/swr/use-dataroom";
import { safeSlugify } from "@/lib/utils";
import DataroomDocumentCard from "@/components/datarooms/dataroom-document-card";
import FolderCard from "@/components/documents/folder-card";
function FolderPathBreadcrumb({
folderPath,
dataroomId,
}: {
folderPath: string[];
dataroomId: string;
}) {
const router = useRouter();
const { id } = router.query as { id: string };
const buildLink = (index: number) => {
if (index < 0) return `/datarooms/${id}/documents`;
const slugs = folderPath.slice(0, index + 1).map(safeSlugify);
return `/datarooms/${id}/documents/${slugs.join("/")}`;
};
return (
<div className="mt-1 flex flex-wrap items-center gap-x-1 text-xs leading-5 text-muted-foreground">
<p className="flex items-center gap-x-1">
<FolderIcon className="h-3 w-3" />
<Link
href={`/datarooms/${id}/documents`}
onClick={(e) => e.stopPropagation()}
className="relative z-10 hover:underline"
>
Root
</Link>
</p>
{folderPath.map((name, index) => (
<p key={index} className="flex items-center gap-x-1">
<ChevronRight className="h-3 w-3" />
<FolderIcon className="h-3 w-3" />
<Link
href={buildLink(index)}
onClick={(e) => e.stopPropagation()}
className="relative z-10 hover:underline"
>
{name}
</Link>
</p>
))}
</div>
);
}
export function DataroomSearchResults({
documents,
folders,
teamInfo,
dataroomId,
searchQuery,
}: {
documents: DataroomFolderDocumentWithPath[];
folders: DataroomFolderWithCountAndPath[];
teamInfo: TeamContextType | null;
dataroomId: string;
searchQuery: string;
}) {
const totalResults = documents.length + folders.length;
return (
<div className="space-y-4">
<div className="flex items-center gap-x-2 text-sm text-muted-foreground">
<span>
Search results for "{searchQuery}"
</span>
<span className="text-xs">
({totalResults} result{totalResults !== 1 ? "s" : ""})
</span>
</div>
{totalResults === 0 ? (
<div className="flex flex-col items-center justify-center rounded-lg border border-dashed py-12">
<p className="text-sm text-muted-foreground">
No documents or folders found matching "{searchQuery}"
</p>
</div>
) : (
<ul role="list" className="space-y-4">
{folders.length > 0 && (
<>
<li className="flex items-center gap-x-1 text-sm text-muted-foreground">
<FolderIcon className="h-4 w-4" />
<span>
{folders.length} folder{folders.length !== 1 ? "s" : ""}
</span>
</li>
{folders.map((folder) => (
<li key={`folder-${folder.id}`}>
<div>
<FolderCard
folder={folder}
teamInfo={teamInfo}
isDataroom={true}
dataroomId={dataroomId}
/>
{folder.folderPath.length > 0 && (
<div className="ml-4 mt-1">
<FolderPathBreadcrumb
folderPath={folder.folderPath}
dataroomId={dataroomId}
/>
</div>
)}
</div>
</li>
))}
</>
)}
{documents.length > 0 && (
<>
<li className="flex items-center gap-x-1 text-sm text-muted-foreground">
<FileIcon className="h-4 w-4" />
<span>
{documents.length} document
{documents.length !== 1 ? "s" : ""}
</span>
</li>
{documents.map((doc) => (
<li key={`document-${doc.id}`}>
<div>
<DataroomDocumentCard
document={doc}
teamInfo={teamInfo}
dataroomId={dataroomId}
/>
{doc.folderPath.length > 0 && (
<div className="ml-4 mt-1">
<FolderPathBreadcrumb
folderPath={doc.folderPath}
dataroomId={dataroomId}
/>
</div>
)}
</div>
</li>
))}
</>
)}
</ul>
)}
</div>
);
}