From 6becf2cfe3f06e1752dac93d52daf6d3cda8cc17 Mon Sep 17 00:00:00 2001 From: NastiaS Date: Thu, 3 May 2018 17:06:50 +0200 Subject: [PATCH] make greetings dynamic based on the local time of user --- src/components/DashboardPage/index.js | 21 +++++++++++++++++++-- static/i18n/en/dashboard.yml | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index e8b49cac..c6baa3b1 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -10,6 +10,7 @@ import { formatCurrencyUnit, getFiatCurrencyByTicker, } from '@ledgerhq/live-common/lib/helpers/currencies' +import moment from 'moment' import type { Account } from '@ledgerhq/live-common/lib/types' @@ -110,6 +111,22 @@ class DashboardPage extends PureComponent { } } + handleGreeting = () => { + const localTimeHour = new Date().getHours() + if (localTimeHour) { + const afternoon_breakpoint = 12 + const evening_breakpoint = 17 + + if (localTimeHour >= afternoon_breakpoint && localTimeHour < evening_breakpoint) { + return 'dashboard:greeting.afternoon' + } else if (localTimeHour >= evening_breakpoint) { + return 'dashboard:greeting.evening' + } + return 'dashboard:greeting.morning' + } + return '' + } + handleChangeSelectedTime = item => this.setState({ selectedTime: item.key, @@ -121,7 +138,7 @@ class DashboardPage extends PureComponent { render() { const { push, accounts, t, counterValue } = this.props const { accountsChunk, selectedTime, daysCount } = this.state - + const timeFrame = this.handleGreeting() const totalAccounts = accounts.length return ( @@ -129,7 +146,7 @@ class DashboardPage extends PureComponent { - {t('dashboard:greetings')} + {timeFrame ? t(timeFrame) : t('dashboard:defaultGreeting')} {totalAccounts > 0 diff --git a/static/i18n/en/dashboard.yml b/static/i18n/en/dashboard.yml index 73afd798..688ebf3c 100644 --- a/static/i18n/en/dashboard.yml +++ b/static/i18n/en/dashboard.yml @@ -1,5 +1,9 @@ title: Dashboard -greetings: 'Good morning!' +greeting: + morning: "Good Morning!" + evening: "Good Evening!" + afternoon: "Good Afternoon!" +defaultGreeting: 'Greetings!' summary: here is the summary of your account summary_plural: 'here is the summary of your {{count}} accounts' noAccounts: no accounts