Skip to content
Merged
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
18 changes: 1 addition & 17 deletions frontend/src/components/GameSearch/GameSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}}
>
Expand Down
23 changes: 1 addition & 22 deletions frontend/src/utils/filterMatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}
Loading