Browse Source

Merge pull request #127 from loeck/master

Improved performance for TransactionsList, remove Defer on Chart in D…
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
beb58dc1c8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/components/DashboardPage/AccountCard.js
  2. 10
      src/components/DashboardPage/index.js
  3. 33
      src/components/TransactionsList/index.js

3
src/components/DashboardPage/AccountCard.js

@ -9,7 +9,6 @@ import IconCurrencyBitcoin from 'icons/currencies/Bitcoin'
import { AreaChart } from 'components/base/Chart' import { AreaChart } from 'components/base/Chart'
import Bar from 'components/base/Bar' import Bar from 'components/base/Bar'
import Box, { Card } from 'components/base/Box' import Box, { Card } from 'components/base/Box'
import Defer from 'components/base/Defer'
import FormattedVal from 'components/base/FormattedVal' import FormattedVal from 'components/base/FormattedVal'
const AccountCard = ({ const AccountCard = ({
@ -47,7 +46,6 @@ const AccountCard = ({
/> />
)} )}
</Box> </Box>
<Defer>
<AreaChart <AreaChart
tiny tiny
id={`account-chart-${account.id}`} id={`account-chart-${account.id}`}
@ -57,7 +55,6 @@ const AccountCard = ({
strokeWidth={1} strokeWidth={1}
linearGradient={[[5, 0.4], [80, 0]]} linearGradient={[[5, 0.4], [80, 0]]}
/> />
</Defer>
</Card> </Card>
) )

10
src/components/DashboardPage/index.js

@ -25,7 +25,6 @@ import { saveSettings } from 'actions/settings'
import { AreaChart } from 'components/base/Chart' import { AreaChart } from 'components/base/Chart'
import Box, { Card } from 'components/base/Box' import Box, { Card } from 'components/base/Box'
import Pills from 'components/base/Pills' import Pills from 'components/base/Pills'
import Defer from 'components/base/Defer'
import Text from 'components/base/Text' import Text from 'components/base/Text'
import TransactionsList from 'components/TransactionsList' import TransactionsList from 'components/TransactionsList'
@ -56,6 +55,7 @@ type State = {
} }
const ACCOUNTS_BY_LINE = 3 const ACCOUNTS_BY_LINE = 3
const ALL_TRANSACTIONS_LIMIT = 10
const TIMEOUT_REFRESH_DATAS = 5e3 const TIMEOUT_REFRESH_DATAS = 5e3
const itemsTimes = [ const itemsTimes = [
@ -92,7 +92,9 @@ const getAllTransactions = accounts => {
return result return result
}, []) }, [])
return sortBy(allTransactions, t => t.received_at).reverse() return sortBy(allTransactions, t => t.received_at)
.reverse()
.slice(0, ALL_TRANSACTIONS_LIMIT)
} }
const getAccountsChunk = accounts => { const getAccountsChunk = accounts => {
@ -123,7 +125,7 @@ class DashboardPage extends PureComponent<Props, State> {
}) })
} }
if (nextProps.accounts.length !== this.props.accounts.length) { if (nextProps.accounts !== this.props.accounts) {
this.setState({ this.setState({
accountsChunk: getAccountsChunk(nextProps.accounts), accountsChunk: getAccountsChunk(nextProps.accounts),
allTransactions: getAllTransactions(nextProps.accounts), allTransactions: getAllTransactions(nextProps.accounts),
@ -192,7 +194,6 @@ class DashboardPage extends PureComponent<Props, State> {
<Box px={6}> <Box px={6}>
<BalanceInfos since={selectedTime} /> <BalanceInfos since={selectedTime} />
</Box> </Box>
<Defer>
<Box ff="Open Sans" fontSize={4} color="warmGrey"> <Box ff="Open Sans" fontSize={4} color="warmGrey">
<AreaChart <AreaChart
id="dashboard-chart" id="dashboard-chart"
@ -218,7 +219,6 @@ class DashboardPage extends PureComponent<Props, State> {
)} )}
/> />
</Box> </Box>
</Defer>
</Card> </Card>
<Box flow={4}> <Box flow={4}>
<Box horizontal align="flex-end"> <Box horizontal align="flex-end">

33
src/components/TransactionsList/index.js

@ -1,9 +1,10 @@
// @flow // @flow
import React from 'react' import React, { Component } from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import moment from 'moment' import moment from 'moment'
import get from 'lodash/get' import get from 'lodash/get'
import isEqual from 'lodash/isEqual'
import type { Transaction as TransactionType } from 'types/common' import type { Transaction as TransactionType } from 'types/common'
@ -118,7 +119,29 @@ type Props = {
withAccounts?: boolean, withAccounts?: boolean,
} }
const TransactionsList = ({ transactions, withAccounts }: Props) => ( class TransactionsList extends Component<Props> {
static defaultProps = {
withAccounts: false,
}
componentWillReceiveProps(nextProps: Props) {
if (nextProps.transactions !== this.props.transactions) {
this._hashCache = this.getHashCache(nextProps.transactions)
}
}
shouldComponentUpdate(nextProps: Props) {
return !isEqual(this._hashCache, this.getHashCache(nextProps.transactions))
}
getHashCache = (transactions: Array<TransactionType>) => transactions.map(t => t.hash)
_hashCache = this.getHashCache(this.props.transactions)
render() {
const { transactions, withAccounts } = this.props
return (
<Box flow={1}> <Box flow={1}>
<Box horizontal pt={4}> <Box horizontal pt={4}>
<HeaderCol size={DATE_COL_SIZE}>{'Date'}</HeaderCol> <HeaderCol size={DATE_COL_SIZE}>{'Date'}</HeaderCol>
@ -136,10 +159,8 @@ const TransactionsList = ({ transactions, withAccounts }: Props) => (
</Box> </Box>
</Defer> </Defer>
</Box> </Box>
) )
}
TransactionsList.defaultProps = {
withAccounts: false,
} }
export default TransactionsList export default TransactionsList

Loading…
Cancel
Save