Skip to content

Commit

Permalink
Add initialLocations in Research page in order to filter the initial …
Browse files Browse the repository at this point in the history
…posts (#880)

* Add initialLocations in Research page

* Fix us default filtered locations - added us states

* run prettier

* run prettier

---------

Co-authored-by: Nikhil Woodruff <[email protected]>
  • Loading branch information
orestisathanasopoulos and nikhilwoodruff authored Nov 27, 2023
1 parent 6a00e22 commit b62413a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/redesign/components/Research.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down

0 comments on commit b62413a

Please sign in to comment.