editor: hotkeys added

This commit is contained in:
muerwre 2018-12-10 11:29:26 +07:00
parent d95f51bd3b
commit 25ae7f8282
9 changed files with 48 additions and 17 deletions

View file

@ -9,7 +9,7 @@ import { EditorDialog } from '$components/panels/EditorDialog';
import { LogoPreview } from '$components/logo/LogoPreview'; import { LogoPreview } from '$components/logo/LogoPreview';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { setMode, startEditing, stopEditing, setLogo, takeAShot } from '$redux/user/actions'; import { setMode, startEditing, stopEditing, setLogo, takeAShot, keyPressed } from '$redux/user/actions';
import { UserLocation } from '$components/UserLocation'; import { UserLocation } from '$components/UserLocation';
import { PROVIDERS } from '$constants/providers'; import { PROVIDERS } from '$constants/providers';
@ -28,10 +28,13 @@ type Props = {
startEditing: Function, startEditing: Function,
stopEditing: Function, stopEditing: Function,
takeAShot: Function, takeAShot: Function,
keyPressed: Function,
} }
class Component extends React.PureComponent<Props, void> { class Component extends React.PureComponent<Props, void> {
componentDidMount() { componentDidMount() {
window.addEventListener('keydown', this.props.keyPressed);
const obj = document.getElementById('control-dialog'); const obj = document.getElementById('control-dialog');
const { width } = this.panel.getBoundingClientRect(); const { width } = this.panel.getBoundingClientRect();
@ -40,6 +43,10 @@ class Component extends React.PureComponent<Props, void> {
obj.style.width = width; obj.style.width = width;
} }
componentWillUnmount() {
window.removeEventListener('keydown', this.props.keyPressed);
}
startPolyMode = () => this.props.setMode(MODES.POLY); startPolyMode = () => this.props.setMode(MODES.POLY);
startStickerMode = () => this.props.setMode(MODES.STICKERS); startStickerMode = () => this.props.setMode(MODES.STICKERS);
startRouterMode = () => this.props.setMode(MODES.ROUTER); startRouterMode = () => this.props.setMode(MODES.ROUTER);
@ -123,7 +130,7 @@ class Component extends React.PureComponent<Props, void> {
className={classnames({ active: false })} className={classnames({ active: false })}
onClick={this.props.takeAShot} onClick={this.props.takeAShot}
> >
<Icon icon="icon-shot-2" /> <Icon icon="icon-shot-4" />
</button> </button>
</div> </div>
@ -208,6 +215,7 @@ const mapDispatchToProps = dispatch => bindActionCreators({
startEditing, startEditing,
stopEditing, stopEditing,
takeAShot, takeAShot,
keyPressed,
}, dispatch); }, dispatch);
export const EditorPanel = connect( export const EditorPanel = connect(

View file

@ -34,7 +34,7 @@ class Component extends React.Component<Props, State> {
}; };
componentWillUnmount() { componentWillUnmount() {
this.croppr.destroy(); if (this.croppr) this.croppr.destroy();
} }
onCropInit = (crop) => { onCropInit = (crop) => {

View file

@ -4,11 +4,10 @@
<meta name="viewport" content="initial-scale=1, maximum-scale=0.8"> <meta name="viewport" content="initial-scale=1, maximum-scale=0.8">
<meta name="theme-color" content="#5A3D6D"> <meta name="theme-color" content="#5A3D6D">
<link rel="icon" href="favicon.png?d" type="image/png" />
<link href="https://fonts.googleapis.com/css?family=Rubik:300,400,500,700&amp;subset=cyrillic" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Rubik:300,400,500,700&amp;subset=cyrillic" rel="stylesheet">
<title>@ORCHID</title> <title>@ORCHID</title>
<link rel="shortcut icon" href="/favicon.png?wd" type="image/png"> <link rel="shortcut icon" href="/favicon.png" type="image/png">
<meta property="og:image" content="/misc/vk_preview.png" /> <meta property="og:image" content="/misc/vk_preview.png" />
<meta content="/misc/vk_preview.png"> <meta content="/misc/vk_preview.png">
<style> <style>

View file

@ -328,13 +328,6 @@ export class Editor {
provider: this.provider, provider: this.provider,
}); });
// setProvider = provider => {
// if (provider === this.provider) return;
//
// this.provider = provider;
// this.map.setProvider(provider);
// };
setProvider = provider => store.dispatch(setProvider(provider)); setProvider = provider => store.dispatch(setProvider(provider));
get isEmpty() { get isEmpty() {

View file

@ -47,3 +47,4 @@ export const locationChanged = location => ({ type: ACTIONS.LOCATION_CHANGED, lo
export const setReady = ready => ({ type: ACTIONS.SET_READY, ready }); export const setReady = ready => ({ type: ACTIONS.SET_READY, ready });
export const gotVkUser = user => ({ type: ACTIONS.GOT_VK_USER, user }); export const gotVkUser = user => ({ type: ACTIONS.GOT_VK_USER, user });
export const keyPressed = ({ key }) => ({ type: ACTIONS.KEY_PRESSED, key });

View file

@ -47,4 +47,5 @@ export const ACTIONS = ({
SET_READY: 'SET_READY', SET_READY: 'SET_READY',
GOT_VK_USER: 'GOT_VK_USER', GOT_VK_USER: 'GOT_VK_USER',
KEY_PRESSED: 'KEY_PRESSED',
}: { [key: String]: String }); }: { [key: String]: String });

View file

@ -5,7 +5,7 @@ import { checkUserToken, getGuestToken, getStoredMap, postMap } from '$utils/api
import { import {
hideRenderer, hideRenderer,
setActiveSticker, setAddress, setActiveSticker, setAddress,
setChanged, setChanged, setDialogActive,
setEditing, setEditing,
setMode, setReady, setRenderer, setMode, setReady, setRenderer,
setSaveError, setSaveError,
@ -297,7 +297,12 @@ function* getRenderData() {
} }
function* takeAShotSaga() { function* takeAShotSaga() {
const data = yield call(getRenderData); const { data, cancel } = yield race({
data: call(getRenderData),
cancel: take(ACTIONS.HIDE_RENDERER),
});
if (cancel || !data) return;
yield put(setRenderer({ yield put(setRenderer({
data, renderer_active: true, width: window.innerWidth, height: window.innerHeight data, renderer_active: true, width: window.innerWidth, height: window.innerHeight
@ -377,6 +382,18 @@ function* gotVkUserSaga({ user }) {
yield put(setUser(data)); yield put(setUser(data));
} }
function* keyPressedSaga({ key }): void {
if (key === 'Escape') {
const { dialog_active, mode, renderer: { renderer_active } } = yield select(getState);
if (renderer_active) return yield put(hideRenderer());
if (dialog_active) return yield put(setDialogActive(false));
if (mode !== MODES.NONE) return yield put(setMode(MODES.NONE));
}
return;
}
export function* userSaga() { export function* userSaga() {
yield takeLatest(REHYDRATE, authCheckSaga); yield takeLatest(REHYDRATE, authCheckSaga);
yield takeEvery(ACTIONS.SET_MODE, setModeSaga); yield takeEvery(ACTIONS.SET_MODE, setModeSaga);
@ -406,4 +423,5 @@ export function* userSaga() {
yield takeLatest(ACTIONS.LOCATION_CHANGED, locationChangeSaga); yield takeLatest(ACTIONS.LOCATION_CHANGED, locationChangeSaga);
yield takeLatest(ACTIONS.GOT_VK_USER, gotVkUserSaga); yield takeLatest(ACTIONS.GOT_VK_USER, gotVkUserSaga);
yield takeLatest(ACTIONS.KEY_PRESSED, keyPressedSaga);
} }

View file

@ -333,8 +333,18 @@
<path stroke="none" fill="black"/> <path stroke="none" fill="black"/>
<path xmlns="http://www.w3.org/2000/svg" d="M17 7h-4v2h4c1.65 0 3 1.35 3 3s-1.35 3-3 3h-4v2h4c2.76 0 5-2.24 5-5s-2.24-5-5-5zm-6 8H7c-1.65 0-3-1.35-3-3s1.35-3 3-3h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-2zm-3-4h8v2H8z" fill="white" stroke="white" stroke-width="0" transform="translate(4 4)"/> <path xmlns="http://www.w3.org/2000/svg" d="M17 7h-4v2h4c1.65 0 3 1.35 3 3s-1.35 3-3 3h-4v2h4c2.76 0 5-2.24 5-5s-2.24-5-5-5zm-6 8H7c-1.65 0-3-1.35-3-3s1.35-3 3-3h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-2zm-3-4h8v2H8z" fill="white" stroke="white" stroke-width="0" transform="translate(4 4)"/>
</g> </g>
<g id="icon-shot-4" stroke="none">
<path stroke="none" fill="black"/>
<path d="M14.12 4l1.83 2H20v12H4V6h4.05l1.83-2h4.24M15 2H9L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2zm-3 7c1.65 0 3 1.35 3 3s-1.35 3-3 3-3-1.35-3-3 1.35-3 3-3m0-2c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5z" fill="white" stroke="white" stroke-width="0" transform="translate(4 4)"/>
</g>
<g id="icon-trash-5" stroke="none">
<path stroke="none" fill="black"/>
<path d="M14.12 10.47L12 12.59l-2.13-2.12-1.41 1.41L10.59 14l-2.12 2.12 1.41 1.41L12 15.41l2.12 2.12 1.41-1.41L13.41 14l2.12-2.12zM15.5 4l-1-1h-5l-1 1H5v2h14V4zM6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM8 9h8v10H8V9z" fill="white" stroke="none" stroke-width="0" transform="translate(4 4)"/>
</g>
</svg> </svg>
</defs> </defs>
<use xlink:href="#icon-folder-1" /> <use xlink:href="#icon-trash-5" />
</svg> </svg>

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Before After
Before After

View file

@ -2,7 +2,6 @@ import { history } from '$redux/store';
export const getPath = () => (window.location && window.location.pathname); export const getPath = () => (window.location && window.location.pathname);
export const pushPath = url => { export const pushPath = url => {
console.log('PUSHING', url);
return history.push(url); return history.push(url);
}; };
@ -10,5 +9,7 @@ export const getUrlData = (url = getPath()) => {
const [, path, mode] = url.split('/'); const [, path, mode] = url.split('/');
const { host, hash } = window.location; const { host, hash } = window.location;
return { path, mode, host, hash }; return {
path, mode, host, hash
};
}; };