From d894cdc93f019852c7c30b6d5713ba0bc7dbda2b Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Tue, 31 Jul 2018 22:54:18 +0200 Subject: Port profile redesign to glitch-soc Port bb71538bb503159177d46d8956bd466973c0876b to glitch-soc --- .../glitch/components/relative_timestamp.js | 50 +- .../flavours/glitch/styles/accounts.scss | 580 +++++---------------- app/javascript/flavours/glitch/styles/basics.scss | 5 +- .../flavours/glitch/styles/components/status.scss | 12 + .../flavours/glitch/styles/containers.scss | 573 ++++++++++++++++++++ app/javascript/flavours/glitch/styles/footer.scss | 154 +++++- app/javascript/flavours/glitch/styles/index.scss | 2 +- .../flavours/glitch/styles/landing_strip.scss | 111 ---- .../flavours/glitch/styles/stream_entries.scss | 391 +++----------- .../flavours/glitch/styles/variables.scss | 2 + app/javascript/flavours/glitch/styles/widgets.scss | 123 +++++ 11 files changed, 1079 insertions(+), 924 deletions(-) delete mode 100644 app/javascript/flavours/glitch/styles/landing_strip.scss create mode 100644 app/javascript/flavours/glitch/styles/widgets.scss (limited to 'app/javascript') diff --git a/app/javascript/flavours/glitch/components/relative_timestamp.js b/app/javascript/flavours/glitch/components/relative_timestamp.js index 3c8db7092..9609714a1 100644 --- a/app/javascript/flavours/glitch/components/relative_timestamp.js +++ b/app/javascript/flavours/glitch/components/relative_timestamp.js @@ -60,6 +60,32 @@ const getUnitDelay = units => { } }; +export const timeAgoString = (intl, date, now, year) => { + const delta = now - date.getTime(); + + let relativeTime; + + if (delta < 10 * SECOND) { + relativeTime = intl.formatMessage(messages.just_now); + } else if (delta < 7 * DAY) { + if (delta < MINUTE) { + relativeTime = intl.formatMessage(messages.seconds, { number: Math.floor(delta / SECOND) }); + } else if (delta < HOUR) { + relativeTime = intl.formatMessage(messages.minutes, { number: Math.floor(delta / MINUTE) }); + } else if (delta < DAY) { + relativeTime = intl.formatMessage(messages.hours, { number: Math.floor(delta / HOUR) }); + } else { + relativeTime = intl.formatMessage(messages.days, { number: Math.floor(delta / DAY) }); + } + } else if (date.getFullYear() === year) { + relativeTime = intl.formatDate(date, shortDateFormatOptions); + } else { + relativeTime = intl.formatDate(date, { ...shortDateFormatOptions, year: 'numeric' }); + } + + return relativeTime; +}; + @injectIntl export default class RelativeTimestamp extends React.Component { @@ -121,28 +147,8 @@ export default class RelativeTimestamp extends React.Component { render () { const { timestamp, intl, year } = this.props; - const date = new Date(timestamp); - const delta = this.state.now - date.getTime(); - - let relativeTime; - - if (delta < 10 * SECOND) { - relativeTime = intl.formatMessage(messages.just_now); - } else if (delta < 7 * DAY) { - if (delta < MINUTE) { - relativeTime = intl.formatMessage(messages.seconds, { number: Math.floor(delta / SECOND) }); - } else if (delta < HOUR) { - relativeTime = intl.formatMessage(messages.minutes, { number: Math.floor(delta / MINUTE) }); - } else if (delta < DAY) { - relativeTime = intl.formatMessage(messages.hours, { number: Math.floor(delta / HOUR) }); - } else { - relativeTime = intl.formatMessage(messages.days, { number: Math.floor(delta / DAY) }); - } - } else if (date.getFullYear() === year) { - relativeTime = intl.formatDate(date, shortDateFormatOptions); - } else { - relativeTime = intl.formatDate(date, { ...shortDateFormatOptions, year: 'numeric' }); - } + const date = new Date(timestamp); + const relativeTime = timeAgoString(intl, date, this.state.now, year); return (