Skip to content

Commit

Permalink
Show date, inflow and outflow in transaction item
Browse files Browse the repository at this point in the history
- Add styles to the title and subtitle
- Update proptypes (+2 squashed commits)
- Get the date instead of description from firebase
  • Loading branch information
arvinsim committed Apr 25, 2017
1 parent 42cd5cd commit 186bfa4
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 23 deletions.
19 changes: 8 additions & 11 deletions src/components/TransactionList/TransactionList.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styles from './styles.js'

import React, { Component } from 'react'
import PropTypes from 'prop-types'
import {
View,
ScrollView,
Expand All @@ -14,14 +15,8 @@ import {
import TransactionListItem from '../TransactionListItem'

class TransactionList extends Component {
_renderListItem (item) {
return (
<Text>{item.transaction}</Text>
)
}

render () {
const { transactions, handleEditTransaction, handleDeleteTransaction } = this.props
const { transactions } = this.props

return (
<View>
Expand All @@ -45,10 +40,12 @@ class TransactionList extends Component {
}

TransactionList.propTypes = {
transactions: React.PropTypes.arrayOf(
React.PropTypes.shape({
title: React.PropTypes.string.isRequired,
description: React.PropTypes.string
transactions: PropTypes.arrayOf(
PropTypes.shape({
title: PropTypes.string.isRequired,
date: PropTypes.string.isRequired,
inflow: PropTypes.string.isRequired,
outflow: PropTypes.string.isRequired
}).isRequired
)
}
Expand Down
43 changes: 34 additions & 9 deletions src/components/TransactionListItem/TransactionListItem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import styles from './styles.js'

import React, { Component } from 'react'
import { View } from 'react-native'
import PropTypes from 'prop-types'
import { View, Text } from 'react-native'
import { ListItem } from 'react-native-elements'

import TransactionListItemOptionsContainer from '../../containers/TransactionListItemOptionsContainer'
Expand All @@ -14,7 +15,7 @@ class TransactionListItem extends Component {
}
}

_toggleShowOptions () {
_toggleShowOptions() {
if (this.state.showOptions) {
this.setState({
showOptions: false
Expand All @@ -26,27 +27,51 @@ class TransactionListItem extends Component {
}
}

renderTitle(title) {
return <Text style={styles.title}>{title}</Text>
}

renderSubtitle(date, inflow, outflow) {
const dateText = date ? <Text style={styles.date}>{date}</Text> : undefined
const inflowText = inflow ? <Text style={styles.inflow}>{inflow}</Text> : undefined
const outflowText = outflow ? <Text style={styles.outflow}>{outflow}</Text> : undefined

return (
<View style={styles.subtitle}>
{dateText}
{inflowText}
{outflowText}
</View>
)
}

render() {
const { item } = this.props
const { title, description } = item
const { title, date, inflow, outflow } = item

return (
<View>
<ListItem
title={title}
subtitle={description}
onPress={this._toggleShowOptions.bind(this)}
title={this.renderTitle(title)}
subtitle={this.renderSubtitle(date, inflow, outflow)}
onPress={this._toggleShowOptions.bind(this)}
hideChevron
/>
{ this.state.showOptions &&
<TransactionListItemOptionsContainer item={item} />
{this.state.showOptions &&
<TransactionListItemOptionsContainer item={item} />
}
</View>
)
}
}

TransactionListItem.propTypes = {
title: React.PropTypes.string
item: PropTypes.shape({
title: PropTypes.string.isRequired,
date: PropTypes.string.isRequired,
inflow: PropTypes.string.isRequired,
outflow: PropTypes.string.isRequired
}).isRequired
}

export default TransactionListItem
24 changes: 23 additions & 1 deletion src/components/TransactionListItem/styles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
import colors from '../../config/colors'
import { StyleSheet } from 'react-native'

const styles = StyleSheet.create({})
const styles = StyleSheet.create({
subtitle: {
flex: 1,
flexDirection: 'row'
},
title: {
flex: 1,
fontSize: 20
},
date: {
flex: 1,
color: '#808080'
},
inflow: {
flex: 1,
color: colors.primary,
},
outflow: {
flex: 1,
color: '#ff0000',
}
})

export default styles
4 changes: 2 additions & 2 deletions src/lib/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export const getTransactionsFromFirebase = () => {
return transactionsRef.once('value').then((snap) => {
let transactions = []
snap.forEach((transaction) => {
const { title, description, inflow, outflow } = transaction.val()
const { title, date, inflow, outflow } = transaction.val()

transactions.push({
title: title,
description: description,
date: date,
inflow: inflow,
outflow: outflow,
_key: transaction.key
Expand Down

0 comments on commit 186bfa4

Please sign in to comment.