From a1316aca98daf83edb8d70cc669761f434736e23 Mon Sep 17 00:00:00 2001 From: Filip Lelek Date: Tue, 1 Oct 2024 15:59:44 +0200 Subject: [PATCH] Change search results --- package-lock.json | 14 -------------- package.json | 1 - src/app/page.tsx | 46 ++++++++++++++++++++++++---------------------- 3 files changed, 24 insertions(+), 37 deletions(-) diff --git a/package-lock.json b/package-lock.json index 96572f5..7e1650b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,7 +37,6 @@ "eslint-config-next": "^12.3.4", "filecoin-verifier-tools": "^2.3.0", "filecoin-verifier-tools-temporary": "^2.3.0", - "fuse.js": "^6.6.2", "lucide-react": "^0.260.0", "next": "13.5.6", "next-auth": "^4.22.1", @@ -8946,14 +8945,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/fuse.js": { - "version": "6.6.2", - "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-6.6.2.tgz", - "integrity": "sha512-cJaJkxCCxC8qIIcPBF9yGxY0W/tVZS3uEISDxhYIdtk8OL93pe+6Zj7LjCqVV4dzbqcriOZ+kQ/NE4RXZHsIGA==", - "engines": { - "node": ">=10" - } - }, "node_modules/gaxios": { "version": "5.1.3", "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-5.1.3.tgz", @@ -21715,11 +21706,6 @@ "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==" }, - "fuse.js": { - "version": "6.6.2", - "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-6.6.2.tgz", - "integrity": "sha512-cJaJkxCCxC8qIIcPBF9yGxY0W/tVZS3uEISDxhYIdtk8OL93pe+6Zj7LjCqVV4dzbqcriOZ+kQ/NE4RXZHsIGA==" - }, "gaxios": { "version": "5.1.3", "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-5.1.3.tgz", diff --git a/package.json b/package.json index e697a2e..01bda3c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "eslint-config-next": "^12.3.4", "filecoin-verifier-tools": "^2.3.0", "filecoin-verifier-tools-temporary": "^2.3.0", - "fuse.js": "^6.6.2", "lucide-react": "^0.260.0", "next": "13.5.6", "next-auth": "^4.22.1", diff --git a/src/app/page.tsx b/src/app/page.tsx index 9c0a8b1..c60f590 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -31,7 +31,6 @@ import { getApplicationsForRepo, } from '@/lib/apiClient' import { type Application } from '@/type' -import Fuse from 'fuse.js' import { Search } from 'lucide-react' import { useSession } from 'next-auth/react' import { usePathname, useRouter, useSearchParams } from 'next/navigation' @@ -126,28 +125,31 @@ export default function Home(): JSX.Element { useEffect(() => { if (isLoading || data == null) return - const filteredData = data?.filter( - (app) => filter === 'all' || app.Lifecycle.State === filter, - ) + const debounceTimeout = setTimeout(() => { + const filteredData = data?.filter( + (app) => filter === 'all' || app.Lifecycle.State === filter, + ) - const fuseOptions = - filteredData?.length > 0 - ? { - keys: [ - ...Object.keys(filteredData[0].Client).map( - (key) => `Client.${key}`, - ), - 'id', - ], - } - : { keys: [] } - - const fuse = new Fuse(filteredData, fuseOptions) - const results = fuse.search(searchTerm) - - const searchResults = - searchTerm !== '' ? results.map((result) => result.item) : filteredData - setSearchResults(searchResults) + const searchResults = searchTerm + ? filteredData.filter((app) => { + const clientName = app.Client?.Name?.toLowerCase() || '' + const owner = app.owner?.toLowerCase() || '' + const repo = app.repo?.toLowerCase() || '' + const searchLower = searchTerm.toLowerCase() + + return ( + clientName.includes(searchLower) || + owner.includes(searchLower) || + repo.includes(searchLower) + ) + }) + : filteredData + setSearchResults(searchResults) + }, 500) + + return () => { + clearTimeout(debounceTimeout) + } }, [searchTerm, filter, data, isLoading]) const handleRenewal = async (): Promise => {