refactor: uploading counters vuex state

This commit is contained in:
Ramires Viana
2020-07-07 19:41:13 +00:00
parent d0b359561f
commit b4f131be50
5 changed files with 98 additions and 65 deletions

View File

@@ -3,7 +3,15 @@ const getters = {
isFiles: state => !state.loading && state.route.name === 'Files',
isListing: (state, getters) => getters.isFiles && state.req.isDir,
isEditor: (state, getters) => getters.isFiles && (state.req.type === 'text' || state.req.type === 'textImmutable'),
selectedCount: state => state.selected.length
selectedCount: state => state.selected.length,
progress : state => {
if (state.uploading.progress.length == 0) {
return 0;
}
let sum = state.uploading.progress.reduce((acc, val) => acc + val)
return Math.ceil(sum / state.uploading.size * 100);
}
}
export default getters

View File

@@ -22,7 +22,13 @@ const state = {
show: null,
showShell: false,
showMessage: null,
showConfirm: null
showConfirm: null,
uploading: {
id: 0,
count: 0,
size: 0,
progress: []
}
}
export default new Vuex.Store({

View File

@@ -1,3 +1,4 @@
import Vue from 'vue'
import * as i18n from '@/i18n'
import moment from 'moment'
@@ -83,8 +84,27 @@ const mutations = {
state.clipboard.key = ''
state.clipboard.items = []
},
setProgress: (state, value) => {
state.progress = value
uploadingIncrementId: (state) => {
state.uploading.id = state.uploading.id + 1
},
uploadingIncrementSize: (state, value) => {
state.uploading.size = state.uploading.size + value
},
uploadingIncrementCount: (state) => {
state.uploading.count = state.uploading.count + 1
},
uploadingDecreaseCount: (state) => {
state.uploading.count = state.uploading.count - 1
},
uploadigSetProgress(state, { id, loaded }) {
Vue.set(state.uploading.progress, id, loaded)
},
uploadingReset: (state) => {
state.uploading.id = 0
state.uploading.size = 0
state.uploading.count = 0
state.uploading.progress = []
}
}