Skip to content

Commit 7c49529

Browse files
authored
Merge pull request #563 from mfts/fix/drag
2 parents bac7eea + 02ace10 commit 7c49529

File tree

4 files changed

+237
-116
lines changed

4 files changed

+237
-116
lines changed

components/datarooms/dataroom-items-list.tsx

Lines changed: 90 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
DataroomFolderDocument,
2929
DataroomFolderWithCount,
3030
} from "@/lib/swr/use-dataroom";
31+
import { useMediaQuery } from "@/lib/utils/use-media-query";
3132

3233
import { DraggableItem } from "../documents/drag-and-drop/draggable-item";
3334
import { DroppableFolder } from "../documents/drag-and-drop/droppable-folder";
@@ -54,6 +55,8 @@ export function DataroomItemsList({
5455
folderCount: number;
5556
documentCount: number;
5657
}) {
58+
const { isMobile } = useMediaQuery();
59+
5760
const [uploads, setUploads] = useState<
5861
{ fileName: string; progress: number; documentId?: string }[]
5962
>([]);
@@ -221,6 +224,29 @@ export function DataroomItemsList({
221224
const renderItem = (item: FolderOrDocument) => {
222225
const itemId = `${item.itemType}-${item.id}`;
223226

227+
if (isMobile) {
228+
return (
229+
<>
230+
{item.itemType === "folder" ? (
231+
<FolderCard
232+
key={itemId}
233+
folder={item}
234+
teamInfo={teamInfo}
235+
isDataroom={!!dataroomId}
236+
dataroomId={dataroomId}
237+
/>
238+
) : (
239+
<DataroomDocumentCard
240+
key={itemId}
241+
document={item as DataroomFolderDocument}
242+
teamInfo={teamInfo}
243+
dataroomId={dataroomId}
244+
/>
245+
)}
246+
</>
247+
);
248+
}
249+
224250
return (
225251
<>
226252
{item.itemType === "folder" ? (
@@ -315,55 +341,71 @@ export function DataroomItemsList({
315341
setRejectedFiles={setRejectedFiles}
316342
dataroomId={dataroomId}
317343
>
318-
<DndContext
319-
sensors={sensors}
320-
onDragStart={handleDragStart}
321-
onDragOver={handleDragOver}
322-
onDragEnd={handleDragEnd}
323-
onDragCancel={() => setIsOverFolder(false)}
324-
measuring={{
325-
droppable: {
326-
strategy: MeasuringStrategy.Always,
327-
},
328-
}}
329-
>
330-
<ul role="list" className="space-y-4">
331-
{mixedItems.map(renderItem)}
332-
</ul>
333-
334-
<Portal>
335-
<DragOverlay className="cursor-default">
336-
<motion.div
337-
initial={{ scale: 1, opacity: 1 }}
338-
animate={{ scale: 0.5, opacity: 1 }}
339-
exit={{ scale: 1, opacity: 1 }}
340-
transition={{ duration: 0.2 }}
341-
className="relative flex h-20 w-40 items-center justify-center rounded-lg bg-gray-200"
342-
>
343-
<div className="h-20 w-40 rounded-lg bg-white text-foreground dark:bg-secondary">
344-
{draggedDocumentName}
345-
</div>
346-
{selectedDocuments.length > 1 ? (
347-
<div className="absolute right-0 top-0 rounded-full bg-white p-1 ring ring-gray-500">
348-
<span className="text-xs font-semibold text-gray-500">
349-
{selectedDocuments.length}
350-
</span>
344+
{isMobile ? (
345+
<div>
346+
<ul role="list" className="space-y-4">
347+
{mixedItems.map(renderItem)}
348+
</ul>
349+
<Portal containerId={"documents-header-count"}>
350+
<HeaderContent />
351+
</Portal>
352+
{mixedItems.length === 0 && (
353+
<div className="flex h-full justify-center">
354+
<EmptyDocuments />
355+
</div>
356+
)}
357+
</div>
358+
) : (
359+
<DndContext
360+
sensors={sensors}
361+
onDragStart={handleDragStart}
362+
onDragOver={handleDragOver}
363+
onDragEnd={handleDragEnd}
364+
onDragCancel={() => setIsOverFolder(false)}
365+
measuring={{
366+
droppable: {
367+
strategy: MeasuringStrategy.Always,
368+
},
369+
}}
370+
>
371+
<ul role="list" className="space-y-4">
372+
{mixedItems.map(renderItem)}
373+
</ul>
374+
375+
<Portal>
376+
<DragOverlay className="cursor-default">
377+
<motion.div
378+
initial={{ scale: 1, opacity: 1 }}
379+
animate={{ scale: 0.5, opacity: 1 }}
380+
exit={{ scale: 1, opacity: 1 }}
381+
transition={{ duration: 0.2 }}
382+
className="relative flex h-20 w-40 items-center justify-center rounded-lg bg-gray-200"
383+
>
384+
<div className="h-20 w-40 rounded-lg bg-white text-foreground dark:bg-secondary">
385+
{draggedDocumentName}
351386
</div>
352-
) : null}
353-
</motion.div>
354-
</DragOverlay>
355-
</Portal>
356-
357-
<Portal containerId={"documents-header-count"}>
358-
<HeaderContent />
359-
</Portal>
360-
361-
{mixedItems.length === 0 && (
362-
<div className="flex h-full justify-center">
363-
<EmptyDocuments />
364-
</div>
365-
)}
366-
</DndContext>
387+
{selectedDocuments.length > 1 ? (
388+
<div className="absolute right-0 top-0 rounded-full bg-white p-1 ring ring-gray-500">
389+
<span className="text-xs font-semibold text-gray-500">
390+
{selectedDocuments.length}
391+
</span>
392+
</div>
393+
) : null}
394+
</motion.div>
395+
</DragOverlay>
396+
</Portal>
397+
398+
<Portal containerId={"documents-header-count"}>
399+
<HeaderContent />
400+
</Portal>
401+
402+
{mixedItems.length === 0 && (
403+
<div className="flex h-full justify-center">
404+
<EmptyDocuments />
405+
</div>
406+
)}
407+
</DndContext>
408+
)}
367409
</UploadZone>
368410
{showDrawer ? (
369411
<UploadNotificationDrawer

0 commit comments

Comments
 (0)