Skip to content

Commit

Permalink
fix(federation): scope button disabling to invitation user interacted…
Browse files Browse the repository at this point in the history
… with

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Mar 1, 2024
1 parent 138d585 commit 892c945
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/components/LeftSidebar/InvitationHandler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
{{ t('spreed', 'Join conversations from remote Nextcloud servers') }}
</p>
<ul class="inbox__list">
<li v-for="item of invitations"
:key="`invitation_${item.id}`"
<li v-for="(item, id) in invitations"
:key="`invitation_${id}`"
class="inbox__item">
<ConversationIcon :item="item" hide-user-status />
<div class="inbox__item-desc">
Expand All @@ -49,20 +49,19 @@
<NcButton type="tertiary"
:aria-label="t('spreed', 'Decline invitation')"
:title="t('spreed', 'Decline invitation')"
:disabled="isLoading"
@click="rejectShare(item.id)">
:disabled="!!item.loading"
@click="rejectShare(id)">
<template #icon>
<NcLoadingIcon v-if="isLoading" :size="20" />
<CancelIcon v-else :size="20" />
<CancelIcon :size="20" />
</template>
</NcButton>
<NcButton type="primary"
:aria-label="t('spreed', 'Accept invitation')"
:title="t('spreed', 'Accept invitation')"
:disabled="isLoading"
@click="acceptShare(item.id)">
:disabled="!!item.loading"
@click="acceptShare(id)">
<template #icon>
<NcLoadingIcon v-if="isLoading" :size="20" />
<NcLoadingIcon v-if="item.loading === 'accept'" :size="20" />
<CheckIcon v-else :size="20" />
</template>
{{ t('spreed', 'Accept') }}
Expand Down Expand Up @@ -108,7 +107,6 @@ export default {
data() {
return {
modal: false,
isLoading: false,
}
},

Expand All @@ -118,13 +116,15 @@ export default {
},

invitations() {
return Object.values(this.federationStore.pendingShares)
.map(item => ({
...item,
const pendingShares = this.federationStore.pendingShares
for (const id in pendingShares) {
pendingShares[id] = Object.assign({}, pendingShares[id], {
type: CONVERSATION.TYPE.GROUP,
isFederatedConversation: true,
isDummyConversation: true,
}))
})
}
return pendingShares
},
},

Expand All @@ -140,20 +140,17 @@ export default {
},

async acceptShare(id) {
this.isLoading = true
const conversation = await this.federationStore.acceptShare(id)
this.isLoading = false
if (conversation?.token) {
this.$store.dispatch('addConversation', conversation)
this.$router.push({ name: 'conversation', params: { token: conversation.token } })
}
if (this.invitations.length === 0) {
this.closeModal()
}
},

async rejectShare(id) {
this.isLoading = true
await this.federationStore.rejectShare(id)
this.isLoading = false
if (this.invitations.length === 0) {
this.closeModal()
}
Expand Down
3 changes: 3 additions & 0 deletions src/stores/federation.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const useFederationStore = defineStore('federation', {
if (!this.pendingShares[id]) {
return
}
Vue.delete(this.pendingShares[id], 'loading')
Vue.set(this.acceptedShares, id, {
...this.pendingShares[id],
accessToken: conversation.remoteAccessToken,
Expand All @@ -138,6 +139,7 @@ export const useFederationStore = defineStore('federation', {
return
}
try {
Vue.set(this.pendingShares[id], 'loading', 'accept')
const response = await acceptShare(id)
this.markInvitationAccepted(id, response.data.ocs.data)
return response.data.ocs.data
Expand All @@ -157,6 +159,7 @@ export const useFederationStore = defineStore('federation', {
return
}
try {
Vue.set(this.pendingShares[id], 'loading', 'reject')
await rejectShare(id)
Vue.delete(this.pendingShares, id)
} catch (error) {
Expand Down

0 comments on commit 892c945

Please sign in to comment.