Skip to content

Commit 15e3059

Browse files
committed
feat: Implement duplicating files in shared drive ✨
1 parent 7ad546d commit 15e3059

File tree

6 files changed

+73
-4
lines changed

6 files changed

+73
-4
lines changed

src/declarations.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ declare module 'cozy-client/dist/models/file' {
7575
export const copy: (
7676
client: import('cozy-client/types/CozyClient').CozyClient,
7777
file: Partial<import('components/FolderPicker/types').File>,
78-
destination: import('components/FolderPicker/types').File
78+
destination: import('components/FolderPicker/types').File,
79+
{
80+
driveId
81+
}?: {
82+
driveId: string
83+
}
7984
) => Promise<void>
8085
export const isDirectory: (
8186
file: import('components/FolderPicker/types').File

src/modules/duplicate/components/DuplicateModal.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ interface DuplicateModalProps {
1818
currentFolder: File
1919
onClose: () => void | Promise<void>
2020
showNextcloudFolder?: boolean
21+
showSharedDriveFolder?: boolean
22+
driveId?: string
2123
}
2224

2325
const DuplicateModal: FC<DuplicateModalProps> = ({
2426
entries,
2527
currentFolder,
2628
onClose,
27-
showNextcloudFolder
29+
showNextcloudFolder,
30+
showSharedDriveFolder,
31+
driveId
2832
}) => {
2933
const { t } = useI18n()
3034
const { showAlert } = useAlert()
@@ -39,7 +43,11 @@ const DuplicateModal: FC<DuplicateModalProps> = ({
3943
setBusy(true)
4044
await Promise.all(
4145
entries.map(async entry => {
42-
await registerCancelable(copy(client, entry as Partial<File>, folder))
46+
await registerCancelable(
47+
copy(client, entry as Partial<File>, folder, {
48+
driveId: driveId ?? ''
49+
})
50+
)
4351
})
4452
)
4553

@@ -88,6 +96,7 @@ const DuplicateModal: FC<DuplicateModalProps> = ({
8896
return (
8997
<FolderPicker
9098
showNextcloudFolder={showNextcloudFolder}
99+
showSharedDriveFolder={showSharedDriveFolder}
91100
currentFolder={currentFolder}
92101
entries={entries}
93102
// eslint-disable-next-line @typescript-eslint/no-misused-promises

src/modules/navigation/AppRoute.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import FileOpenerExternal from '@/modules/viewer/FileOpenerExternal'
3535
import { KonnectorRoutes } from '@/modules/views/Drive/KonnectorRoutes'
3636
import { FavoritesView } from '@/modules/views/Favorites/FavoritesView'
3737
import { FolderDuplicateView } from '@/modules/views/Folder/FolderDuplicateView'
38+
import { SharedDriveDuplicateView } from '@/modules/views/Folder/SharedDriveDuplicateView'
3839
import { MoveFilesView } from '@/modules/views/Modal/MoveFilesView'
3940
import { QualifyFileView } from '@/modules/views/Modal/QualifyFileView'
4041
import { ShareDisplayedFolderView } from '@/modules/views/Modal/ShareDisplayedFolderView'
@@ -141,6 +142,7 @@ const AppRoute = () => (
141142
/>
142143
<Route path="file/:fileId/revision" element={<FileHistory />} />
143144
<Route path="file/:fileId/v/revision" element={<FileHistory />} />
145+
<Route path="duplicate" element={<SharedDriveDuplicateView />} />
144146
</Route>
145147
</>
146148
) : null}

src/modules/shareddrives/components/SharedDriveFolderBody.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
1212

1313
import { useModalContext } from '@/lib/ModalContext'
1414
import { download, infos, versions, rename, trash, hr } from '@/modules/actions'
15+
import { duplicateTo } from '@/modules/actions/components/duplicateTo'
1516
import { FolderBody } from '@/modules/folder/components/FolderBody'
1617

1718
const SharedDriveFolderBody = ({
@@ -51,7 +52,7 @@ const SharedDriveFolderBody = ({
5152
refresh
5253
}
5354
const actions = makeActions(
54-
[download, hr, rename, infos, hr, versions, hr, trash],
55+
[download, hr, rename, duplicateTo, infos, hr, versions, hr, trash],
5556
actionsOptions
5657
)
5758

src/modules/views/Folder/FolderDuplicateView.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import flag from 'cozy-flags'
88
import { LoaderModal } from '@/components/LoaderModal'
99
import useDisplayedFolder from '@/hooks/useDisplayedFolder'
1010
import { DuplicateModal } from '@/modules/duplicate/components/DuplicateModal'
11+
import { useSharedDrives } from '@/modules/shareddrives/hooks/useSharedDrives'
1112
import { buildParentsByIdsQuery } from '@/queries'
1213

1314
const FolderDuplicateView: FC = () => {
@@ -16,6 +17,7 @@ const FolderDuplicateView: FC = () => {
1617
state: { fileIds?: string[] }
1718
}
1819
const { displayedFolder } = useDisplayedFolder()
20+
const { sharedDrives } = useSharedDrives()
1921

2022
const hasFileIds = state.fileIds != undefined
2123

@@ -39,6 +41,7 @@ const FolderDuplicateView: FC = () => {
3941
return (
4042
<DuplicateModal
4143
showNextcloudFolder={!flag('drive.hide-nextcloud-dev')}
44+
showSharedDriveFolder={sharedDrives.length > 0}
4245
currentFolder={displayedFolder}
4346
entries={fileResult.data}
4447
onClose={onClose}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React, { FC } from 'react'
2+
import { Navigate, useLocation, useNavigate } from 'react-router-dom'
3+
4+
import flag from 'cozy-flags'
5+
6+
import { LoaderModal } from '@/components/LoaderModal'
7+
import useDisplayedFolder from '@/hooks/useDisplayedFolder'
8+
import { DuplicateModal } from '@/modules/duplicate/components/DuplicateModal'
9+
import { useMultipleSharedDriveFolders } from '@/modules/shareddrives/hooks/useMultipleSharedDriveFolders'
10+
11+
const SharedDriveDuplicateView: FC = () => {
12+
const navigate = useNavigate()
13+
const { state } = useLocation() as {
14+
state: { fileIds?: string[] }
15+
}
16+
const { displayedFolder } = useDisplayedFolder()
17+
18+
const hasFileIds = state.fileIds != undefined
19+
20+
const { sharedDriveResults } = useMultipleSharedDriveFolders({
21+
folderIds: state.fileIds ?? [],
22+
driveId: displayedFolder?.driveId ?? ''
23+
})
24+
25+
if (!hasFileIds) {
26+
return <Navigate to=".." replace={true} />
27+
}
28+
29+
if (sharedDriveResults && displayedFolder) {
30+
const onClose = (): void => {
31+
navigate('..', { replace: true })
32+
}
33+
34+
return (
35+
<DuplicateModal
36+
showNextcloudFolder={!flag('drive.hide-nextcloud-dev')}
37+
showSharedDriveFolder={true}
38+
currentFolder={displayedFolder}
39+
entries={sharedDriveResults}
40+
onClose={onClose}
41+
driveId={displayedFolder.driveId}
42+
/>
43+
)
44+
}
45+
46+
return <LoaderModal />
47+
}
48+
49+
export { SharedDriveDuplicateView }

0 commit comments

Comments
 (0)