From 45cd3d1d656e0d4b8dc7ea360e68d397e3fc16ae Mon Sep 17 00:00:00 2001 From: Luna McNulty Date: Fri, 31 May 2024 17:01:49 -0400 Subject: [PATCH 1/6] Add date range selector histogram --- .../src/components/discover/Controls.js | 4 +- .../src/components/discover/Discover.js | 4 +- .../src/components/discover/Filter.js | 15 +- .../src/components/discover/Filters.js | 4 +- .../discover/filterTypes/RangeInput.js | 208 +++++++++++++++++- site/gatsby-site/src/pages/apps/discover.js | 39 +++- 6 files changed, 257 insertions(+), 17 deletions(-) diff --git a/site/gatsby-site/src/components/discover/Controls.js b/site/gatsby-site/src/components/discover/Controls.js index fc2c2ecf0f..b64931ce52 100644 --- a/site/gatsby-site/src/components/discover/Controls.js +++ b/site/gatsby-site/src/components/discover/Controls.js @@ -12,7 +12,7 @@ import { Trans } from 'react-i18next'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faCaretDown, faCaretRight } from '@fortawesome/free-solid-svg-icons'; -const Controls = () => { +const Controls = ({ bins }) => { const { indexUiState } = useInstantSearch(); const [expandFilters, setExpandFilters] = useState(false); @@ -75,7 +75,7 @@ const Controls = () => {
- +
); }; diff --git a/site/gatsby-site/src/components/discover/Discover.js b/site/gatsby-site/src/components/discover/Discover.js index 24a2cfc1f2..3fdbe9ecc1 100644 --- a/site/gatsby-site/src/components/discover/Discover.js +++ b/site/gatsby-site/src/components/discover/Discover.js @@ -30,7 +30,7 @@ function mapping() { }; } -export default function Discover() { +export default function Discover({ bins }) { const { locale } = useLocalization(); const [indexName] = useState(`instant_search-${locale}-featured`); @@ -114,7 +114,7 @@ export default function Discover() { - {width > 767 ? : } + {width > 767 ? : } diff --git a/site/gatsby-site/src/components/discover/Filter.js b/site/gatsby-site/src/components/discover/Filter.js index 7a82cf0bec..e01adf3b76 100644 --- a/site/gatsby-site/src/components/discover/Filter.js +++ b/site/gatsby-site/src/components/discover/Filter.js @@ -54,7 +54,7 @@ function ToggleContent({ label, touched, faIcon, toggled, accordion = false }) { ); } -function ButtonToggle({ label, faIcon, touched, type, filterProps }) { +function ButtonToggle({ label, faIcon, touched, type, filterProps, bins }) { const [toggled, setToggled] = useState(true); const toggleDropdown = () => { @@ -105,20 +105,20 @@ function ButtonToggle({ label, faIcon, touched, type, filterProps }) { toggled ? 'hidden' : 'block ' } bg-white divide-y divide-gray-100 rounded-lg shadow dark:bg-gray-700`} > - + ); } -function FilterContent({ type, filterProps }) { +function FilterContent({ type, filterProps, bins }) { const { default: Component } = componentsMap[type]; - return ; + return ; } const FilterOverlay = React.forwardRef(function Container( - { type, filterProps, ...overlayProps }, + { bins, type, filterProps, ...overlayProps }, ref ) { return ( @@ -131,14 +131,14 @@ const FilterOverlay = React.forwardRef(function Container( >
- +
); }); -export default function Filter({ type, ...filterProps }) { +export default function Filter({ type, bins, ...filterProps }) { const { label, faIcon, attribute } = filterProps; const { touchedCount } = componentsMap[type]; @@ -155,6 +155,7 @@ export default function Filter({ type, ...filterProps }) { touched={touched} type={type} filterProps={filterProps} + {...{ bins }} /> ); diff --git a/site/gatsby-site/src/components/discover/Filters.js b/site/gatsby-site/src/components/discover/Filters.js index e8d3d81b1e..7365d41320 100644 --- a/site/gatsby-site/src/components/discover/Filters.js +++ b/site/gatsby-site/src/components/discover/Filters.js @@ -3,7 +3,7 @@ import REFINEMENT_LISTS from 'components/discover/REFINEMENT_LISTS'; import Filter from './Filter'; import { graphql, useStaticQuery } from 'gatsby'; -function Filters({ expandFilters }) { +function Filters({ expandFilters, bins }) { const { taxa: { nodes: taxa }, } = useStaticQuery(graphql` @@ -44,7 +44,7 @@ function Filters({ expandFilters }) { } return (
- +
); })} diff --git a/site/gatsby-site/src/components/discover/filterTypes/RangeInput.js b/site/gatsby-site/src/components/discover/filterTypes/RangeInput.js index b183b392ef..b9476283f6 100644 --- a/site/gatsby-site/src/components/discover/filterTypes/RangeInput.js +++ b/site/gatsby-site/src/components/discover/filterTypes/RangeInput.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState, useRef, useEffect } from 'react'; import { useRange } from 'react-instantsearch'; import { Trans } from 'react-i18next'; import { debounce } from 'debounce'; @@ -13,7 +13,7 @@ const formatDate = (epoch) => new Date(epoch * 1000).toISOString().substr(0, 10) const dateToEpoch = (date) => new Date(date).getTime() / 1000; -export default function RangeInput({ attribute }) { +export default function RangeInput({ attribute, bins }) { const { range: { min, max }, start, @@ -53,6 +53,18 @@ export default function RangeInput({ attribute }) { {({ values, errors, touched, handleBlur }) => ( <>
+ { + onChange({ min, max: currentRefinement.max }); + })} + setSelectionMax={debounce((max) => { + onChange({ max, min: currentRefinement.min }); + }, 2000)} + {...{ bins }} + />