Skip to content

Commit

Permalink
Merge pull request #5113 from nextcloud/backport/4535/stable20.1
Browse files Browse the repository at this point in the history
[stable20.1] Add upload editor in files sidebar mode
  • Loading branch information
PVince81 authored Feb 9, 2021
2 parents fef5bae + 87918f2 commit c1d0547
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
3 changes: 3 additions & 0 deletions src/FilesSidebarTabApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<template v-else>
<CallButton class="call-button" />
<ChatView :token="token" />
<UploadEditor />
</template>
</div>
</template>
Expand All @@ -60,6 +61,7 @@ import { signalingKill } from './utils/webrtc/index'
import { getCurrentUser } from '@nextcloud/auth'
import { loadState } from '@nextcloud/initial-state'
import Axios from '@nextcloud/axios'
import UploadEditor from './components/UploadEditor'
import CallButton from './components/TopBar/CallButton'
import ChatView from './components/ChatView'
import duplicateSessionHandler from './mixins/duplicateSessionHandler'
Expand All @@ -73,6 +75,7 @@ export default {
components: {
CallButton,
ChatView,
UploadEditor,
},

mixins: [
Expand Down
21 changes: 2 additions & 19 deletions src/components/UploadEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ export default {
Plus,
},

data() {
return {
modalDismissed: false,
}
},

computed: {
token() {
return this.$store.getters.getToken()
Expand All @@ -101,33 +95,22 @@ export default {
return []
},

showUploadEditor() {
return this.$store.getters.showUploadEditor
},

showModal() {
return this.showUploadEditor && !this.modalDismissed
return !!this.currentUploadId
},

addMoreAriaLabel() {
return t('spreed', 'Add more files')
},
},

watch: {
currentUploadId() {
this.modalDismissed = false
},
},

methods: {
handleDismiss() {
this.modalDismissed = true
this.$store.dispatch('discardUpload', this.currentUploadId)
},

handleUpload() {
this.$store.dispatch('uploadFiles', this.currentUploadId)
this.modalDismissed = true
},
/**
* Clicks the hidden file input when clicking the correspondent ActionButton,
Expand Down
33 changes: 21 additions & 12 deletions src/store/fileUploadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const state = {
uploads: {
},
currentUploadId: undefined,
showUploadEditor: false,
}

const getters = {
Expand Down Expand Up @@ -87,10 +86,6 @@ const getters = {
currentUploadId: (state) => {
return state.currentUploadId
},

showUploadEditor: (state) => {
return state.showUploadEditor
},
}

const mutations = {
Expand Down Expand Up @@ -168,11 +163,6 @@ const mutations = {
state.currentUploadId = currentUploadId
},

// Shows hides the upload editor
showUploadEditor(state, show) {
state.showUploadEditor = show
},

removeFileFromSelection(state, fileId) {
const uploadId = state.currentUploadId
for (const key in state.uploads[uploadId].files) {
Expand All @@ -181,15 +171,17 @@ const mutations = {
}
}
},

discardUpload(state, uploadId) {
Vue.delete(state.uploads, uploadId)
},
}

const actions = {

initialiseUpload({ commit, dispatch }, { uploadId, token, files }) {
// Set last upload id
commit('setCurrentUploadId', uploadId)
// Show upload editor
commit('showUploadEditor', true)

files.forEach(file => {
// Get localurl for previews
Expand All @@ -204,12 +196,29 @@ const actions = {
})
},

/**
* Discards an upload
* @param {object} param0 Commit and state
* @param {object} uploadId The unique uploadId
*/
discardUpload({ commit, state, getters }, uploadId) {
if (state.currentUploadId === uploadId) {
commit('setCurrentUploadId', undefined)
}

commit('discardUpload', { uploadId })
},

/**
* Uploads the files to the root directory of the user
* @param {object} param0 Commit, state and getters
* @param {object} uploadId The unique uploadId
*/
async uploadFiles({ commit, dispatch, state, getters }, uploadId) {
if (state.currentUploadId === uploadId) {
commit('setCurrentUploadId', undefined)
}

EventBus.$emit('uploadStart')

// Tag the previously indexed files and add the temporary messages to the
Expand Down

0 comments on commit c1d0547

Please sign in to comment.