Skip to content

Commit bec974b

Browse files
committed
Fundable: sync active filter with ?category= query param
1 parent e08e69d commit bec974b

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/components/fundable/index.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { useState, useEffect } from "react";
22
import styles from "./styles.module.css";
33
import Section from "../layout/Section";
44
import CardGrid from "../layout/CardGrid";
@@ -18,7 +18,21 @@ export function getCategoryFromProjectPageName(pageName: string) {
1818
}
1919

2020
export function MainAreaFundableProjects() {
21-
const [active, setActive] = useState("All");
21+
const [active, setActive] = useState(() => {
22+
if (typeof window === "undefined") return "All";
23+
const param = new URLSearchParams(window.location.search).get("category");
24+
return CATEGORIES.includes(param) ? param : "All";
25+
});
26+
27+
useEffect(() => {
28+
const url = new URL(window.location.href);
29+
if (active === "All") {
30+
url.searchParams.delete("category");
31+
} else {
32+
url.searchParams.set("category", active);
33+
}
34+
window.history.replaceState(null, "", url.toString());
35+
}, [active]);
2236

2337
const visible = active === "All"
2438
? ALL_PROJECTS

0 commit comments

Comments
 (0)