jiti-meet/react/features/reactions/components/web/ReactionEmoji.tsx

99 lines
2.0 KiB
TypeScript
Raw Normal View History

/* eslint-disable import/order */
import React, { Component } from 'react';
// @ts-ignore
import { IStore } from '../../../app/types';
// @ts-ignore
import { connect } from '../../../base/redux';
import { removeReaction } from '../../actions.any';
import { REACTIONS } from '../../constants';
type Props = {
/**
2022-07-20 08:47:01 +00:00
* Index of the reaction in the queue.
*/
2022-07-20 08:47:01 +00:00
index: number,
/**
2022-07-20 08:47:01 +00:00
* Reaction to be displayed.
*/
2022-07-20 08:47:01 +00:00
reaction: string,
/**
* Removes reaction from redux state.
*/
reactionRemove: Function,
/**
2022-07-20 08:47:01 +00:00
* Id of the reaction.
*/
2022-07-20 08:47:01 +00:00
uid: string
};
type State = {
/**
* Index of CSS animation. Number between 0-20.
*/
index: number
}
/**
* Used to display animated reactions.
*
* @returns {ReactElement}
*/
class ReactionEmoji extends Component<Props, State> {
/**
* Initializes a new {@code ReactionEmoji} instance.
*
* @param {Props} props - The read-only React {@code Component} props with
* which the new instance is to be initialized.
*/
constructor(props: Props) {
super(props);
this.state = {
index: props.index % 21
};
}
/**
* Implements React Component's componentDidMount.
*
* @inheritdoc
*/
componentDidMount() {
setTimeout(() => this.props.reactionRemove(this.props.uid), 5000);
}
/**
* Implements React's {@link Component#render}.
*
* @inheritdoc
*/
render() {
const { reaction, uid } = this.props;
const { index } = this.state;
return (
<div
className = { `reaction-emoji reaction-${index}` }
id = { uid }>
{ REACTIONS[reaction].emoji }
</div>
);
}
}
const mapDispatchToProps = (dispatch: IStore['dispatch']) => {
return {
reactionRemove: (uid: string) => dispatch(removeReaction(uid))
};
};
export default connect(undefined, mapDispatchToProps)(ReactionEmoji);