diff --git a/src/components/MessagesList/MessagesGroup/Message/MessagePart/MessageBody.vue b/src/components/MessagesList/MessagesGroup/Message/MessagePart/MessageBody.vue index 574c6471c72..8a90977072d 100644 --- a/src/components/MessagesList/MessagesGroup/Message/MessagePart/MessageBody.vue +++ b/src/components/MessagesList/MessagesGroup/Message/MessagePart/MessageBody.vue @@ -141,7 +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 { usePollsStore } from '../../../../../stores/polls.ts' import { parseSpecialSymbols, parseMentions } from '../../../../../utils/textParse.ts' // Regular expression to check for Unicode emojis in message text diff --git a/src/components/MessagesList/MessagesGroup/Message/MessagePart/Poll.vue b/src/components/MessagesList/MessagesGroup/Message/MessagePart/Poll.vue index 4c2197446ac..ae9f9423a73 100644 --- a/src/components/MessagesList/MessagesGroup/Message/MessagePart/Poll.vue +++ b/src/components/MessagesList/MessagesGroup/Message/MessagePart/Poll.vue @@ -39,7 +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' +import { usePollsStore } from '../../../../../stores/polls.ts' export default { name: 'Poll', diff --git a/src/components/NewMessage/NewMessagePollEditor.vue b/src/components/NewMessage/NewMessagePollEditor.vue index a65e22a10be..166137a5547 100644 --- a/src/components/NewMessage/NewMessagePollEditor.vue +++ b/src/components/NewMessage/NewMessagePollEditor.vue @@ -77,7 +77,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 { usePollsStore } from '../../stores/polls.js' +import { usePollsStore } from '../../stores/polls.ts' export default { name: 'NewMessagePollEditor', diff --git a/src/components/PollViewer/PollViewer.vue b/src/components/PollViewer/PollViewer.vue index 5e978013c99..2085a089050 100644 --- a/src/components/PollViewer/PollViewer.vue +++ b/src/components/PollViewer/PollViewer.vue @@ -108,7 +108,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' +import { usePollsStore } from '../../stores/polls.ts' export default { name: 'PollViewer', diff --git a/src/store/messagesStore.js b/src/store/messagesStore.js index 6a659c19c2f..260696b3eef 100644 --- a/src/store/messagesStore.js +++ b/src/store/messagesStore.js @@ -30,7 +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 { usePollsStore } from '../stores/polls.ts' import { useReactionsStore } from '../stores/reactions.js' import { useSharedItemsStore } from '../stores/sharedItems.js' import CancelableRequest from '../utils/cancelableRequest.js' diff --git a/src/stores/__tests__/polls.spec.js b/src/stores/__tests__/polls.spec.js index d44de007014..c278b63ce25 100644 --- a/src/stores/__tests__/polls.spec.js +++ b/src/stores/__tests__/polls.spec.js @@ -13,7 +13,7 @@ import { endPoll, } from '../../services/pollService.ts' import { generateOCSResponse } from '../../test-helpers.js' -import { usePollsStore } from '../polls.js' +import { usePollsStore } from '../polls.ts' jest.mock('../../services/pollService', () => ({ createPoll: jest.fn(), diff --git a/src/stores/polls.js b/src/stores/polls.ts similarity index 73% rename from src/stores/polls.js rename to src/stores/polls.ts index 3592b822e77..b82c6baa33e 100644 --- a/src/stores/polls.js +++ b/src/stores/polls.ts @@ -15,9 +15,22 @@ import { submitVote, endPoll, } from '../services/pollService.ts' - +import type { + ChatMessage, + createPollParams, + Poll, votePollParams +} from '../types/index.ts' + +type createPollPayload = { token: string } & createPollParams +type submitVotePayload = { token: string, pollId: number } & Pick +type State = { + polls: Record>, + debouncedFunctions: Record void>>, + activePoll: null, + pollToastsQueue: Record>, +} export const usePollsStore = defineStore('polls', { - state: () => ({ + state: (): State => ({ polls: {}, debouncedFunctions: {}, activePoll: null, @@ -25,24 +38,24 @@ export const usePollsStore = defineStore('polls', { }), getters: { - getPoll: (state) => (token, pollId) => { + getPoll: (state) => (token: string, pollId: number): Poll => { return state.polls[token]?.[pollId] }, - isNewPoll: (state) => (pollId) => { + isNewPoll: (state) => (pollId: number) => { return state.pollToastsQueue[pollId] !== undefined }, }, actions: { - addPoll({ token, poll }) { + addPoll({ token, poll }: { token: string, poll: Poll }) { if (!this.polls[token]) { Vue.set(this.polls, token, {}) } Vue.set(this.polls[token], poll.id, poll) }, - async getPollData({ token, pollId }) { + async getPollData({ token, pollId }: { token: string, pollId: number }) { try { const response = await getPollData(token, pollId) this.addPoll({ token, poll: response.data.ocs.data }) @@ -60,7 +73,7 @@ export const usePollsStore = defineStore('polls', { * @param { string } root0.token The token of the conversation * @param { number } root0.pollId The id of the poll */ - debounceGetPollData({ token, pollId }) { + debounceGetPollData({ token, pollId }: { token: string, pollId: number }) { if (!this.debouncedFunctions[token]) { Vue.set(this.debouncedFunctions, token, {}) } @@ -75,7 +88,7 @@ export const usePollsStore = defineStore('polls', { this.debouncedFunctions[token][pollId]() }, - async createPoll({ token, question, options, resultMode, maxVotes }) { + async createPoll({ token, question, options, resultMode, maxVotes }: createPollPayload) { try { const response = await createPoll({ token, @@ -92,7 +105,7 @@ export const usePollsStore = defineStore('polls', { } }, - async submitVote({ token, pollId, optionIds }) { + async submitVote({ token, pollId, optionIds }: submitVotePayload) { try { const response = await submitVote(token, pollId, optionIds) this.addPoll({ token, poll: response.data.ocs.data }) @@ -102,7 +115,7 @@ export const usePollsStore = defineStore('polls', { } }, - async endPoll({ token, pollId }) { + async endPoll({ token, pollId }: { token: string, pollId: number }) { try { const response = await endPoll(token, pollId) this.addPoll({ token, poll: response.data.ocs.data }) @@ -112,7 +125,7 @@ export const usePollsStore = defineStore('polls', { } }, - setActivePoll({ token, pollId, name }) { + setActivePoll({ token, pollId, name }: { token: string, pollId: number, name: string }) { Vue.set(this, 'activePoll', { token, id: pollId, name }) }, @@ -122,8 +135,8 @@ export const usePollsStore = defineStore('polls', { } }, - addPollToast({ token, message }) { - const pollId = message.messageParameters.object.id + addPollToast({ token, message }: { token: string, message: ChatMessage }) { + const pollId = +message.messageParameters.object.id const name = message.messageParameters.object.name const toast = showInfo(t('spreed', 'Poll "{name}" was created by {user}. Click to vote', { @@ -141,7 +154,7 @@ export const usePollsStore = defineStore('polls', { Vue.set(this.pollToastsQueue, pollId, toast) }, - hidePollToast(pollId) { + hidePollToast(pollId: number) { if (this.pollToastsQueue[pollId]) { this.pollToastsQueue[pollId].hideToast() Vue.delete(this.pollToastsQueue, pollId) @@ -150,7 +163,7 @@ export const usePollsStore = defineStore('polls', { hideAllPollToasts() { for (const pollId in this.pollToastsQueue) { - this.hidePollToast(pollId) + this.hidePollToast(+pollId) } }, },