From a437373e15f08ba935ec9772b1382535a78125c9 Mon Sep 17 00:00:00 2001 From: Maja Date: Tue, 19 Mar 2024 12:06:01 +0100 Subject: [PATCH] Improve form performance on MAT and search pages (#923) --- components/DateRangePicker.js | 119 +++++++++++++++-------------- components/aggregation/mat/Form.js | 23 +++--- components/search/FilterSidebar.js | 52 ++++++------- package.json | 2 +- yarn.lock | 8 +- 5 files changed, 107 insertions(+), 97 deletions(-) diff --git a/components/DateRangePicker.js b/components/DateRangePicker.js index 44a7976d..45dba90d 100644 --- a/components/DateRangePicker.js +++ b/components/DateRangePicker.js @@ -1,28 +1,29 @@ -import React, { useState } from 'react' -import { format, parse, sub, addDays } from 'date-fns' -import { DayPicker, useInput } from 'react-day-picker' +import { addDays, parse, sub } from 'date-fns' +import { Button } from 'ooni-components' +import React, { useMemo, useState } from 'react' +import { DayPicker } from 'react-day-picker' import 'react-day-picker/dist/style.css' -import OutsideClickHandler from 'react-outside-click-handler' import { useIntl } from 'react-intl' +import OutsideClickHandler from 'react-outside-click-handler' import styled from 'styled-components' -import { Button } from 'ooni-components' -import { getDirection } from 'components/withIntl' +import ar from 'date-fns/locale/ar' import de from 'date-fns/locale/de' import en from 'date-fns/locale/en-US' import es from 'date-fns/locale/es' import fa from 'date-fns/locale/fa-IR' import fr from 'date-fns/locale/fr' import is from 'date-fns/locale/is' -import ru from 'date-fns/locale/ru' -import tr from 'date-fns/locale/tr' -import ar from 'date-fns/locale/ar' import pt from 'date-fns/locale/pt' +import ru from 'date-fns/locale/ru' import th from 'date-fns/locale/th' +import tr from 'date-fns/locale/tr' import vi from 'date-fns/locale/vi' import zh from 'date-fns/locale/zh-CN' import zhHant from 'date-fns/locale/zh-HK' +import { getDirection } from 'components/withIntl' + const StyledDatetime = styled.div` z-index: 99999; position: absolute; @@ -55,43 +56,62 @@ justify-content: right; gap: 6px; ` -const getDateFnsLocale = locale => { - switch (locale) { - case 'de': - return de - case 'es': - return es - case 'fa': - return fa - case 'ar': - return ar - case 'fr': - return fr - case 'is': - return is - case 'pt-BR': - return pt - case 'ru': - return ru - case 'tr': - return tr - case 'th': - return th - case 'vi': - return vi - case 'zh-CN': - return zh - case 'zh-Hant': - return zhHant - default: - return en - } +const Footer = ({ handleRangeSelect, range, close }) => { + const intl = useIntl() + + return ( + + + + + ) } const DateRangePicker = ({handleRangeSelect, initialRange, close, ...props}) => { const intl = useIntl() const tomorrow = addDays(new Date(), 1) const ranges = ['Today', 'LastWeek', 'LastMonth', 'LastYear'] + + const dateFnsLocale = useMemo(() => { + switch (intl.locale) { + case 'de': + return de + case 'es': + return es + case 'fa': + return fa + case 'ar': + return ar + case 'fr': + return fr + case 'is': + return is + case 'pt-BR': + return pt + case 'ru': + return ru + case 'tr': + return tr + case 'th': + return th + case 'vi': + return vi + case 'zh-CN': + return zh + case 'zh-Hant': + return zhHant + default: + return en + } + }, [intl.locale]) const selectRange = (range) => { switch (range) { @@ -122,20 +142,7 @@ const DateRangePicker = ({handleRangeSelect, initialRange, close, ...props}) => }}>{intl.formatMessage({id: `DateRange.${range}`})} ) const [range, setRange] = useState({from: parse(initialRange.from, 'yyyy-MM-dd', new Date()), to: parse(initialRange.to, 'yyyy-MM-dd', new Date())}) - const Footer = () => ( - - - - - ) + const onSelect = (range) => { setRange(range) } @@ -147,12 +154,12 @@ const DateRangePicker = ({handleRangeSelect, initialRange, close, ...props}) => } /> + footer={