diff --git a/src/components/DashboardPage/AccountCardList.js b/src/components/DashboardPage/AccountCardList.js new file mode 100644 index 00000000..eee7321e --- /dev/null +++ b/src/components/DashboardPage/AccountCardList.js @@ -0,0 +1,66 @@ +// @flow + +import React, { Component } from 'react' +import type { Account, Currency } from '@ledgerhq/live-common/lib/types' + +import Box from 'components/base/Box' +import AccountCard from './AccountCard' +import AccountCardListHeader from './AccountCardListHeader' +import AccountCardPlaceholder from './AccountCardPlaceholder' + +type Props = { + accounts: Account[], + onAccountClick: Account => void, + counterValue: Currency, + daysCount: number, +} + +class AccountCardList extends Component { + render() { + const { accounts, counterValue, daysCount, onAccountClick } = this.props + + return ( + + + + {accounts + .map(account => ({ + key: account.id, + account, + })) + .concat( + Array(3 - (accounts.length % 3)) + .fill(null) + .map((_, i) => ({ + key: `placeholder_${i}`, + withPlaceholder: i === 0, + })), + ) + .map(item => ( + + {item.account ? ( + + ) : item.withPlaceholder ? ( + + ) : null} + + ))} + + + ) + } +} + +export default AccountCardList diff --git a/src/components/DashboardPage/AccountCardListHeader.js b/src/components/DashboardPage/AccountCardListHeader.js new file mode 100644 index 00000000..9da0fde5 --- /dev/null +++ b/src/components/DashboardPage/AccountCardListHeader.js @@ -0,0 +1,33 @@ +// @flow + +import React, { PureComponent } from 'react' +import { translate } from 'react-i18next' +import type { T } from 'types/common' + +import Box from 'components/base/Box' +import Text from 'components/base/Text' +import AccountsOrder from './AccountsOrder' + +type Props = { + t: T, + accountsLength: number, +} + +class AccountCardListHeader extends PureComponent { + render() { + const { accountsLength, t } = this.props + + return ( + + + {t('app:dashboard.accounts.title', { count: accountsLength })} + + + + + + ) + } +} + +export default translate()(AccountCardListHeader) diff --git a/src/components/DashboardPage/AccountCardPlaceholder.js b/src/components/DashboardPage/AccountCardPlaceholder.js new file mode 100644 index 00000000..1936fe4d --- /dev/null +++ b/src/components/DashboardPage/AccountCardPlaceholder.js @@ -0,0 +1,64 @@ +// @flow + +import React, { PureComponent } from 'react' +import { connect } from 'react-redux' +import { translate } from 'react-i18next' +import styled from 'styled-components' + +import { openModal } from 'reducers/modals' +import { MODAL_ADD_ACCOUNTS } from 'config/constants' +import type { T } from 'types/common' +import { i } from 'helpers/staticPath' +import Box from 'components/base/Box' +import Button from 'components/base/Button' + +const Wrapper = styled(Box).attrs({ + p: 4, + flex: 1, + alignItems: 'center', +})` + border: 1px dashed ${p => p.theme.colors.fog}; + border-radius: 4px; + height: 215px; +` + +class AccountCardPlaceholder extends PureComponent<{ + t: T, + openModal: string => void, +}> { + onAddAccounts = () => this.props.openModal(MODAL_ADD_ACCOUNTS) + + render() { + const { t } = this.props + return ( + + + + + + {t('app:dashboard.emptyAccountTile.desc')} + + + + ) + } +} + +export default translate()( + connect( + null, + { + openModal, + }, + )(AccountCardPlaceholder), +) diff --git a/src/components/DashboardPage/CurrentGreetings.js b/src/components/DashboardPage/CurrentGreetings.js new file mode 100644 index 00000000..da4896b8 --- /dev/null +++ b/src/components/DashboardPage/CurrentGreetings.js @@ -0,0 +1,31 @@ +// @flow +import React, { PureComponent } from 'react' +import { translate } from 'react-i18next' +import type { T } from 'types/common' + +import Text from 'components/base/Text' + +const getCurrentGreetings = () => { + const localTimeHour = new Date().getHours() + const afternoon_breakpoint = 12 + const evening_breakpoint = 17 + if (localTimeHour >= afternoon_breakpoint && localTimeHour < evening_breakpoint) { + return 'app:dashboard.greeting.afternoon' + } else if (localTimeHour >= evening_breakpoint) { + return 'app:dashboard.greeting.evening' + } + return 'app:dashboard.greeting.morning' +} + +class CurrentGettings extends PureComponent<{ t: T }> { + render() { + const { t } = this.props + return ( + + {t(getCurrentGreetings())} + + ) + } +} + +export default translate()(CurrentGettings) diff --git a/src/components/DashboardPage/SummaryDesc.js b/src/components/DashboardPage/SummaryDesc.js new file mode 100644 index 00000000..ff8c5f3e --- /dev/null +++ b/src/components/DashboardPage/SummaryDesc.js @@ -0,0 +1,22 @@ +// @flow + +import React, { PureComponent } from 'react' +import { translate } from 'react-i18next' +import type { T } from 'types/common' +import Text from 'components/base/Text' + +class SummaryDesc extends PureComponent<{ + t: T, + totalAccounts: number, +}> { + render() { + const { totalAccounts, t } = this.props + return ( + + {t('app:dashboard.summary', { count: totalAccounts })} + + ) + } +} + +export default translate()(SummaryDesc) diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index 384f6d71..2b3b6340 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -5,7 +5,6 @@ import uniq from 'lodash/uniq' import { compose } from 'redux' import { translate } from 'react-i18next' import { connect } from 'react-redux' -import styled from 'styled-components' import { push } from 'react-router-redux' import { createStructuredSelector } from 'reselect' import type { Account, Currency } from '@ledgerhq/live-common/lib/types' @@ -14,11 +13,8 @@ import type { T } from 'types/common' import { colors } from 'styles/theme' import { accountsSelector } from 'reducers/accounts' -import { openModal } from 'reducers/modals' -import { MODAL_ADD_ACCOUNTS } from 'config/constants' import { counterValueCurrencySelector, - localeSelector, selectedTimeRangeSelector, timeRangeDaysByKey, } from 'reducers/settings' @@ -32,27 +28,23 @@ import UpdateNotifier from 'components/UpdateNotifier' import BalanceInfos from 'components/BalanceSummary/BalanceInfos' import BalanceSummary from 'components/BalanceSummary' import Box from 'components/base/Box' -import { i } from 'helpers/staticPath' import PillsDaysCount from 'components/PillsDaysCount' -import Text from 'components/base/Text' import OperationsList from 'components/OperationsList' import StickyBackToTop from 'components/StickyBackToTop' -import Button from 'components/base/Button' -import AccountCard from './AccountCard' -import AccountsOrder from './AccountsOrder' import EmptyState from './EmptyState' +import CurrentGreetings from './CurrentGreetings' +import SummaryDesc from './SummaryDesc' +import AccountCardList from './AccountCardList' const mapStateToProps = createStructuredSelector({ accounts: accountsSelector, counterValue: counterValueCurrencySelector, - locale: localeSelector, selectedTimeRange: selectedTimeRangeSelector, }) const mapDispatchToProps = { push, saveSettings, - openModal, } type Props = { @@ -62,41 +54,33 @@ type Props = { counterValue: Currency, selectedTimeRange: TimeRange, saveSettings: ({ selectedTimeRange: TimeRange }) => *, - openModal: string => void, } class DashboardPage extends PureComponent { onAccountClick = account => this.props.push(`/account/${account.id}`) - handleGreeting = () => { - const localTimeHour = new Date().getHours() - const afternoon_breakpoint = 12 - const evening_breakpoint = 17 - - if (localTimeHour >= afternoon_breakpoint && localTimeHour < evening_breakpoint) { - return 'app:dashboard.greeting.afternoon' - } else if (localTimeHour >= evening_breakpoint) { - return 'app:dashboard.greeting.evening' - } - return 'app:dashboard.greeting.morning' - } - handleChangeSelectedTime = item => { this.props.saveSettings({ selectedTimeRange: item.key }) } - _cacheBalance = null + renderHeader = ({ isAvailable, totalBalance, selectedTimeRange, sinceBalance, refBalance }) => ( + + ) render() { - const { accounts, t, counterValue, selectedTimeRange, openModal } = this.props + const { accounts, t, counterValue, selectedTimeRange } = this.props const daysCount = timeRangeDaysByKey[selectedTimeRange] - const timeFrame = this.handleGreeting() - const imagePath = i('empty-account-tile.svg') const totalAccounts = accounts.length const totalCurrencies = uniq(accounts.map(a => a.currency.id)).length const totalOperations = accounts.reduce((sum, a) => sum + a.operations.length, 0) - const displayOperationsHelper = (account: Account) => account.operations.length > 0 - const displayOperations = accounts.some(displayOperationsHelper) return ( @@ -113,12 +97,8 @@ class DashboardPage extends PureComponent { - - {t(timeFrame)} - - - {t('app:dashboard.summary', { count: totalAccounts })} - + + { /> - - + + + + {totalOperations > 0 && ( + ( - - )} + title={t('app:dashboard.recentActivity')} + withAccount /> - - - - {t('app:dashboard.accounts.title', { count: accounts.length })} - - - - - - - {accounts - .concat( - Array(3 - (accounts.length % 3)) - .fill(null) - .map((_, i) => i === 0), - ) - .map((account, i) => ( - - {account ? ( - typeof account === 'object' ? ( - - ) : ( - - - - - - {t('app:dashboard.emptyAccountTile.desc')} - - - - ) - ) : null} - - ))} - - - {displayOperations && ( - - )} - - + )} + ) : ( @@ -243,13 +151,3 @@ export default compose( ), translate(), )(DashboardPage) - -const Wrapper = styled(Box).attrs({ - p: 4, - flex: 1, - alignItems: 'center', -})` - border: 1px dashed ${p => p.theme.colors.fog}; - border-radius: 4px; - height: 215px; -`