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" /> <Icon icon="icon-trash-4" />
</button> </button>
<button
className={classnames('disabled', { active: mode === MODES.SHOTTER })}
onClick={this.props.takeAShot}
// onClick={getTilePlacement}
>
<Icon icon="icon-shot-3" />
</button>
<button <button
className={classnames('disabled', { active: mode === MODES.LOGO })} className={classnames('disabled', { active: mode === MODES.LOGO })}
> >
@ -147,20 +139,6 @@ class Component extends React.PureComponent<Props, void> {
</div> </div>
<div className={classnames('panel right', { active: !editing })}> <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"> <div className="control-bar">
<button className="primary single" onClick={this.props.startEditing}> <button className="primary single" onClick={this.props.startEditing}>
<Icon icon="icon-route-2" /> <Icon icon="icon-route-2" />

View file

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

View file

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

View file

@ -264,10 +264,13 @@ function* getCropData({
canvas.height = height; canvas.height = height;
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
const image = yield imageFetcher(data); const image = yield imageFetcher(data);
const logoImage = yield imageFetcher(LOGOS[logo][1]);
ctx.drawImage(image, -x, -y); ctx.drawImage(image, -x, -y);
ctx.drawImage(logoImage, width - logoImage.width, height - logoImage.height);
if (logo && LOGOS[logo][1]) {
const logoImage = yield imageFetcher(LOGOS[logo][1]);
ctx.drawImage(logoImage, width - logoImage.width, height - logoImage.height);
}
return yield canvas.toDataURL('image/jpeg'); return yield canvas.toDataURL('image/jpeg');
} }

View file

@ -79,6 +79,7 @@
font-size: 14px; font-size: 14px;
font-weight: 500; font-weight: 500;
margin-left: 8px; margin-left: 8px;
text-transform: uppercase;
} }
&:first-child { &:first-child {

View file

@ -17,6 +17,7 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
position: relative; position: relative;
transition: opacity 250ms;
} }
img#rendererOutput { img#rendererOutput {