Browse Source

feature(activity): create selectors folder for specific selectors. sortedActivity for all payments, invoices, txs sorted by timestamp

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
c1853cc5f8
  1. 5
      app/routes/activity/components/Activity.js
  2. 6
      app/routes/activity/containers/ActivityContainer.js
  3. 22
      app/selectors/activity.js
  4. 5
      app/selectors/index.js

5
app/routes/activity/components/Activity.js

@ -33,9 +33,10 @@ class Activity extends Component {
setInvoice,
paymentModalOpen,
invoiceModalOpen,
currentTicker
currentTicker,
sortedActivity
} = this.props
console.log('sortedActivity: ', sortedActivity)
if (invoiceLoading || paymentLoading) { return <div>Loading...</div> }
return (
<div>

6
app/routes/activity/containers/ActivityContainer.js

@ -12,6 +12,7 @@ import {
paymentSelectors
} from '../../../reducers/payment'
import { fetchTransactions } from '../../../reducers/transaction'
import { activitySelectors } from '../../../selectors'
import Activity from '../components/Activity'
const mapDispatchToProps = {
@ -23,6 +24,7 @@ const mapDispatchToProps = {
searchInvoices
}
console.log('activitySelectors: ', activitySelectors)
const mapStateToProps = state => ({
activity: state.activity,
@ -36,7 +38,9 @@ const mapStateToProps = state => ({
paymentModalOpen: paymentSelectors.paymentModalOpen(state),
invoiceModalOpen: invoiceSelectors.invoiceModalOpen(state),
currentTicker: tickerSelectors.currentTicker(state)
currentTicker: tickerSelectors.currentTicker(state),
sortedActivity: activitySelectors.sortedActivity(state)
})
export default connect(mapStateToProps, mapDispatchToProps)(Activity)

22
app/selectors/activity.js

@ -0,0 +1,22 @@
import { createSelector } from 'reselect'
const activitySelectors = {}
const paymentsSelector = state => state.payment.payments
const invoicesSelector = state => state.invoice.invoices
const transactionsSelector = state => state.transaction.transactions
activitySelectors.sortedActivity = createSelector(
paymentsSelector,
invoicesSelector,
transactionsSelector,
(payments, invoices, transactions) => {
return [...payments, ...invoices, ...transactions].sort((a, b) => {
let aTimestamp = a.hasOwnProperty('time_stamp') ? a.time_stamp : a.creation_date
let bTimestamp = b.hasOwnProperty('time_stamp') ? b.time_stamp : b.creation_date
return bTimestamp - aTimestamp
})
}
)
export default activitySelectors

5
app/selectors/index.js

@ -0,0 +1,5 @@
import activitySelectors from './activity'
export default {
activitySelectors
}
Loading…
Cancel
Save