Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[full-ci] Implement single file upload on "paste" action #9140

Merged
merged 8 commits into from Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-upload-file-on-paste
@@ -0,0 +1,6 @@
Enhancement: Upload file on paste

We've implemented the possibility to upload a single file in the clipboard from anywhere via paste.

https://github.com/owncloud/web/pull/9140
https://github.com/owncloud/web/issues/9047
22 changes: 21 additions & 1 deletion packages/web-app-files/src/components/AppBar/CreateAndUpload.vue
Expand Up @@ -240,15 +240,35 @@ export default defineComponent({
return unref(currentFolder)?.canUpload({ user: store.getters.user })
})

const handlePasteFileEvent = (event) => {
if (store.state.Files.clipboardResources.length) {
return
}
const items = (event.clipboardData || event.originalEvent.clipboardData).items
const files = []
for (let index in items) {
const item = items[index]
if (item.kind === 'file') {
const file = item.getAsFile()
files.push(file)
event.preventDefault()
break
}
}
lookacat marked this conversation as resolved.
Show resolved Hide resolved
instance.onFilesSelected(files)
}

onMounted(() => {
filesSelectedSub = uppyService.subscribe('filesSelected', instance.onFilesSelected)
uploadCompletedSub = uppyService.subscribe('uploadCompleted', instance.onUploadComplete)
document.addEventListener('paste', handlePasteFileEvent)
})

onBeforeUnmount(() => {
uppyService.unsubscribe('filesSelected', filesSelectedSub)
uppyService.unsubscribe('uploadCompleted', uploadCompletedSub)
uppyService.removeDropTarget()
document.removeEventListener('paste', handlePasteFileEvent)
})

watch(
Expand Down Expand Up @@ -357,7 +377,7 @@ export default defineComponent({
methods: {
...mapActions('Files', ['clearClipboardFiles', 'pasteSelectedFiles']),
...mapActions(['showMessage', 'createModal', 'setModalInputErrorMessage', 'hideModal']),
...mapMutations('Files', ['UPSERT_RESOURCE']),
...mapMutations('Files', ['UPSERT_RESOURCE', 'clipboardResources']),
lookacat marked this conversation as resolved.
Show resolved Hide resolved
...mapMutations('runtime/spaces', ['UPDATE_SPACE_FIELD']),
...mapMutations(['SET_QUOTA']),

Expand Down