|
1 | | -import React, { Component } from 'react' |
| 1 | +import React from 'react' |
2 | 2 | import PropTypes from 'prop-types' |
3 | 3 | import { map } from 'lodash' |
4 | 4 | import { connect } from 'react-redux' |
| 5 | +import { compose } from 'redux' |
5 | 6 | import { firebaseConnect, isLoaded, isEmpty } from 'react-redux-firebase' |
6 | 7 | import TodoItem from './TodoItem' |
7 | 8 |
|
8 | | -const renderList = (list) => |
9 | | - !isLoaded(list) |
| 9 | +function renderList(list) { |
| 10 | + return !isLoaded(list) |
10 | 11 | ? 'Loading' |
11 | | - : (isEmpty(list)) |
| 12 | + : isEmpty(list) |
12 | 13 | ? 'Todo list is empty' |
13 | | - : map(list, (todo, id) => |
14 | | - <TodoItem key={id} id={id} todo={todo} /> |
15 | | - ) |
| 14 | + : map(list, (todo, id) => <TodoItem key={id} id={id} todo={todo} />) |
| 15 | +} |
16 | 16 |
|
17 | | -const MultipleQueries = ({ incompleteTodos, completeTodos }) => ( |
18 | | - <div> |
19 | | - <div> |
20 | | - <h2>react-redux-firebase multiple queries demo</h2> |
21 | | - </div> |
| 17 | +function Home({ incompleteTodos, completeTodos }) { |
| 18 | + return ( |
22 | 19 | <div> |
23 | | - <h4>Incomplete Todos</h4> |
24 | | - {renderList(incompleteTodos)} |
25 | | - <h4>Complete Todos</h4> |
26 | | - {renderList(completeTodos)} |
| 20 | + <div> |
| 21 | + <h2>react-redux-firebase multiple queries demo</h2> |
| 22 | + </div> |
| 23 | + <div> |
| 24 | + <h4>Incomplete Todos</h4> |
| 25 | + {renderList(incompleteTodos)} |
| 26 | + <h4>Complete Todos</h4> |
| 27 | + {renderList(completeTodos)} |
| 28 | + </div> |
27 | 29 | </div> |
28 | | - </div> |
29 | | -) |
| 30 | + ) |
| 31 | +} |
30 | 32 |
|
31 | | -MultipleQueries.propTypes = { |
32 | | - myProjects: PropTypes.object, |
33 | | - anonymousProjects: PropTypes.object |
| 33 | +Home.propTypes = { |
| 34 | + incompleteTodos: PropTypes.object, |
| 35 | + completeTodos: PropTypes.object |
34 | 36 | } |
35 | 37 |
|
36 | | -export default compose( |
| 38 | +const enhance = compose( |
37 | 39 | firebaseConnect([ |
38 | 40 | { |
39 | 41 | path: 'todos', |
40 | 42 | storeAs: 'incompleteTodos', |
41 | | - queryParams: [ 'orderByChild=done', 'equalTo=true'] }, |
| 43 | + queryParams: ['orderByChild=done', 'equalTo=true'] |
| 44 | + }, |
42 | 45 | { |
43 | 46 | path: 'todos', |
44 | 47 | storeAs: 'completeTodos', |
45 | | - queryParams: [ 'orderByChild=done', 'equalTo=false'] |
46 | | - }, |
| 48 | + queryParams: ['orderByChild=done', 'equalTo=false'] |
| 49 | + } |
47 | 50 | ]), |
48 | | - connect( |
49 | | - ({ firebase: { data } }) => ({ |
50 | | - incompleteTodos: data['incompleteTodos'], // path matches storeAs |
51 | | - completeTodos: data['completeTodos'] // path matches storeAs |
52 | | - }) |
53 | | - ) |
| 51 | + connect(({ firebase: { data } }) => ({ |
| 52 | + incompleteTodos: data['incompleteTodos'], // path matches storeAs |
| 53 | + completeTodos: data['completeTodos'] // path matches storeAs |
| 54 | + })) |
54 | 55 | ) |
| 56 | + |
| 57 | +export default enhance(Home) |
0 commit comments