cropper: fixed empty logo case

This commit is contained in:
muerwre 2018-11-28 18:13:01 +07:00
parent 34d1b85513
commit 6f21b909c0
6 changed files with 23 additions and 51 deletions

View file

@ -103,14 +103,6 @@ class Component extends React.PureComponent<Props, void> {
<Icon icon="icon-trash-4" />
</button>
<button
className={classnames('disabled', { active: mode === MODES.SHOTTER })}
onClick={this.props.takeAShot}
// onClick={getTilePlacement}
>
<Icon icon="icon-shot-3" />
</button>
<button
className={classnames('disabled', { active: mode === MODES.LOGO })}
>
@ -147,20 +139,6 @@ class Component extends React.PureComponent<Props, void> {
</div>
<div className={classnames('panel right', { active: !editing })}>
<div className="control-bar">
<button
className={classnames('disabled', { active: mode === MODES.SHOTTER })}
onClick={this.startShotterMode}
>
<Icon icon="icon-shot-3" />
<span>
СНИМОК
</span>
</button>
</div>
<div className="control-sep" />
<div className="control-bar">
<button className="primary single" onClick={this.props.startEditing}>
<Icon icon="icon-route-2" />

View file

@ -5,18 +5,17 @@ import { SERVER } from '$constants/api';
import { DEFAULT_USER, ROLES } from '$constants/auth';
import { UserButton } from '$components/user/UserButton';
import { UserMenu } from '$components/user/UserMenu';
import { setUser, userLogout } from '$redux/user/actions';
import { setUser, userLogout, takeAShot } from '$redux/user/actions';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import type { UserType } from '$constants/types';
import { MODES } from '$constants/modes';
import classnames from 'classnames';
import { Icon } from '$components/panels/Icon';
type Props = {
user: UserType,
userLogout: Function,
setUser: Function,
takeAShot: Function,
};
export class Component extends React.PureComponent<Props, void> {
@ -92,9 +91,7 @@ export class Component extends React.PureComponent<Props, void> {
<div className="control-bar">
<button
className="disabled"
// className={classnames({ active: mode === MODES.SHOTTER })}
// onClick={this.startShotterMode}
onClick={this.props.takeAShot}
>
<Icon icon="icon-shot-3" />
</button>
@ -107,6 +104,6 @@ export class Component extends React.PureComponent<Props, void> {
const mapStateToProps = ({ user: { user } }) => ({ user });
const mapDispatchToProps = dispatch => bindActionCreators({ setUser, userLogout }, dispatch);
const mapDispatchToProps = dispatch => bindActionCreators({ setUser, userLogout, takeAShot }, dispatch);
export const UserPanel = connect(mapStateToProps, mapDispatchToProps)(Component);

View file

@ -16,15 +16,20 @@ type Props = {
};
type State = {
opacity: Number,
};
class Component extends React.Component<Props, State> {
state = {
opacity: 0,
};
onImageLoaded = () => {
this.croppr = new Croppr(this.image, {
onCropMove: this.moveLogo,
onInitialize: this.onCropInit,
});
this.setState({ opacity: 1 });
};
componentWillUnmount() {
@ -32,13 +37,9 @@ class Component extends React.Component<Props, State> {
}
onCropInit = (crop) => {
const { regionEl, box } = crop;
const scale = ((box.x2 - box.x1) / window.innerWidth);
console.log('CROP', crop, scale);
this.logo = document.createElement('div');
this.logo.className = 'renderer-logo';
this.logo.style.transform = `scale(${scale})`;
@ -50,20 +51,13 @@ class Component extends React.Component<Props, State> {
regionEl.append(this.logo);
};
moveLogo = ({ x, y, width, height }) => {
if (!this.logo) return;
this.logo.style.color = 'blue';
};
croppr;
getImage = () => {
this.props.cropAShot(this.croppr.getValue());
};
getImage = () => this.props.cropAShot(this.croppr.getValue());
render() {
const { data } = this.props;
const { opacity } = this.state;
const { innerWidth, innerHeight } = window;
const padding = 30;
const paddingBottom = 80;
@ -80,13 +74,10 @@ class Component extends React.Component<Props, State> {
<div>
<div
className="renderer-shade"
style={{
padding,
paddingBottom,
}}
style={{ padding, paddingBottom }}
>
<div
style={{ width, height }}
style={{ width, height, opacity }}
>
<img
src={data}
@ -121,6 +112,7 @@ class Component extends React.Component<Props, State> {
onClick={this.props.hideRenderer}
>
<Icon icon="icon-cancel-1" />
<span>Отмена</span>
</button>
<button