Keyboard shorcuts working

This commit is contained in:
Belen Curcio
2017-06-19 17:48:20 -03:00
parent dad6534011
commit 12a5654fb8
2 changed files with 19 additions and 16 deletions
@@ -60,7 +60,7 @@ const Comment = ({
return (
<li
tabIndex={props.index}
className={`mdl-card ${selectionStateCSS} ${styles.Comment} ${styles.listItem} ${minimal ? styles.minimal : ''}`}
className={`mdl-card ${selectionStateCSS} ${selected ? styles.selected : ''} ${styles.Comment} ${styles.listItem} ${minimal ? styles.minimal : ''}`}
>
<div className={styles.container}>
<div className={styles.itemHeader}>
@@ -14,8 +14,13 @@ import StorySearch from '../containers/StorySearch';
import {Spinner} from 'coral-ui';
export default class Moderation extends Component {
state = {
selectedIndex: 0,
constructor() {
super();
this.state = {
selectedIndex: 0
};
}
componentWillMount() {
@@ -60,24 +65,22 @@ export default class Moderation extends Component {
getComments = () => {
const {root, route} = this.props;
const activeTab = route.path === ':id' ? 'premod' : route.path;
return root[activeTab];
return root[activeTab].nodes;
}
select = (next) => () => {
if (next) {
this.setState((prevState) =>
({
...prevState,
selectedIndex: prevState.selectedIndex < this.getComments().length - 1
? prevState.selectedIndex + 1 : prevState.selectedIndex
}));
this.setState((state) => ({
...state,
selectedIndex: state.selectedIndex < this.getComments().length - 1
? state.selectedIndex + 1 : state.selectedIndex
}));
} else {
this.setState((prevState) =>
({
...prevState,
selectedIndex: prevState.selectedIndex > 0 ?
prevState.selectedIndex - 1 : prevState.selectedIndex
}));
this.setState((state) => ({
...state,
selectedIndex: state.selectedIndex > 0
? state.selectedIndex - 1 : state.selectedIndex
}));
}
}