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

feat(shares): add drag-n-drop option in the modal #10898

Merged
merged 1 commit into from Nov 15, 2023
Merged
Changes from all 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
35 changes: 34 additions & 1 deletion src/components/NewMessage/NewMessageUploadEditor.vue
Expand Up @@ -26,7 +26,10 @@
class="upload-editor"
:container="container"
@close="handleDismiss">
<div class="upload-editor">
<div class="upload-editor"
@dragover.prevent="handleDragOver"
@dragleave.prevent="handleDragLeave"
@drop.prevent="handleDropFiles">
<template v-if="!isVoiceMessage">
<!--native file picker, hidden -->
<input id="file-upload"
Expand All @@ -36,6 +39,7 @@
class="hidden-visually"
@change="handleFileInput">
<TransitionWrapper class="upload-editor__previews"
:class="{'dragging-over': isDraggingOver}"
name="fade"
tag="div"
group>
Expand Down Expand Up @@ -104,6 +108,7 @@ export default {
data() {
return {
modalContainerId: null,
isDraggingOver: false,
}
},

Expand Down Expand Up @@ -201,6 +206,29 @@ export default {
handleRemoveFileFromSelection(id) {
this.$store.dispatch('removeFileFromSelection', id)
},

handleDragOver(event) {
if (event.dataTransfer.types.includes('Files')) {
this.isDraggingOver = true
}
},

handleDragLeave(event) {
if (!event.currentTarget.contains(event.relatedTarget)) {
this.isDraggingOver = false
}
},

handleDropFiles(event) {
if (!this.isDraggingOver) {
return
}

this.isDraggingOver = false

const files = Object.values(event.dataTransfer.files)
this.$store.dispatch('initialiseUpload', { files, token: this.token, uploadId: this.currentUploadId })
},
},
}
</script>
Expand All @@ -218,6 +246,11 @@ export default {
position: relative;
overflow: auto;
flex-wrap: wrap;

&.dragging-over {
outline: 3px dashed var(--color-primary-element);
border-radius: var(--border-radius-large);
}
}
}

Expand Down