Skip to content

Commit

Permalink
Merge pull request #43267 from nextcloud/fix/files/selection-typing-a…
Browse files Browse the repository at this point in the history
…nd-drop-upload
  • Loading branch information
skjnldsv authored Feb 7, 2024
2 parents 071ebaa + 5f4a0d9 commit 840e8fc
Show file tree
Hide file tree
Showing 12 changed files with 481 additions and 665 deletions.
50 changes: 30 additions & 20 deletions apps/files/src/components/DragAndDropNotice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { defineComponent } from 'vue'
import { Folder, Permission } from '@nextcloud/files'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { UploadStatus } from '@nextcloud/upload'

import TrayArrowDownIcon from 'vue-material-design-icons/TrayArrowDown.vue'

Expand Down Expand Up @@ -143,10 +144,11 @@ export default defineComponent({
}
},

onDrop(event: DragEvent) {
logger.debug('Dropped on DragAndDropNotice', { event, error: this.cantUploadLabel })
async onDrop(event: DragEvent) {
logger.debug('Dropped on DragAndDropNotice', { event })

if (!this.canUpload || this.isQuotaExceeded) {
// cantUploadLabel is null if we can upload
if (this.cantUploadLabel) {
showError(this.cantUploadLabel)
return
}
Expand All @@ -162,23 +164,31 @@ export default defineComponent({
// Start upload
logger.debug(`Uploading files to ${this.currentFolder.path}`)
// Process finished uploads
handleDrop(event.dataTransfer).then((uploads) => {
logger.debug('Upload terminated', { uploads })
showSuccess(t('files', 'Upload successful'))

// Scroll to last upload in current directory if terminated
const lastUpload = uploads.findLast((upload) => !upload.file.webkitRelativePath.includes('/') && upload.response?.headers?.['oc-fileid'])
if (lastUpload !== undefined) {
this.$router.push({
...this.$route,
params: {
view: this.$route.params?.view ?? 'files',
// Remove instanceid from header response
fileid: parseInt(lastUpload.response!.headers['oc-fileid']),
},
})
}
})
const uploads = await handleDrop(event.dataTransfer)
logger.debug('Upload terminated', { uploads })

if (uploads.some((upload) => upload.status === UploadStatus.FAILED)) {
showError(t('files', 'Some files could not be uploaded'))
const failedUploads = uploads.filter((upload) => upload.status === UploadStatus.FAILED)
logger.debug('Some files could not be uploaded', { failedUploads })
} else {
showSuccess(t('files', 'Files uploaded successfully'))
}

// Scroll to last successful upload in current directory if terminated
const lastUpload = uploads.findLast((upload) => upload.status !== UploadStatus.FAILED
&& !upload.file.webkitRelativePath.includes('/')
&& upload.response?.headers?.['oc-fileid'])

if (lastUpload !== undefined) {
this.$router.push({
...this.$route,
params: {
view: this.$route.params?.view ?? 'files',
fileid: parseInt(lastUpload.response!.headers['oc-fileid']),
},
})
}
}
this.dragover = false
},
Expand Down
Loading

0 comments on commit 840e8fc

Please sign in to comment.