mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 04:26:57 +00:00
1715b1646b
* Mutual Highlighting (#41) * Tidy up * Delete unused API route
25 lines
793 B
TypeScript
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()))
|
|
})
|