mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 04:26:57 +00:00
* Mutual Highlighting (#41) * Tidy up * Delete unused API route
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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()))
|
||||
})
|
||||
Reference in New Issue
Block a user