Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ReactionEmoji.tsx 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { IStore } from '../../../app/types';
  4. import { removeReaction } from '../../actions.any';
  5. import { REACTIONS } from '../../constants';
  6. interface IProps {
  7. /**
  8. * Index of the reaction in the queue.
  9. */
  10. index: number;
  11. /**
  12. * Reaction to be displayed.
  13. */
  14. reaction: string;
  15. /**
  16. * Removes reaction from redux state.
  17. */
  18. reactionRemove: Function;
  19. /**
  20. * Id of the reaction.
  21. */
  22. uid: string;
  23. }
  24. interface IState {
  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<IProps, IState> {
  36. /**
  37. * Initializes a new {@code ReactionEmoji} instance.
  38. *
  39. * @param {IProps} props - The read-only React {@code Component} props with
  40. * which the new instance is to be initialized.
  41. */
  42. constructor(props: IProps) {
  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.reactionRemove(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 = (dispatch: IStore['dispatch']) => {
  74. return {
  75. reactionRemove: (uid: string) => dispatch(removeReaction(uid))
  76. };
  77. };
  78. export default connect(undefined, mapDispatchToProps)(ReactionEmoji);