2021-07-13 06:50:08 +00:00
|
|
|
import React, { Component } from 'react';
|
2022-07-27 09:56:07 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2022-07-11 12:30:37 +00:00
|
|
|
import { IStore } from '../../../app/types';
|
2021-07-13 06:50:08 +00:00
|
|
|
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.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
index: number;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
2022-07-20 08:47:01 +00:00
|
|
|
* Reaction to be displayed.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
reaction: string;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes reaction from redux state.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
reactionRemove: Function;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
2022-07-20 08:47:01 +00:00
|
|
|
* Id of the reaction.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
uid: string;
|
2021-07-13 06:50:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Index of CSS animation. Number between 0-20.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
index: number;
|
|
|
|
};
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
2022-06-08 07:44:47 +00:00
|
|
|
setTimeout(() => this.props.reactionRemove(this.props.uid), 5000);
|
2021-07-13 06:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 12:30:37 +00:00
|
|
|
const mapDispatchToProps = (dispatch: IStore['dispatch']) => {
|
|
|
|
return {
|
|
|
|
reactionRemove: (uid: string) => dispatch(removeReaction(uid))
|
|
|
|
};
|
|
|
|
};
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2022-07-11 12:30:37 +00:00
|
|
|
export default connect(undefined, mapDispatchToProps)(ReactionEmoji);
|