import * as React from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import classNames from 'classnames'; import './types'; import './FailBox.css'; import { screenSelector } from './selector'; import { setScreenModForView } from 'src/store/modules/app/actions'; import { RootStore } from 'src/store/types/store'; import { ImageInfo } from 'src/store/modules/tests/types'; import ImageDiffSwipe from './ImageDiffSwipe/ImageDiffSwipe'; import ImageDiffLoupe from './ImageDiffLoupe/ImageDiffLoupe'; import ImageDiffOnionSkin from './ImageDiffOnionSkin/ImageDiffOnionSkin'; import { withMeasurer } from 'src/components/modules/TestBox/withMeasurer'; class FailBox extends React.Component { public state = { valueSwipe: 0.5, valueOnionSkin: 0.5, valueLoupe: 2, }; public componentDidUpdate(prevProps): void { if (this.props.screenViewMode !== prevProps.screenViewMode) { this.props.measure(); } } private textModKeyItems = { '3-up': '3-up', onlyDiff: 'Only Diff', loupe: 'Loupe', swipe: 'Swipe', onionSkin: 'Onion Skin', }; private handleInputChange = (e) => { return this.setState({ valueSwipe: parseFloat(e.target.value) }); } private handleInputChangeOnion = (e) => { return this.setState({ valueOnionSkin: parseFloat(e.target.value) }); } private handleInputChangeLoupe = (e) => { this.setState({ valueLoupe: parseFloat(e.target.value) }); } private createHandleClickAtTab(key: string) { return () => { this.props.setScreenModForView(key, this.props.viewId); }; } public getBoxContent(): JSX.Element { const { expectedPath, actualPath, diffPath } = this.props; return ( <> {this.renderBoxItem('Expected', 'green', expectedPath)} {this.renderBoxItem('Actual', 'red', actualPath)} {this.renderBoxItem('Diff', 'gray', diffPath)} ); } public getBoxContentDiff(): JSX.Element { const { diffPath } = this.props; return <>{this.renderBoxItem('Diff', 'gray', diffPath)}; } public renderBoxItem(cn: string, color: string, imgPath: string): JSX.Element { return (

{cn}

{`${cn}-Img`}
); } public renderBoxContentLoupe(): JSX.Element { const { expectedPath, actualPath } = this.props; const { valueLoupe } = this.state; return (
); } public renderBoxContentSwipe(): JSX.Element { const { valueSwipe } = this.state; const { expectedPath, actualPath } = this.props; return (
); } public renderBoxContentOnionSkin(): JSX.Element { const { expectedPath, actualPath } = this.props; const { valueOnionSkin } = this.state; return (
); } public getView() { switch (this.props.screenViewMode) { case 'onlyDiff': return this.getBoxContentDiff(); case 'loupe': return this.renderBoxContentLoupe(); case 'swipe': return this.renderBoxContentSwipe(); case 'onionSkin': return this.renderBoxContentOnionSkin(); case '3-up': default: return this.getBoxContent(); } } public getTabModItem(): JSX.Element[] { return Object.keys(this.textModKeyItems).map((key) => { return this.renderTabItem(this.textModKeyItems[key], key); }); } public renderTabItem(item: string, key: string): JSX.Element { const { screenViewMode } = this.props; const cnLink = classNames('modNav-item-link', { 'selected': screenViewMode === key, }); return (
  • {item}
  • ); } public render(): JSX.Element { return ( <>
    {this.getView()}
    ); } } function mapStateToProps(store: RootStore, ownProps: ImageInfo) { return screenSelector(store, ownProps); } const mapDispatchToProps = (dispatch) => ({ ...bindActionCreators({ setScreenModForView }, dispatch), }); export default connect( mapStateToProps, mapDispatchToProps, )(withMeasurer(FailBox));