Skip to content

Commit e0bbf07

Browse files
committed
fixup! feat(files): unify drag and drop methods
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent c95741c commit e0bbf07

3 files changed

Lines changed: 194 additions & 144 deletions

File tree

apps/files/src/components/BreadCrumbs.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,13 @@ export default defineComponent({
141141
142142
// Hide breadcrumbs if an upload is ongoing
143143
shouldShowBreadcrumbs(): boolean {
144-
return this.filesListWidth > 400 && !this.isUploadInProgress
144+
// If we're uploading files, only show the breadcrumbs
145+
// if the files list is greater than 768px wide
146+
if (this.isUploadInProgress) {
147+
return this.filesListWidth > 768
148+
}
149+
// If we're not uploading, we have enough space from 400px
150+
return this.filesListWidth > 400
145151
},
146152
147153
// used to show the views icon for the first breadcrumb
@@ -240,7 +246,7 @@ export default defineComponent({
240246
241247
// Else we're moving/copying files
242248
const nodes = selection.map(fileid => this.filesStore.getNode(fileid)) as Node[]
243-
await onDropInternalFiles(folder, nodes, isCopy)
249+
await onDropInternalFiles(nodes, folder, contents.contents, isCopy)
244250
245251
// Reset selection after we dropped the files
246252
// if the dropped files are within the selection

apps/files/src/components/DragAndDropNotice.vue

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import { UploadStatus } from '@nextcloud/upload'
5353
import TrayArrowDownIcon from 'vue-material-design-icons/TrayArrowDown.vue'
5454
5555
import logger from '../logger.js'
56-
import { handleDrop } from '../services/DropService'
56+
import { dataTransferToFileTree, handleDrop, onDropExternalFiles } from '../services/DropService'
5757
5858
export default defineComponent({
5959
name: 'DragAndDropNotice',
@@ -76,6 +76,10 @@ export default defineComponent({
7676
},
7777
7878
computed: {
79+
currentView() {
80+
return this.$navigation.active
81+
},
82+
7983
/**
8084
* Check if the current folder has create permissions
8185
*/
@@ -146,8 +150,6 @@ export default defineComponent({
146150
},
147151
148152
async onDrop(event: DragEvent) {
149-
logger.debug('Dropped on DragAndDropNotice', { event })
150-
151153
// cantUploadLabel is null if we can upload
152154
if (this.cantUploadLabel) {
153155
showError(this.cantUploadLabel)
@@ -161,38 +163,50 @@ export default defineComponent({
161163
event.preventDefault()
162164
event.stopPropagation()
163165
164-
if (event.dataTransfer && event.dataTransfer.items.length > 0) {
165-
// Start upload
166-
logger.debug(`Uploading files to ${this.currentFolder.path}`)
167-
// Process finished uploads
168-
const uploads = await handleDrop(event.dataTransfer)
169-
logger.debug('Upload terminated', { uploads })
170-
171-
if (uploads.some((upload) => upload.status === UploadStatus.FAILED)) {
172-
showError(t('files', 'Some files could not be uploaded'))
173-
const failedUploads = uploads.filter((upload) => upload.status === UploadStatus.FAILED)
174-
logger.debug('Some files could not be uploaded', { failedUploads })
175-
} else {
176-
showSuccess(t('files', 'Files uploaded successfully'))
177-
}
178-
179-
// Scroll to last successful upload in current directory if terminated
180-
const lastUpload = uploads.findLast((upload) => upload.status !== UploadStatus.FAILED
181-
&& !upload.file.webkitRelativePath.includes('/')
182-
&& upload.response?.headers?.['oc-fileid'])
183-
184-
if (lastUpload !== undefined) {
185-
this.$router.push({
186-
...this.$route,
187-
params: {
188-
view: this.$route.params?.view ?? 'files',
189-
fileid: parseInt(lastUpload.response!.headers['oc-fileid']),
190-
},
191-
})
192-
}
166+
// Caching the selection
167+
const items = [...event.dataTransfer?.items || []] as DataTransferItem[]
168+
169+
// We need to process the dataTransfer ASAP before the
170+
// browser clears it. This is why we cache the items too.
171+
const fileTree = await dataTransferToFileTree(items)
172+
173+
// We might not have the target directory fetched yet
174+
const contents = await this.currentView?.getContents(this.currentFolder.path)
175+
const folder = contents?.folder
176+
if (!folder) {
177+
showError(this.t('files', 'Target folder does not exist any more'))
178+
return
179+
}
180+
181+
// If another button is pressed, cancel it. This
182+
// allows cancelling the drag with the right click.
183+
if (event.button !== 0) {
184+
return
185+
}
186+
187+
logger.debug('Dropped', { event, folder, fileTree })
188+
189+
// Check whether we're uploading files
190+
const uploads = await onDropExternalFiles(fileTree, folder, contents.contents)
191+
192+
// Scroll to last successful upload in current directory if terminated
193+
const lastUpload = uploads.findLast((upload) => upload.status !== UploadStatus.FAILED
194+
&& !upload.file.webkitRelativePath.includes('/')
195+
&& upload.response?.headers?.['oc-fileid'])
196+
197+
if (lastUpload !== undefined) {
198+
this.$router.push({
199+
...this.$route,
200+
params: {
201+
view: this.$route.params?.view ?? 'files',
202+
fileid: parseInt(lastUpload.response!.headers['oc-fileid']),
203+
},
204+
})
193205
}
206+
194207
this.dragover = false
195208
},
209+
196210
t,
197211
},
198212
})

0 commit comments

Comments
 (0)