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

[stable20.1] Add upload editor in files sidebar mode #5113

Merged
merged 5 commits into from
Feb 9, 2021
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
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