import { Game, GameGroup } from "@/types/stellaris"; import { Dropdown } from "@nextui-org/react"; import { Dispatch, Key, SetStateAction, Suspense } from "react"; import { fetchGameGroups } from "@/components/server/fetchers"; type SelectionType = "all" | Set; export const GameGroupSelect = ( props: { game: Game, groups: [GameGroup[], Dispatch>>], currentGroups: [GameGroup[], Dispatch>>] }) => { const currentGame = props.game; const [gameGroups, setGameGroups] = props.groups; const [currentGameGroups, setCurrentGameGroups] = props.currentGroups; const changeSelection = (keys: SelectionType) => { if (keys != "all") { let newSelection: GameGroup[] = []; keys.forEach(key => { gameGroups.forEach(group => { if (key == group.name) { newSelection.push(group); } }) }); setCurrentGameGroups(newSelection) } } return ( <> {currentGameGroups.map(elem => elem.name).join(", ")} elem.name)} onSelectionChange={changeSelection} items={gameGroups} > {gameGroups.map((item) => ( {item.name} ))} ) } const DataHandler = async ( props: { game: Game, groups: [GameGroup[], Dispatch>>], currentGroups: [GameGroup[], Dispatch>>] }) => { if (props) { const currentGame = props.game; const [gameGroups, setGameGroups] = props.groups; const [currentGameGroups, setCurrentGameGroups] = props.currentGroups; if (!gameGroups[0] || gameGroups[0].game_id != currentGame.id) { setGameGroups(await fetchGameGroups(currentGame)); } else if (!currentGameGroups[0] || currentGameGroups[0].game_id != gameGroups[0].game_id) { setCurrentGameGroups(gameGroups); } } return <> }