All files / components ChosenGif.js

100% Statements 8/8
50% Branches 1/2
100% Functions 4/4
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                        4x   4x                               1x     1x   1x 1x                
// @flow
import * as React from 'react';
import { connect } from 'react-redux';
import { setChosen } from '../actions/resultActions';
 
type Props = {
  url: string,
  clearChosen: any,
};
 
export class ChosenGif extends React.Component<Props> {
  render() {
    const { url, clearChosen } = this.props;
 
    return (
      <>
        {url !== '' ? (
          <div className="gifpicker__chosengif">
            <img src={url} alt="Chosen tenor gif" />
            <button type="button" onClick={clearChosen}></button>
            <input type="hidden" name="tenorgif" value={url} />
          </div>
        ) : (
          <></>
        )}
      </>
    );
  }
}
 
export const mapStateToProps = state => ({
  url: state.result.chosen,
});
export const mapDispatchToProps = dispatch => ({
  clearChosen: e => {
    e.preventDefault();
    dispatch(setChosen(''));
  },
});
 
export default connect<*, *, *, *, *, *>(
  mapStateToProps,
  mapDispatchToProps
)(ChosenGif);