Skip to content

Commit bc4a430

Browse files
committed
9-1
1 parent b759eee commit bc4a430

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

chapter9/src/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import './index.css';
44
import App from './App';
5-
import { rateColor, removeColor } from './actions';
6-
import {sortFunction} from 'lib/array-helpers';
75
import * as serviceWorker from './serviceWorker';
86

97
const colors = {

chapter9/src/lib/array-helpers.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import PropTypes from 'prop-types'
2+
import '../../../stylesheets/Menu.scss'
3+
4+
const options = {
5+
date: "SORTED_BY_DATE",
6+
title: "SORTED_BY_TITLE",
7+
rating: "SORTED_BY_RATING"
8+
}
9+
10+
const SortMenu = ({ sort="SORTED_BY_DATE", onSelect=f=>f}) =>
11+
<nav className="menu">
12+
<h1>Sort Colors</h1>
13+
{Object.keys(options).map((item, i) =>
14+
<a key={i}
15+
href="#"
16+
className={(sort === options[item]) ? "selected" : null}
17+
onClick={e => {
18+
e.preventDefault()
19+
onSelect(options[item])
20+
}}>{item}</a>
21+
)}
22+
</nav>
23+
24+
SortMenu.propTypes = {
25+
sort: PropTypes.string,
26+
onSelect: PropTypes.func
27+
}
28+
29+
export default SortMenu

0 commit comments

Comments
 (0)