Skip to content

Commit

Permalink
Merge pull request #13249 from nextcloud/feat/noid/pollstore-to-pinia
Browse files Browse the repository at this point in the history
  • Loading branch information
Antreesy authored Sep 14, 2024
2 parents 3aad2b4 + ffb7869 commit dd61c8e
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ import CallButton from '../../../../TopBar/CallButton.vue'
import { useIsInCall } from '../../../../../composables/useIsInCall.js'
import { useMessageInfo } from '../../../../../composables/useMessageInfo.js'
import { EventBus } from '../../../../../services/EventBus.js'
import { usePollsStore } from '../../../../../stores/polls.js'
import { parseSpecialSymbols, parseMentions } from '../../../../../utils/textParse.ts'
// Regular expression to check for Unicode emojis in message text
Expand Down Expand Up @@ -199,8 +200,10 @@ export default {
isEditable,
isFileShare,
} = useMessageInfo(message)
return {
isInCall: useIsInCall(),
pollsStore: usePollsStore(),
isEditable,
isFileShare,
}
Expand Down Expand Up @@ -241,7 +244,7 @@ export default {
return false
}
return this.isInCall && !!this.$store.getters.getNewPolls[this.message.messageParameters.object.id]
return this.isInCall && this.pollsStore.isNewPoll(this.message.messageParameters.object.id)
},
isTemporary() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { t } from '@nextcloud/l10n'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import { POLL } from '../../../../../constants.js'
import { usePollsStore } from '../../../../../stores/polls.js'
export default {
name: 'Poll',
Expand Down Expand Up @@ -74,9 +75,15 @@ export default {
},
},
setup() {
return {
pollsStore: usePollsStore(),
}
},
computed: {
poll() {
return this.$store.getters.getPoll(this.token, this.id)
return this.pollsStore.getPoll(this.token, this.id)
},
pollFooterText() {
Expand All @@ -96,15 +103,15 @@ export default {
t,
getPollData() {
if (!this.poll) {
this.$store.dispatch('getPollData', {
this.pollsStore.getPollData({
token: this.token,
pollId: this.id,
})
}
},
openPoll() {
this.$store.dispatch('setActivePoll', {
this.pollsStore.setActivePoll({
token: this.token,
pollId: this.id,
name: this.name,
Expand Down
30 changes: 15 additions & 15 deletions src/components/NewMessage/NewMessagePollEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadi
import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js'
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
import pollService from '../../services/pollService.js'
import { usePollsStore } from '../../stores/polls.js'
export default {
name: 'NewMessagePollEditor',
Expand All @@ -102,6 +102,12 @@ export default {
emits: ['close'],
setup() {
return {
pollsStore: usePollsStore(),
}
},
data() {
return {
isPrivate: false,
Expand Down Expand Up @@ -140,21 +146,15 @@ export default {
},
async createPoll() {
try {
const response = await pollService.postNewPoll(
this.token,
this.pollQuestion,
this.pollOptions,
this.isPrivate ? 1 : 0,
this.isMultipleAnswer ? 0 : 1)
// Add the poll immediately to the store
this.$store.dispatch('addPoll', {
token: this.token,
poll: response.data.ocs.data,
})
const poll = await this.pollsStore.createPoll({
token: this.token,
question: this.pollQuestion,
options: this.pollOptions,
resultMode: this.isPrivate ? 1 : 0,
maxVotes: this.isMultipleAnswer ? 0 : 1
})
if (poll) {
this.dismissEditor()
} catch (error) {
console.debug(error)
}
},
Expand Down
22 changes: 12 additions & 10 deletions src/components/PollViewer/PollViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ import { useId } from '../../composables/useId.ts'
import { useIsInCall } from '../../composables/useIsInCall.js'
import { POLL } from '../../constants.js'
import { EventBus } from '../../services/EventBus.js'
import { usePollsStore } from '../../stores/polls.js'
export default {
name: 'PollViewer',
Expand All @@ -138,6 +139,7 @@ export default {
return {
isInCall: useIsInCall(),
pollsStore: usePollsStore(),
voteToSubmit,
modalPage,
loading,
Expand All @@ -147,7 +149,7 @@ export default {
computed: {
activePoll() {
return this.$store.getters.activePoll
return this.pollsStore.activePoll
},
name() {
Expand All @@ -167,7 +169,7 @@ export default {
},
poll() {
return this.$store.getters.getPoll(this.token, this.id)
return this.pollsStore.getPoll(this.token, this.id)
},
selfHasVoted() {
Expand Down Expand Up @@ -238,12 +240,12 @@ export default {
},
id(value) {
this.$store.dispatch('hidePollToast', value)
this.pollsStore.hidePollToast(value)
},
isInCall(value) {
if (!value) {
this.$store.dispatch('hideAllPollToasts')
this.pollsStore.hideAllPollToasts()
}
},
Expand Down Expand Up @@ -274,7 +276,7 @@ export default {
n,
getPollData() {
if (!this.poll) {
this.$store.dispatch('getPollData', {
this.pollsStore.getPollData({
token: this.token,
pollId: this.id,
})
Expand All @@ -292,21 +294,21 @@ export default {
return
}
this.$store.dispatch('addPollToast', { token, message })
this.pollsStore.addPollToast({ token, message })
},
dismissModal() {
this.$store.dispatch('removeActivePoll')
this.pollsStore.removeActivePoll()
this.voteToSubmit = []
},
async submitVote() {
this.loading = true
try {
await this.$store.dispatch('submitVote', {
await this.pollsStore.submitVote({
token: this.token,
pollId: this.id,
vote: this.voteToSubmit.map(element => +element),
optionIds: this.voteToSubmit.map(element => +element),
})
this.modalPage = 'results'
} catch (error) {
Expand All @@ -319,7 +321,7 @@ export default {
async endPoll() {
this.loading = true
try {
await this.$store.dispatch('endPoll', {
await this.pollsStore.endPoll({
token: this.token,
pollId: this.id,
})
Expand Down
7 changes: 5 additions & 2 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from '../services/messagesService.ts'
import { useChatExtrasStore } from '../stores/chatExtras.js'
import { useGuestNameStore } from '../stores/guestName.js'
import { usePollsStore } from '../stores/polls.js'
import { useReactionsStore } from '../stores/reactions.js'
import { useSharedItemsStore } from '../stores/sharedItems.js'
import CancelableRequest from '../utils/cancelableRequest.js'
Expand Down Expand Up @@ -575,7 +576,8 @@ const actions = {
}

if (message.systemMessage === 'poll_voted') {
context.dispatch('debounceGetPollData', {
const pollsStore = usePollsStore()
pollsStore.debounceGetPollData({
token,
pollId: message.messageParameters.poll.id,
})
Expand All @@ -584,7 +586,8 @@ const actions = {
}

if (message.systemMessage === 'poll_closed') {
context.dispatch('getPollData', {
const pollsStore = usePollsStore()
pollsStore.getPollData({
token,
pollId: message.messageParameters.poll.id,
})
Expand Down
1 change: 0 additions & 1 deletion src/store/messagesStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ describe('messagesStore', () => {
testStoreConfig.modules.conversationsStore.actions.updateConversationLastMessage = updateConversationLastMessageMock
testStoreConfig.modules.conversationsStore.actions.updateConversationLastReadMessage = updateConversationLastReadMessageMock
testStoreConfig.modules.conversationsStore.actions.updateConversationLastActive = updateConversationLastActiveAction
testStoreConfig.modules.pollStore.getters.debounceGetPollData = jest.fn()

store = new Vuex.Store(testStoreConfig)
})
Expand Down
Loading

0 comments on commit dd61c8e

Please sign in to comment.