From 1e09af45bb23f5afc50f9585f07d30860b0243ab Mon Sep 17 00:00:00 2001 From: Johannes Bortne Date: Fri, 27 Nov 2026 08:37:33 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20fjern=20filter=20ved=20n=C3=B8yaktig=20t?= =?UTF-8?q?reff=20p=C3=A5=20Enter=20i=20s=C3=B8kefeltet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/GameSearch/GameSearch.tsx | 18 +-------------- frontend/src/utils/filterMatches.ts | 23 +------------------ 2 files changed, 2 insertions(+), 39 deletions(-) diff --git a/frontend/src/components/GameSearch/GameSearch.tsx b/frontend/src/components/GameSearch/GameSearch.tsx index 8c8651d1..f4dbb392 100644 --- a/frontend/src/components/GameSearch/GameSearch.tsx +++ b/frontend/src/components/GameSearch/GameSearch.tsx @@ -3,11 +3,7 @@ import { useQuery } from '@apollo/client/react'; import { useDebounce } from '../../hooks/useDebounce'; import { SEARCH_SUGGESTIONS, type Suggestion } from '../../graphql/searchSuggestions'; import { FILTER_OPTIONS } from '../../graphql/filterOptions'; -import { - findExactFilterMatch, - findFilterMatches, - type FilterMatch, -} from '../../utils/filterMatches'; +import { findFilterMatches, type FilterMatch } from '../../utils/filterMatches'; import './GameSearch.css'; import { useIsPhone } from '../../hooks/useIsPhone'; @@ -220,18 +216,6 @@ export function GameSearch({ e.preventDefault(); setOpen(false); if (isPhone) inputRef.current?.blur(); - // Er teksten nøyaktig navnet eller et kallenavn på én sjanger eller plattform - // (f.eks. "playstation" eller "ps5"), filtreres det på den i stedet for å søke - // etter teksten i spillnavnene. Ellers vanlig søk - const exact = - onSelectFilter && filterOptions - ? findExactFilterMatch(input, filterOptions.genres, filterOptions.platforms) - : null; - if (exact) { - setInput(''); - onSelectFilter?.(exact); - return; - } onSearch(input.trim(), true); }} > diff --git a/frontend/src/utils/filterMatches.ts b/frontend/src/utils/filterMatches.ts index 32f18af0..dea282f4 100644 --- a/frontend/src/utils/filterMatches.ts +++ b/frontend/src/utils/filterMatches.ts @@ -124,25 +124,4 @@ export function findFilterMatches( .sort((a, b) => a.rank - b.rank) .slice(0, max) .map(({ kind, id, name }) => ({ kind, id, name })); -} - -/** - * Filteret teksten treffer nøyaktig, altså hele navnet eller et helt kallenavn. Brukes når - * man trykker Enter uten å velge et forslag. null hvis ingen treffer nøyaktig, eller hvis - * flere gjør det (f.eks. "konsoll" eller "mobil"), siden det da ikke er klart hvilket som menes - */ -export function findExactFilterMatch( - term: string, - genres: Facet[], - platforms: Facet[], -): FilterMatch | null { - const q = term.trim().toLowerCase(); - if (q.length < MIN_CHARS) return null; - const exact = [ - ...matchFacets(q, 'genre', genres, GENRE_ALIASES), - ...matchFacets(q, 'platform', platforms, PLATFORM_ALIASES), - ].filter((hit) => hit.rank === 0); - if (exact.length !== 1) return null; - const { kind, id, name } = exact[0]; - return { kind, id, name }; -} +} \ No newline at end of file