Skip to content
This repository was archived by the owner on Dec 28, 2023. It is now read-only.

Community track for the win! #11

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "none",
"tabWidth": 2,
"printWidth": 120,
"semi": true,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neither consistent with the existing style nor our usual style at Vend 😉

Copy link
Author

@rlopes rlopes Nov 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I know this is the case. Since I have all my nice tooling set up to automatically format code, I tweaked that file to follow the current style in that specific Medium repo. They use different rules from us.
I am very keen though to create a PR that makes the entire repo. follow standardjs and no semicolons.

"singleQuote": false
}
54 changes: 28 additions & 26 deletions components/KeyboardListener.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
// @flow

import React from 'react'
import React from "react";

type Props = {
increaseFocusedMilestoneFn: () => void,
selectNextTrackFn: () => void,
decreaseFocusedMilestoneFn: () => void,
selectPrevTrackFn: () => void
}
};

class KeyboardListener extends React.Component<Props> {
componentDidMount() {
window.addEventListener('keydown', (e) => this.handleKeyDown(e)) // TK unlisten
window.addEventListener("keydown", this.handleKeyDown);
}

componentWillUnmount() {
window.removeEventListener("keydown", this.handleKeyDown);
}

handleKeyDown(e: KeyboardEvent) {
if (document.activeElement && document.activeElement.tagName === 'INPUT') {
if (document.activeElement && document.activeElement.tagName === "INPUT") {
// Don't do shortcuts while input has focus.
return
return;
}
switch(e.code) {
case 'ArrowUp':
this.props.increaseFocusedMilestoneFn()
e.preventDefault()
break
case 'ArrowRight':
this.props.selectNextTrackFn()
e.preventDefault()
break
case 'ArrowDown':
this.props.decreaseFocusedMilestoneFn()
e.preventDefault()
break
case 'ArrowLeft':
this.props.selectPrevTrackFn()
e.preventDefault()
break
switch (e.code) {
case "ArrowUp":
this.props.increaseFocusedMilestoneFn();
e.preventDefault();
break;
case "ArrowRight":
this.props.selectNextTrackFn();
e.preventDefault();
break;
case "ArrowDown":
this.props.decreaseFocusedMilestoneFn();
e.preventDefault();
break;
case "ArrowLeft":
this.props.selectPrevTrackFn();
e.preventDefault();
break;
}
}

render() {
return null
return null;
}

}

export default KeyboardListener
export default KeyboardListener;
Loading