more intuitive game loading (#13)

* faster game laoding without need for add button
This commit is contained in:
titanium_machine
2025-05-03 16:44:53 +02:00
committed by GitHub
parent fb88d3b8b2
commit d14ac15dca
3 changed files with 43 additions and 18 deletions

View File

@@ -15,9 +15,11 @@ import { useEffect, useState } from "react";
interface Props {
pgn: string;
setPgn: (pgn: string) => void;
/** Called when a game is selected; if provided, bypasses manual 'Add' */
onSelect?: (pgn: string) => void;
}
export default function LichessInput({ pgn, setPgn }: Props) {
export default function LichessInput({ pgn, setPgn, onSelect }: Props) {
const [requestCount, setRequestCount] = useState(0);
const [lichessUsername, setLichessUsername] = useLocalStorage(
"lichess-username",
@@ -68,7 +70,14 @@ export default function LichessInput({ pgn, setPgn }: Props) {
>
{games.map((game) => (
<ListItemButton
onClick={() => setPgn(game.pgn)}
onClick={() => {
const selectedPgn: string = game.pgn;
if (onSelect) {
onSelect(selectedPgn);
} else {
setPgn(selectedPgn);
}
}}
selected={pgn === game.pgn}
style={{ width: 350, maxWidth: 350 }}
key={game.id}