Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Re-add debounce for status
Browse files Browse the repository at this point in the history
  • Loading branch information
acouch committed Jun 26, 2024
1 parent 57297f5 commit 114d9b6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions frontend/src/app/[locale]/look/SearchOpportunityStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useContext } from "react";

import { Checkbox } from "@trussworks/react-uswds";
// import { useDebouncedCallback } from "use-debounce";
import { useDebouncedCallback } from "use-debounce";
import { QueryContext } from "./QueryProvider";
import { useSearchParamUpdater2 } from "src/hooks/useSearchParamUpdater";

Expand All @@ -24,21 +24,28 @@ const statusOptions: StatusOption[] = [
{ id: "status-archived", label: "Archived", value: "archived" },
];

// Wait a half-second before updating query params
// Wait 50 miliseconds before updating query params
// and submitting the form
// const SEARCH_OPPORTUNITY_STATUS_DEBOUNCE_TIME = 500;
const SEARCH_OPPORTUNITY_STATUS_DEBOUNCE_TIME = 50;

export default function SearchOpportunityStatus({ selectedStatuses }: SearchOpportunityStatusProps) {
const { queryTerm } = useContext(QueryContext);
const { updateQueryParams } = useSearchParamUpdater2();

const debouncedUpdate = useDebouncedCallback(
(selectedStatuses: Set<string>) => {
const key = "status";
updateQueryParams(selectedStatuses, key, queryTerm);
},
SEARCH_OPPORTUNITY_STATUS_DEBOUNCE_TIME,
);

const handleCheck = (statusValue: string, isChecked: boolean) => {
const updatedStatuses = new Set(selectedStatuses);
isChecked
? updatedStatuses.add(statusValue)
: updatedStatuses.delete(statusValue);
const key = "status";
updateQueryParams(updatedStatuses, key, queryTerm);
debouncedUpdate(updatedStatuses);
};

return (
Expand Down

0 comments on commit 114d9b6

Please sign in to comment.