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

Properly handle multiple shares in a row and refactor sharee loading #2367

Merged
merged 1 commit into from
Oct 13, 2020
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
43 changes: 35 additions & 8 deletions src/components/board/SharingTabSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@
:options="formatedSharees"
:user-select="true"
label="displayName"
:loading="isLoading || !!isSearching"
:disabled="isLoading"
track-by="multiselectKey"
:internal-search="true"
@input="clickAddAcl"
@search-change="asyncFind" />
@search-change="asyncFind">
<template #noOptions>
{{ isSearching ? t('deck', 'Searching for users, groups and circles ...') : t('deck', 'No participants found') }}
</template>
<template #noResult>
{{ isSearching ? t('deck', 'Searching for users, groups and circles ...') : t('deck', 'No participants found') }}
</template>
</Multiselect>

<ul
id="shareWithList"
Expand Down Expand Up @@ -63,6 +72,7 @@ import { Avatar, Multiselect, Actions, ActionButton, ActionCheckbox } from '@nex
import { CollectionList } from 'nextcloud-vue-collections'
import { mapGetters, mapState } from 'vuex'
import { getCurrentUser } from '@nextcloud/auth'
import { showError } from '@nextcloud/dialogs'

export default {
name: 'SharingTabSidebar',
Expand All @@ -83,6 +93,7 @@ export default {
data() {
return {
isLoading: false,
isSearching: false,
addAcl: null,
addAclForAPI: null,
}
Expand Down Expand Up @@ -137,21 +148,37 @@ export default {
this.asyncFind('')
},
methods: {
asyncFind(query) {
this.isLoading = true
this.$store.dispatch('loadSharees', query).then(response => {
this.isLoading = false
})
async asyncFind(query) {
// manual debounce to handle async searching more easily and have more control over the loading state
const timestamp = (new Date()).getTime()
if (!this.isSearching || timestamp > this.isSearching + 300) {
this.isSearching = timestamp
await this.$store.dispatch('loadSharees', query)

// only reset searching flag if the most recent search finished
if (this.isSearching === timestamp) {
this.isSearching = false
}
}
},
clickAddAcl() {
async clickAddAcl() {
this.addAclForAPI = {
type: this.addAcl.value.shareType,
participant: this.addAcl.value.shareWith,
permissionEdit: false,
permissionShare: false,
permissionManage: false,
}
this.$store.dispatch('addAclToCurrentBoard', this.addAclForAPI)
this.isLoading = true
try {
await this.$store.dispatch('addAclToCurrentBoard', this.addAclForAPI)
} catch (e) {
const errorMessage = t('deck', 'Failed to create share with {displayName}', { displayName: this.addAcl.displayName })
console.error(errorMessage, e)
showError(errorMessage)
}
this.addAcl = null
this.isLoading = false
},
clickEditAcl(acl) {
this.addAclForAPI = Object.assign({}, acl)
Expand Down
20 changes: 8 additions & 12 deletions src/store/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import comment from './comment'
import trashbin from './trashbin'
import attachment from './attachment'
import overview from './overview'
import debounce from 'lodash/debounce'
Vue.use(Vuex)

const apiClient = new BoardApi()
Expand Down Expand Up @@ -392,7 +391,7 @@ export default new Vuex.Store({
const boards = await apiClient.loadBoards()
commit('setBoards', boards)
},
loadSharees: debounce(function({ commit }, query) {
async loadSharees({ commit }, query) {
const params = new URLSearchParams()
if (typeof query === 'undefined') {
return
Expand All @@ -402,10 +401,9 @@ export default new Vuex.Store({
params.append('perPage', 20)
params.append('itemType', [0, 1, 7])

axios.get(generateOcsUrl('apps/files_sharing/api/v1') + 'sharees', { params }).then((response) => {
commit('setSharees', response.data.ocs.data)
})
}, 250),
const response = await axios.get(generateOcsUrl('apps/files_sharing/api/v1') + 'sharees', { params })
commit('setSharees', response.data.ocs.data)
},

setBoardFilter({ commmit }, filter) {
commmit('setBoardFilter', filter)
Expand Down Expand Up @@ -454,13 +452,11 @@ export default new Vuex.Store({
},

// acl actions
addAclToCurrentBoard({ dispatch, commit }, newAcl) {
async addAclToCurrentBoard({ dispatch, commit }, newAcl) {
newAcl.boardId = this.state.currentBoard.id
apiClient.addAcl(newAcl)
.then((returnAcl) => {
commit('addAclToCurrentBoard', returnAcl)
dispatch('refreshBoard', newAcl.boardId)
})
const result = await apiClient.addAcl(newAcl)
commit('addAclToCurrentBoard', result)
dispatch('refreshBoard', newAcl.boardId)
},
updateAclFromCurrentBoard({ commit }, acl) {
acl.boardId = this.state.currentBoard.id
Expand Down