Skip to content

Commit

Permalink
fix: debounce query title in add log
Browse files Browse the repository at this point in the history
  • Loading branch information
dinkelspiel committed May 28, 2024
1 parent 0159c86 commit a000d74
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions components/addLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import fetcher from '@/client/fetcher';
import { Category, Entry } from '@prisma/client';
import UserEntryCard from './userEntryCard';
import { Drawer, DrawerContent, DrawerTrigger } from './ui/drawer';
import { useMediaQuery } from 'usehooks-ts';
import { useDebounceValue, useMediaQuery } from 'usehooks-ts';
import { cn } from '@/lib/utils';
import { toast } from 'sonner';
import { ExtendedUserEntry } from '@/app/(app)/dashboard/state';
Expand Down Expand Up @@ -168,11 +168,13 @@ const AddLogContent = ({
return q;
};

const debouncedQueryTitle = useDebounceValue(queryTitle, 500);

const { data: queryResults, isLoading: queryIsLoading } = useSWR<
Entry[],
{ error: string }
>(
`/api/entries?q=${queryTitle}&take=8&categories=${generateQueryCategories()}`,
`/api/entries?q=${debouncedQueryTitle[0]}&take=8&categories=${generateQueryCategories()}`,
fetcher
);

Expand All @@ -188,7 +190,7 @@ const AddLogContent = ({
}[],
{ error: string }
>(
`/api/import/search?q=${queryTitle}&categories=${generateQueryCategories()}&take=12&excludeExisting=true`,
`/api/import/search?q=${debouncedQueryTitle[0]}&categories=${generateQueryCategories()}&take=12&excludeExisting=true`,
fetcher
);

Expand Down

0 comments on commit a000d74

Please sign in to comment.