Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions apps/web/components/ContentSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import { useEffect, useRef, useState, useDeferredValue } from "react";
import { useEffect, useRef, useState, useDeferredValue, useMemo } from "react";
import Link from "next/link";
import { Cross2Icon, MagnifyingGlassIcon } from "@radix-ui/react-icons";
import { Dialog, DialogClose, DialogContent, Input, Card, CardDescription, CardHeader, CardTitle } from "@repo/ui";
Expand Down Expand Up @@ -45,11 +45,15 @@ export function ContentSearch({ tracks }: { tracks: TrackPros[] }) {
});
setAllTracks(updatedTracks);
}, []);
useEffect(() => {
const fuse = new Fuse(allTracks, {

// Memoize to avoid unnecessary re-computation
const fuse = useMemo(() => {
return new Fuse(allTracks, {
keys: ["payload.problemTitle"],
});
}, [allTracks]);

useEffect(() => {
async function fetchSearchResults() {
if (deferredInput.length > 0) {
/* const data = await getSearchResults(deferredInput); */
Expand All @@ -61,7 +65,7 @@ export function ContentSearch({ tracks }: { tracks: TrackPros[] }) {
}
}
fetchSearchResults();
}, [deferredInput]);
}, [deferredInput , fuse]);

useEffect(() => {
const handleKeyPress = (event: KeyboardEvent) => {
Expand Down
Empty file removed yarn.lock
Empty file.