updated format and lint scripts and applied them

This commit is contained in:
JJ Kasper
2018-06-01 16:52:12 -05:00
parent 53ac8a6793
commit 017a9993ee
58 changed files with 1711 additions and 1568 deletions

View File

@@ -1,8 +1,8 @@
import { Component } from 'react';
import Router from 'next/router';
import getUrl from '../util/getUrl';
import { getKey } from '../util/keys';
import { doLogout } from '../redux/actions/userAct';
import { Component } from 'react'
import Router from 'next/router'
import getUrl from '../util/getUrl'
import { getKey } from '../util/keys'
import { doLogout } from '../redux/actions/userAct'
/* - keyboard shortcuts
g then h -> navigate home
@@ -16,53 +16,56 @@ import { doLogout } from '../redux/actions/userAct';
const keyToUrl = {
72: '/',
78: '/new',
83: '/settings'
};
83: '/settings',
}
const keyToEl = {
69: { sel: '#edit', func: 'click' },
191: { sel: '.search', func: 'focus' }
};
69: { sel: '#edit', func: 'click' },
191: { sel: '.search', func: 'focus' },
}
class KeyShortcuts extends Component {
handleDown = e => {
const tag = e.target.tagName;
if(tag === 'INPUT' || tag === 'TEXTAREA') return;
const key = getKey(e);
if(this.prevKey === 71) { // prev key was g
const tag = e.target.tagName
if (tag === 'INPUT' || tag === 'TEXTAREA') return
const key = getKey(e)
if (this.prevKey === 71) {
// prev key was g
switch (key) {
case 72:
case 78:
case 83: {
const url = keyToUrl[key];
Router.push(url, getUrl(url));
break;
}
case 76: {
setTimeout(doLogout, 1);
break;
}
default: break;
case 72:
case 78:
case 83: {
const url = keyToUrl[key]
Router.push(url, getUrl(url))
break
}
case 76: {
setTimeout(doLogout, 1)
break
}
default:
break
}
}
switch (key) {
case 69:
case 191: {
const { sel, func } = keyToEl[key];
const el = document.querySelector(sel);
if(el) setTimeout(() => el[func](), 1);
break;
case 69:
case 191: {
const { sel, func } = keyToEl[key]
const el = document.querySelector(sel)
if (el) setTimeout(() => el[func](), 1)
break
}
default:
break
}
default: break;
}
this.prevKey = key;
};
this.prevKey = key
}
componentDidMount() {
window.addEventListener('keydown', this.handleDown);
window.addEventListener('keydown', this.handleDown)
}
componentWillUnmount() {
window.removeEventListener('keydown', this.handleDown);
window.removeEventListener('keydown', this.handleDown)
}
render = () => null
}
export default KeyShortcuts;
export default KeyShortcuts