Files
echecsfrance/app/atoms.ts
T
Timothy Armes 1715b1646b Mutual Highlighting (#41) (#55)
* Mutual Highlighting (#41)

* Tidy up

* Delete unused API route
2023-07-05 13:55:56 +02:00

25 lines
793 B
TypeScript

import { Tournament } from '@/types';
import { atom } from 'jotai';
import atomWithDebounce from "@/utils/atomWithDebounce";
export const tournamentsAtom = atom<Tournament[]>([]);
export const searchStringAtom = atom('');
export const {
currentValueAtom: hoveredMapTournamentIdAtom,
debouncedValueAtom: debouncedHoveredMapTournamentIdAtom,
} = atomWithDebounce<string | null>(null);
export const {
debouncedValueAtom: debouncedHoveredListTournamentIdAtom,
} = atomWithDebounce<string | null>(null);
export const filteredTournamentsAtom = atom((get) => {
const tournaments = get(tournamentsAtom);
const searchString = get(searchStringAtom).trim();
if (searchString === '') return tournaments;
return tournaments.filter((t) => t.town.includes(searchString.toUpperCase()))
})