|
1 | 1 | import React from 'react'; |
2 | | -import { Link } from 'react-router-dom'; |
| 2 | +import { connect } from 'react-redux'; |
3 | 3 |
|
4 | 4 | import Title from './common/Title'; |
| 5 | +import RecentSnippetItem from './RecentSnippetItem'; |
| 6 | +import * as actions from '../actions'; |
5 | 7 |
|
6 | 8 | import '../styles/RecentSnippets.styl'; |
7 | 9 |
|
8 | | -const RecentSnippets = () => ( |
9 | | - [ |
10 | | - <Title title="Recent snippets" additionalClass="recent-title" key="title-recent" />, |
11 | | - <ul className="recent-snippet" key="recent-snippet"> |
12 | | - <li className="recent-snippet-item"> |
13 | | - <div className="recent-snippet-data"> |
14 | | - <div> |
15 | | - <span className="recent-snippet-data-title">#235435, Untitled</span> |
16 | | - <span className="recent-snippet-data-lang">[ Java ]</span> |
17 | | - </div> |
18 | | - <span className="recent-snippet-data-author">By Guest</span> |
19 | | - </div> |
20 | | - <div> |
21 | | - <button className="recent-snippet-button light">Raw</button> |
22 | | - <button className="recent-snippet-button light">Download</button> |
23 | | - <Link to="/2" className="recent-snippet-button">Show</Link> |
24 | | - </div> |
25 | | - </li> |
26 | | - <li className="recent-snippet-item"> |
27 | | - <div className="recent-snippet-data"> |
28 | | - <div> |
29 | | - <span className="recent-snippet-data-title">#235435, Untitled</span> |
30 | | - <span className="recent-snippet-data-lang">[ Java ]</span> |
31 | | - </div> |
32 | | - <span className="recent-snippet-data-author">By Guest</span> |
33 | | - </div> |
34 | | - <div> |
35 | | - <button className="recent-snippet-button light">Raw</button> |
36 | | - <button className="recent-snippet-button light">Download</button> |
37 | | - <Link to="/3" className="recent-snippet-button">Show</Link> |
38 | | - </div> |
39 | | - </li> |
40 | | - </ul>, |
41 | | - ] |
42 | | -); |
| 10 | +class RecentSnippets extends React.Component { |
| 11 | + componentDidMount() { |
| 12 | + const { dispatch } = this.props; |
| 13 | + dispatch(actions.fetchRecentSnippets); |
| 14 | + } |
43 | 15 |
|
44 | | -export default RecentSnippets; |
| 16 | + render() { |
| 17 | + const { snippets, recent } = this.props; |
| 18 | + |
| 19 | + return ([ |
| 20 | + <Title title="Recent snippets" additionalClass="recent-title" key="title-recent" />, |
| 21 | + <ul className="recent-snippet" key="recent-snippet"> |
| 22 | + {recent.map(id => <RecentSnippetItem key={id} snippet={snippets.get(id)} />)} |
| 23 | + </ul>, |
| 24 | + ]); |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +export default connect(state => ({ |
| 29 | + snippets: state.snippets, |
| 30 | + recent: state.recent, |
| 31 | +}))(RecentSnippets); |
0 commit comments