ref(polls) Convert files to TS (#12296)

This commit is contained in:
Robert Pintilii 2022-10-04 15:06:02 +03:00 committed by GitHub
parent 7d7bf987a1
commit c35d1d8d4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 28 deletions

View File

@ -1,5 +1,3 @@
// @flow
import { import {
CHANGE_VOTE, CHANGE_VOTE,
CLEAR_POLLS, CLEAR_POLLS,
@ -9,7 +7,7 @@ import {
RESET_NB_UNREAD_POLLS, RESET_NB_UNREAD_POLLS,
RETRACT_VOTE RETRACT_VOTE
} from './actionTypes'; } from './actionTypes';
import type { Answer, Poll } from './types'; import { Answer, Poll } from './types';
/** /**
* Action to signal that existing polls needs to be cleared from state. * Action to signal that existing polls needs to be cleared from state.

View File

@ -1,4 +1,4 @@
// @flow import { IState } from '../app/types';
/** /**
* Selector creator for determining if poll results should be displayed or not. * Selector creator for determining if poll results should be displayed or not.
@ -7,7 +7,7 @@
* @returns {Function} * @returns {Function}
*/ */
export function shouldShowResults(id: string) { export function shouldShowResults(id: string) {
return function(state: Object) { return function(state: IState) {
return Boolean(state['features/polls']?.polls[id].showResults); return Boolean(state['features/polls']?.polls[id].showResults);
}; };
} }
@ -19,7 +19,7 @@ export function shouldShowResults(id: string) {
* @returns {Function} * @returns {Function}
*/ */
export function getPoll(pollId: string) { export function getPoll(pollId: string) {
return function(state: Object) { return function(state: IState) {
return state['features/polls'].polls[pollId]; return state['features/polls'].polls[pollId];
}; };
} }
@ -27,10 +27,10 @@ export function getPoll(pollId: string) {
/** /**
* Selector for calculating the number of unread poll messages. * Selector for calculating the number of unread poll messages.
* *
* @param {Object} state - The redux state. * @param {IState} state - The redux state.
* @returns {number} The number of unread messages. * @returns {number} The number of unread messages.
*/ */
export function getUnreadPollCount(state: Object) { export function getUnreadPollCount(state: IState) {
const { nbUnreadPolls } = state['features/polls']; const { nbUnreadPolls } = state['features/polls'];
return nbUnreadPolls; return nbUnreadPolls;

View File

@ -1,16 +1,13 @@
// @flow import { IStore } from '../app/types';
import { getCurrentConference } from '../base/conference';
import { CONFERENCE_JOIN_IN_PROGRESS } from '../base/conference/actionTypes'; import { CONFERENCE_JOIN_IN_PROGRESS } from '../base/conference/actionTypes';
import { getCurrentConference } from '../base/conference/functions';
import { JitsiConferenceEvents } from '../base/lib-jitsi-meet'; import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux'; import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
import { playSound } from '../base/sounds'; import StateListenerRegistry from '../base/redux/StateListenerRegistry';
import { playSound } from '../base/sounds/actions';
import { INCOMING_MSG_SOUND_ID } from '../chat/constants'; import { INCOMING_MSG_SOUND_ID } from '../chat/constants';
import { import { showNotification } from '../notifications/actions';
NOTIFICATION_TIMEOUT_TYPE, import { NOTIFICATION_TIMEOUT_TYPE, NOTIFICATION_TYPE } from '../notifications/constants';
NOTIFICATION_TYPE,
showNotification
} from '../notifications';
import { RECEIVE_POLL } from './actionTypes'; import { RECEIVE_POLL } from './actionTypes';
import { clearPolls, receiveAnswer, receivePoll } from './actions'; import { clearPolls, receiveAnswer, receivePoll } from './actions';
@ -19,7 +16,7 @@ import {
COMMAND_NEW_POLL, COMMAND_NEW_POLL,
COMMAND_OLD_POLLS COMMAND_OLD_POLLS
} from './constants'; } from './constants';
import type { Answer, Poll } from './types'; import { Answer, Poll, PollData } from './types';
/** /**
* Set up state change listener to perform maintenance tasks when the conference * Set up state change listener to perform maintenance tasks when the conference
@ -36,7 +33,7 @@ StateListenerRegistry.register(
} }
}); });
const parsePollData = (pollData): Poll | null => { const parsePollData = (pollData: PollData): Poll | null => {
if (typeof pollData !== 'object' || pollData === null) { if (typeof pollData !== 'object' || pollData === null) {
return null; return null;
} }
@ -84,9 +81,9 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
const { conference } = action; const { conference } = action;
conference.on(JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, conference.on(JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
(_, data) => _handleReceivePollsMessage(data, dispatch)); (_: any, data: any) => _handleReceivePollsMessage(data, dispatch));
conference.on(JitsiConferenceEvents.NON_PARTICIPANT_MESSAGE_RECEIVED, conference.on(JitsiConferenceEvents.NON_PARTICIPANT_MESSAGE_RECEIVED,
(_, data) => _handleReceivePollsMessage(data, dispatch)); (_: any, data: any) => _handleReceivePollsMessage(data, dispatch));
break; break;
} }
@ -118,7 +115,7 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
* *
* @returns {void} * @returns {void}
*/ */
function _handleReceivePollsMessage(data, dispatch) { function _handleReceivePollsMessage(data: any, dispatch: IStore['dispatch']) {
switch (data.type) { switch (data.type) {
case COMMAND_NEW_POLL: { case COMMAND_NEW_POLL: {
const { question, answers, pollId, senderId, senderName } = data; const { question, answers, pollId, senderId, senderName } = data;
@ -130,7 +127,7 @@ function _handleReceivePollsMessage(data, dispatch) {
showResults: false, showResults: false,
lastVote: null, lastVote: null,
question, question,
answers: answers.map(answer => { answers: answers.map((answer: Answer) => {
return { return {
name: answer, name: answer,
voters: new Map() voters: new Map()

View File

@ -1,4 +1,4 @@
export type Answer = { export interface Answer {
/** /**
* An array of boolean: true if the answer was chosen by the responder, else false. * An array of boolean: true if the answer was chosen by the responder, else false.
@ -19,9 +19,9 @@ export type Answer = {
* Name of the voter. * Name of the voter.
*/ */
voterName: string; voterName: string;
}; }
export type Poll = { export interface Poll {
/** /**
* An array of answers: * An array of answers:
@ -60,4 +60,8 @@ export type Poll = {
* Whether the results should be shown instead of the answer form. * Whether the results should be shown instead of the answer form.
*/ */
showResults: boolean; showResults: boolean;
}; }
export interface PollData extends Poll {
id: string;
}