From b62413ae3f604b4c50b840fddb9bee992a884ac4 Mon Sep 17 00:00:00 2001 From: orestisathanasopoulos <84371920+orestisathanasopoulos@users.noreply.github.com> Date: Mon, 27 Nov 2023 13:35:43 +0100 Subject: [PATCH] Add initialLocations in Research page in order to filter the initial posts (#880) * Add initialLocations in Research page * Fix us default filtered locations - added us states * run prettier * run prettier --------- Co-authored-by: Nikhil Woodruff <35577657+nikhilwoodruff@users.noreply.github.com> --- src/redesign/components/Research.jsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/redesign/components/Research.jsx b/src/redesign/components/Research.jsx index 71f5c42f0..ec27f27b9 100644 --- a/src/redesign/components/Research.jsx +++ b/src/redesign/components/Research.jsx @@ -54,12 +54,28 @@ function ResearchExplorer() { } scrollTo(0, 0); }; + + const extractCountryIdFromPathname = () => { + const pathSegments = window.location.pathname.split("/").filter(Boolean); + if (pathSegments.length > 0) { + return pathSegments[0]; + } + }; + + const initialLocations = locationTags.filter( + (location) => + location === extractCountryIdFromPathname() || + location.startsWith(extractCountryIdFromPathname() + "-") || + location === "global", + ); + const [filteredTopics, setFilteredTopics] = useState( searchParams.get("topics")?.split(",") || topicTags, ); const [filteredLocations, setFilteredLocations] = useState( - searchParams.get("locations")?.split(",") || locationTags, + searchParams.get("locations")?.split(",") || initialLocations, ); + const [filteredAuthors, setFilteredAuthors] = useState( searchParams.get("authors")?.split(",") || authorKeys, );