@@ -9,6 +9,7 @@ import SingleColumn from "../components/SingleColumn";
9import Section from "../components/Section";
9import Section from "../components/Section";
10import GrantPreview from "../components/GrantPreview";
10import GrantPreview from "../components/GrantPreview";
11import JoinGroup from "../components/JoinGroup";
11import JoinGroup from "../components/JoinGroup";
12+import omit from "lodash.omit";
12import { getAllPosts, getGrantsCategories, getGrantsTypes } from "../lib/lib";
13import { getAllPosts, getGrantsCategories, getGrantsTypes } from "../lib/lib";
14function isArray(arr) {
15function isArray(arr) {
@@ -41,6 +42,25 @@ export default function Grants({ posts, categories, types, search }) {
45+ function pushOrDropQuery(queryName, currentQuery, item) {
47+ if (isArray(currentQuery)) {
48+ to = isOrIsIn(item, currentQuery)
49+ ? currentQuery.filter((e) => e !== item)
50+ : [...currentQuery, item];
52+ to = isOrIsIn(item, currentQuery)
54+ : [currentQuery, item].filter((e) => e !== undefined);
57+ toWithQuery = omit(router.query, queryName);
59+ toWithQuery = { ...router.query, [queryName]: to };
44 const annotatedPosts = posts.map((post) => {
64 const annotatedPosts = posts.map((post) => {
45 if (post.extra.canceled) {
65 if (post.extra.canceled) {
46 return { ...post, status: "canceled" };
66 return { ...post, status: "canceled" };
@@ -304,21 +324,7 @@ export default function Grants({ posts, categories, types, search }) {
304 const active = isOrIsIn(each, category)
324 const active = isOrIsIn(each, category)
305 ? "bg-green-400 text-white"
325 ? "bg-green-400 text-white"
306 : "bg-wall-100 text-wall-500";
326 : "bg-wall-100 text-wall-500";
307− let to, categoryQuery;
327+ const categoryQuery = pushOrDropQuery("category", category, each);
308− if (isArray(category)) {
309− to = isOrIsIn(each, category)
310− ? category.filter((e) => e !== each)
311− : [...category, each];
313− to = isOrIsIn(each, category)
315− : [category, each].filter((e) => e !== undefined);
318− categoryQuery = (({ category, ...obj }) => obj)(router.query);
320− categoryQuery = { ...router.query, category: to };
324 className={`${active} badge-sm mr-1 my-1`}
330 className={`${active} badge-sm mr-1 my-1`}
@@ -348,19 +354,7 @@ export default function Grants({ posts, categories, types, search }) {
348 ? "Exclude In Progress"
354 ? "Exclude In Progress"
349 : "Include In Progress";
355 : "Include In Progress";
351− let to, statusQuery;
357+ const statusQuery = pushOrDropQuery("status", status, each);
352− if (isArray(status)) {
353− to = isOrIsIn(each, status)
354− ? status.filter((e) => e !== each)
355− : [...status, each];
357− to = isOrIsIn(each, status) ? null : [status, each];
360− statusQuery = (({ status, ...obj }) => obj)(router.query);
362− statusQuery = { ...router.query, status: to };
366 className="mr-4 badge-sm bg-black text-white"
360 className="mr-4 badge-sm bg-black text-white"