Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Successfully listing summaries, refs #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Genar Trias Ortiz committed Dec 7, 2017
1 parent 32d2b68 commit dbdb559
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/components/Summaries/SummaryRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import PropTypes from 'prop-types'
import React, { Component } from 'react'

export default class SummaryRow extends Component {
static propTypes = {
summary: PropTypes.object.isRequired,
}

render() {
const { summary } = this.props
return (
<div className='summary-row'>
<ul>
<li>
{ summary.exchange }: { summary.benfit }
</li>
</ul>
</div>
)
}
}
9 changes: 7 additions & 2 deletions src/components/Summaries/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import React, { Component } from 'react'

import { get as getSummaries } from '../../actions/summaries'
import SummaryRow from './SummaryRow'

export default class Summaries extends Component {
static propTypes = {
Expand All @@ -14,9 +15,13 @@ export default class Summaries extends Component {
}

render() {
const rows = this.props.summaries.ids.map((summaryId) => {
const summary = this.props.summaries.all[summaryId]
return <SummaryRow key={summaryId} summary={summary} />
})
return (
<div className='summaries-index'>
Summaries goes here
{rows}
</div>
)
}
Expand Down
4 changes: 3 additions & 1 deletion src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import api from './api'
import markets from './markets'
import events from './events'
import balances from './balances'
import summaries from './summaries'

export const idsMapper = (arrayOfObjects, id = 'id') => {
const all = {}
const ids = []
_.each(arrayOfObjects, (content) => {
all[content[id]] = content
ids.push(content.id)
ids.push(content[id])
})

return {
Expand All @@ -25,4 +26,5 @@ export default combineReducers({
balances,
markets,
events,
summaries,
})
2 changes: 1 addition & 1 deletion src/reducers/summaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default (state = defaultState, action = {}) => {
case SUMMARIES_GET_SUCCESS:
return {
...state,
...idsMapper(action.summaries, 'Currency'),
...idsMapper(action.summaries, 'exchange'),
}

case SUMMARIES_GET_ERROR:
Expand Down

0 comments on commit dbdb559

Please sign in to comment.