Skip to content

Commit eac1594

Browse files
committed
fix: debounce search query
1 parent 9510c41 commit eac1594

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

app/(app)/challenges/content.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useState } from "react";
44
import type { TagState } from "./_filter/tag";
5+
import { useDebouncedValue } from 'foxact/use-debounced-value';
56

67
import { QuestionDifficulty, type QuestionWhereInput } from "@/gql/graphql";
78
import FilterSection from "./_filter";
@@ -42,8 +43,20 @@ export default function ChallengePageContent() {
4243
],
4344
});
4445

46+
const deferredSearch = useDebouncedValue(search, 200);
47+
4548
const where: QuestionWhereInput = {
46-
titleContainsFold: search,
49+
or: [
50+
{
51+
titleContainsFold: deferredSearch,
52+
},
53+
{
54+
descriptionContainsFold: deferredSearch,
55+
},
56+
{
57+
categoryContainsFold: deferredSearch,
58+
},
59+
],
4760
difficultyIn: tags.difficulty,
4861
};
4962

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"babel-plugin-react-compiler": "19.1.0-rc.3",
3939
"class-variance-authority": "^0.7.1",
4040
"clsx": "^2.1.1",
41+
"foxact": "^0.2.49",
4142
"graphql": "^16.11.0",
4243
"lucide-react": "^0.544.0",
4344
"next": "15.6.0-canary.6",

pnpm-lock.yaml

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)