Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 98d5d86

Browse files
committed
fix(files): Reset drop notice on firefox
On firefox there is an old bug where when you move a dragged file outside the window the `dragleave` event is never emitted. So we just use a timeout to reset the drag over state. Also a small change: Use the ID of the main container instead of relying on tag name and class. (The ID is guranteed as other APIs rely on it, while the class is just used internally). Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 6d2253e commit 98d5d86

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

apps/files/src/components/DragAndDropNotice.vue

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@
2727

2828
<script lang="ts">
2929
import type { Folder } from '@nextcloud/files'
30+
3031
import { Permission } from '@nextcloud/files'
3132
import { showError } from '@nextcloud/dialogs'
3233
import { translate as t } from '@nextcloud/l10n'
3334
import { UploadStatus } from '@nextcloud/upload'
3435
import { defineComponent, type PropType } from 'vue'
36+
import debounce from 'debounce'
3537
3638
import TrayArrowDownIcon from 'vue-material-design-icons/TrayArrowDown.vue'
3739
3840
import { useNavigation } from '../composables/useNavigation'
3941
import { dataTransferToFileTree, onDropExternalFiles } from '../services/DropService'
4042
import logger from '../logger.ts'
43+
import type { RawLocation } from 'vue-router'
4144
4245
export default defineComponent({
4346
name: 'DragAndDropNotice',
@@ -86,18 +89,29 @@ export default defineComponent({
8689
}
8790
return null
8891
},
92+
93+
/**
94+
* Debounced function to reset the drag over state
95+
* Required as Firefox has a bug where no dragleave is emitted:
96+
* https://bugzilla.mozilla.org/show_bug.cgi?id=656164
97+
*/
98+
resetDragOver() {
99+
return debounce(() => {
100+
this.dragover = false
101+
}, 3000)
102+
},
89103
},
90104
91105
mounted() {
92106
// Add events on parent to cover both the table and DragAndDrop notice
93-
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
107+
const mainContent = window.document.getElementById('app-content-vue') as HTMLElement
94108
mainContent.addEventListener('dragover', this.onDragOver)
95109
mainContent.addEventListener('dragleave', this.onDragLeave)
96110
mainContent.addEventListener('drop', this.onContentDrop)
97111
},
98112
99113
beforeDestroy() {
100-
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
114+
const mainContent = window.document.getElementById('app-content-vue') as HTMLElement
101115
mainContent.removeEventListener('dragover', this.onDragOver)
102116
mainContent.removeEventListener('dragleave', this.onDragLeave)
103117
mainContent.removeEventListener('drop', this.onContentDrop)
@@ -112,6 +126,7 @@ export default defineComponent({
112126
if (isForeignFile) {
113127
// Only handle uploading of outside files (not Nextcloud files)
114128
this.dragover = true
129+
this.resetDragOver()
115130
}
116131
},
117132
@@ -126,6 +141,7 @@ export default defineComponent({
126141
127142
if (this.dragover) {
128143
this.dragover = false
144+
this.resetDragOver.clear()
129145
}
130146
},
131147
@@ -134,6 +150,7 @@ export default defineComponent({
134150
event.preventDefault()
135151
if (this.dragover) {
136152
this.dragover = false
153+
this.resetDragOver.clear()
137154
}
138155
},
139156
@@ -186,16 +203,21 @@ export default defineComponent({
186203
187204
if (lastUpload !== undefined) {
188205
logger.debug('Scrolling to last upload in current folder', { lastUpload })
189-
this.$router.push({
190-
...this.$route,
206+
const location: RawLocation = {
207+
path: this.$route.path,
208+
// Keep params but change file id
191209
params: {
192-
view: this.$route.params?.view ?? 'files',
193-
fileid: parseInt(lastUpload.response!.headers['oc-fileid']),
210+
...this.$route.params,
211+
fileid: String(lastUpload.response!.headers['oc-fileid']),
194212
},
195-
})
213+
}
214+
// Remove open file from query
215+
delete location.query?.openfile
216+
this.$router.push(location)
196217
}
197218
198219
this.dragover = false
220+
this.resetDragOver.clear()
199221
},
200222
201223
t,

0 commit comments

Comments
 (0)