diff --git a/app/components/Layout.js b/app/components/Layout.js index 7fd9eafc..a00b3bef 100644 --- a/app/components/Layout.js +++ b/app/components/Layout.js @@ -22,7 +22,6 @@ import UiStore from "stores/UiStore"; import ErrorSuspended from "scenes/ErrorSuspended"; import KeyboardShortcuts from "scenes/KeyboardShortcuts"; import Button from "components/Button"; -import DocumentHistory from "components/DocumentHistory"; import Flex from "components/Flex"; import Guide from "components/Guide"; import { LoadingIndicatorBar } from "components/LoadingIndicator"; @@ -38,6 +37,12 @@ import { newDocumentUrl, } from "utils/routeHelpers"; +const DocumentHistory = React.lazy(() => + import( + /* webpackChunkName: "document-history" */ "components/DocumentHistory" + ) +); + type Props = { documents: DocumentsStore, children?: ?React.Node, @@ -154,12 +159,14 @@ class Layout extends React.Component { {this.props.children} - - - + + + + + diff --git a/app/components/PaginatedList.js b/app/components/PaginatedList.js index ca1d7061..ce876259 100644 --- a/app/components/PaginatedList.js +++ b/app/components/PaginatedList.js @@ -2,10 +2,11 @@ import ArrowKeyNavigation from "boundless-arrow-key-navigation"; import { isEqual } from "lodash"; import { observable, action } from "mobx"; -import { observer } from "mobx-react"; +import { observer, inject } from "mobx-react"; import * as React from "react"; import { withTranslation, type TFunction } from "react-i18next"; import { Waypoint } from "react-waypoint"; +import AuthStore from "stores/AuthStore"; import { DEFAULT_PAGINATION_LIMIT } from "stores/BaseStore"; import DelayedMount from "components/DelayedMount"; import PlaceholderList from "components/List/Placeholder"; @@ -17,6 +18,7 @@ type Props = { heading?: React.Node, empty?: React.Node, items: any[], + auth: AuthStore, renderItem: (any, index: number) => React.Node, renderHeading?: (name: React.Element | string) => React.Node, t: TFunction, @@ -105,7 +107,7 @@ class PaginatedList extends React.Component { }; render() { - const { items, heading, empty, renderHeading } = this.props; + const { items, heading, auth, empty, renderHeading } = this.props; let previousHeading = ""; const showLoading = @@ -137,7 +139,11 @@ class PaginatedList extends React.Component { // Get what a heading would look like for this item const currentDate = item.updatedAt || item.createdAt || previousHeading; - const currentHeading = dateToHeading(currentDate, this.props.t); + const currentHeading = dateToHeading( + currentDate, + this.props.t, + auth.user?.language + ); // If the heading is different to any previous heading then we // should render it, otherwise the item can go under the previous @@ -173,4 +179,4 @@ class PaginatedList extends React.Component { export const Component = PaginatedList; -export default withTranslation()(PaginatedList); +export default withTranslation()(inject("auth")(PaginatedList)); diff --git a/app/utils/dates.js b/app/utils/dates.js index a902f475..c3ac1ef8 100644 --- a/app/utils/dates.js +++ b/app/utils/dates.js @@ -4,14 +4,20 @@ import { isYesterday, differenceInCalendarWeeks, differenceInCalendarMonths, + differenceInCalendarYears, + format as formatDate, } from "date-fns"; -import * as React from "react"; import { type TFunction } from "react-i18next"; -import LocaleTime from "components/LocaleTime"; +import { dateLocale } from "utils/i18n"; -export function dateToHeading(dateTime: string, t: TFunction) { +export function dateToHeading( + dateTime: string, + t: TFunction, + userLocale: ?string +) { const date = Date.parse(dateTime); const now = new Date(); + const locale = dateLocale(userLocale); if (isToday(date)) { return t("Today"); @@ -26,7 +32,7 @@ export function dateToHeading(dateTime: string, t: TFunction) { // async bundle loading of languages const weekDiff = differenceInCalendarWeeks(now, date); if (weekDiff === 0) { - return ; + return formatDate(Date.parse(dateTime), "iiii", { locale }); } if (weekDiff === 1) { @@ -42,10 +48,11 @@ export function dateToHeading(dateTime: string, t: TFunction) { return t("Last month"); } - if (monthDiff <= 12) { + const yearDiff = differenceInCalendarYears(now, date); + if (yearDiff === 0) { return t("This year"); } // If older than the current calendar year then just print the year e.g 2020 - return ; + return formatDate(Date.parse(dateTime), "y", { locale }); } diff --git a/app/utils/i18n.js b/app/utils/i18n.js new file mode 100644 index 00000000..6480c14e --- /dev/null +++ b/app/utils/i18n.js @@ -0,0 +1,36 @@ +// @flow +import { + enUS, + de, + faIR, + fr, + es, + it, + ja, + ko, + ptBR, + pt, + zhCN, + zhTW, + ru, +} from "date-fns/locale"; + +const locales = { + en_US: enUS, + de_DE: de, + es_ES: es, + fa_IR: faIR, + fr_FR: fr, + it_IT: it, + ja_JP: ja, + ko_KR: ko, + pt_BR: ptBR, + pt_PT: pt, + zh_CN: zhCN, + zh_TW: zhTW, + ru_RU: ru, +}; + +export function dateLocale(userLocale: ?string) { + return userLocale ? locales[userLocale] : undefined; +}