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

fix(files): Reset drop notice on firefox #47465

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions apps/files/src/components/DragAndDropNotice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@

<script lang="ts">
import type { Folder } from '@nextcloud/files'

import { Permission } from '@nextcloud/files'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { UploadStatus } from '@nextcloud/upload'
import { defineComponent, type PropType } from 'vue'
import debounce from 'debounce'

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

import { useNavigation } from '../composables/useNavigation'
import { dataTransferToFileTree, onDropExternalFiles } from '../services/DropService'
import logger from '../logger.ts'
import type { RawLocation } from 'vue-router'

export default defineComponent({
name: 'DragAndDropNotice',
Expand Down Expand Up @@ -86,18 +89,29 @@ export default defineComponent({
}
return null
},

/**
* Debounced function to reset the drag over state
* Required as Firefox has a bug where no dragleave is emitted:
* https://bugzilla.mozilla.org/show_bug.cgi?id=656164
*/
resetDragOver() {
return debounce(() => {
this.dragover = false
}, 3000)
},
},

mounted() {
// Add events on parent to cover both the table and DragAndDrop notice
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
const mainContent = window.document.getElementById('app-content-vue') as HTMLElement
artonge marked this conversation as resolved.
Show resolved Hide resolved
mainContent.addEventListener('dragover', this.onDragOver)
mainContent.addEventListener('dragleave', this.onDragLeave)
mainContent.addEventListener('drop', this.onContentDrop)
},

beforeDestroy() {
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
const mainContent = window.document.getElementById('app-content-vue') as HTMLElement
mainContent.removeEventListener('dragover', this.onDragOver)
mainContent.removeEventListener('dragleave', this.onDragLeave)
mainContent.removeEventListener('drop', this.onContentDrop)
Expand All @@ -112,6 +126,7 @@ export default defineComponent({
if (isForeignFile) {
// Only handle uploading of outside files (not Nextcloud files)
this.dragover = true
this.resetDragOver()
artonge marked this conversation as resolved.
Show resolved Hide resolved
}
},

Expand All @@ -126,6 +141,7 @@ export default defineComponent({

if (this.dragover) {
this.dragover = false
this.resetDragOver.clear()
}
},

Expand All @@ -134,6 +150,7 @@ export default defineComponent({
event.preventDefault()
if (this.dragover) {
this.dragover = false
this.resetDragOver.clear()
}
},

Expand Down Expand Up @@ -186,16 +203,24 @@ export default defineComponent({

if (lastUpload !== undefined) {
logger.debug('Scrolling to last upload in current folder', { lastUpload })
this.$router.push({
...this.$route,
const location: RawLocation = {
path: this.$route.path,
artonge marked this conversation as resolved.
Show resolved Hide resolved
// Keep params but change file id
params: {
view: this.$route.params?.view ?? 'files',
fileid: parseInt(lastUpload.response!.headers['oc-fileid']),
...this.$route.params,
fileid: String(lastUpload.response!.headers['oc-fileid']),
},
susnux marked this conversation as resolved.
Show resolved Hide resolved
query: {
...this.$route.query,
},
})
}
// Remove open file from query
delete location.query.openfile
this.$router.push(location)
}

this.dragover = false
this.resetDragOver.clear()
},

t,
Expand Down
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

Loading