You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ReactionEmoji.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from '../../../base/redux';
  4. import { removeReaction } from '../../actions.any';
  5. import { REACTIONS } from '../../constants';
  6. type Props = {
  7. /**
  8. * Reaction to be displayed.
  9. */
  10. reaction: string,
  11. /**
  12. * Id of the reaction.
  13. */
  14. uid: Number,
  15. /**
  16. * Removes reaction from redux state.
  17. */
  18. removeReaction: Function,
  19. /**
  20. * Index of the reaction in the queue.
  21. */
  22. index: number
  23. };
  24. type State = {
  25. /**
  26. * Index of CSS animation. Number between 0-20.
  27. */
  28. index: number
  29. }
  30. /**
  31. * Used to display animated reactions.
  32. *
  33. * @returns {ReactElement}
  34. */
  35. class ReactionEmoji extends Component<Props, State> {
  36. /**
  37. * Initializes a new {@code ReactionEmoji} instance.
  38. *
  39. * @param {Props} props - The read-only React {@code Component} props with
  40. * which the new instance is to be initialized.
  41. */
  42. constructor(props: Props) {
  43. super(props);
  44. this.state = {
  45. index: props.index % 21
  46. };
  47. }
  48. /**
  49. * Implements React Component's componentDidMount.
  50. *
  51. * @inheritdoc
  52. */
  53. componentDidMount() {
  54. setTimeout(() => this.props.removeReaction(this.props.uid), 5000);
  55. }
  56. /**
  57. * Implements React's {@link Component#render}.
  58. *
  59. * @inheritdoc
  60. */
  61. render() {
  62. const { reaction, uid } = this.props;
  63. const { index } = this.state;
  64. return (
  65. <div
  66. className = { `reaction-emoji reaction-${index}` }
  67. id = { uid }>
  68. { REACTIONS[reaction].emoji }
  69. </div>
  70. );
  71. }
  72. }
  73. const mapDispatchToProps = {
  74. removeReaction
  75. };
  76. export default connect(
  77. null,
  78. mapDispatchToProps,
  79. )(ReactionEmoji);