import {addNTimes, PlayableLetterData} from "./utils"; import {useEffect, useState} from "react"; import {Modal} from "./Modal"; import {Letter as LetterData} from "word_grid"; import * as React from "react"; export function TileExchangeModal(props: { playerLetters: PlayableLetterData[], isOpen: boolean, setOpen: (isOpen: boolean) => void, exchangeFunction: (selectedArray: Array) => void }) { function clearExchangeTiles() { const array: boolean[] = []; addNTimes(array, false, props.playerLetters.length); return array; } const [tilesToExchange, setTilesToExchange] = useState(clearExchangeTiles); useEffect(() => { setTilesToExchange(clearExchangeTiles()); }, [props.playerLetters]) let tilesExchangedSelected = 0; for (let i of tilesToExchange) { if(i) { tilesExchangedSelected++; } } return { setTilesToExchange(clearExchangeTiles()); props.setOpen(isOpen); }}>
Click on each tile you'd like to exchange. You currently have {tilesExchangedSelected} tiles selected.
; } function TilesExchangedTray(props: { tray: Array, trayLength: number, selectedArray: Array, setSelectedArray: (x: Array) => void, }){ const divContent = []; for(let i=0; i); // empty tile elements } for(let i = 0; i { props.selectedArray[i] = !props.selectedArray[i]; props.setSelectedArray(props.selectedArray.slice()); } if(tileData != null){ divContent[tileData.index] = ; } } return
{divContent}
; } function DummyExchangeTile(props: { letter: LetterData, isSelected: boolean, onClick: () => void, }){ let textClassName = "text"; if(props.letter.is_blank) { textClassName += " prev-blank"; } let letterClassName = "letter"; if(props.isSelected){ letterClassName += ' selected-tile'; } return
{props.letter.text}
{props.letter.points}
; }