Skip to content

Commit

Permalink
debounce searchterm
Browse files Browse the repository at this point in the history
  • Loading branch information
soumitradev committed Aug 4, 2023
1 parent e247918 commit 61bacfe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/TimetableEditMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ const TimetableEditMenu = ({
}`}
>
{course.clashing && (
<div className="absolute left-0 top-8 py-1 bg-slate-900/60 text-center w-full">
<div className="absolute left-0 top-8 py-1 bg-slate-900/80 text-center w-full">
<span className="text-slate-200 font-medium text-md">
Clashing with{" "}
{course.clashing
Expand Down
8 changes: 5 additions & 3 deletions src/pages/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";

import { useDebounce } from "usehooks-ts";
import {
LogOut,
AlertOctagon,
Expand Down Expand Up @@ -153,14 +154,15 @@ const Edit = () => {
const [isVertical, setIsVertical] = useState(false);

const [searchTerm, setSearchTerm] = useState("");
const debouncedSearchTerm = useDebounce<string>(searchTerm, 500);
const courseSearchResults = useMemo(
() =>
(searchTerm === ""
(debouncedSearchTerm === ""
? courseDetails
: courseDetails.filter((e) =>
(e.code + ": " + e.name)
.toLowerCase()
.includes(searchTerm.toLowerCase())
.includes(debouncedSearchTerm.toLowerCase())
)
).map((e) => {
const withClash = e as {
Expand All @@ -187,7 +189,7 @@ const Edit = () => {
withClash.clashing = clashes.length === 0 ? null : clashes;
return withClash;
}),
[courseDetails, searchTerm, timetableDetails.examTimes]
[courseDetails, debouncedSearchTerm, timetableDetails.examTimes]
);
const addedCourses = useMemo(
() =>
Expand Down

0 comments on commit 61bacfe

Please sign in to comment.