import GameDto from "Frontend/generated/org/gameyfin/app/games/dto/GameDto"; import {Button, Image, Input, Modal, ModalBody, ModalContent, ModalHeader, ScrollShadow} from "@heroui/react"; import React, {useEffect, useState} from "react"; import GameSearchResultDto from "Frontend/generated/org/gameyfin/app/games/dto/GameSearchResultDto"; import {GameEndpoint} from "Frontend/generated/endpoints"; import {ArrowRight, MagnifyingGlass} from "@phosphor-icons/react"; import PluginIcon from "Frontend/components/general/plugin/PluginIcon"; import {useSnapshot} from "valtio/react"; import {pluginState} from "Frontend/state/PluginState"; import PluginDto from "Frontend/generated/org/gameyfin/app/core/plugins/dto/PluginDto"; interface GameCoverPickerModalProps { game: GameDto; isOpen: boolean; onOpenChange: () => void; setCoverUrl: (url: string) => void; } export function GameCoverPickerModal({game, isOpen, onOpenChange, setCoverUrl}: GameCoverPickerModalProps) { const [coverUrl, setCoverUrlState] = useState(""); const [searchTerm, setSearchTerm] = useState(game.title); const [searchResults, setSearchResults] = useState([]); const [isSearching, setIsSearching] = useState(false); const state = useSnapshot(pluginState).state; useEffect(() => { if (isOpen && searchTerm.length > 0 && searchResults.length === 0) { search(); } }, [isOpen]); async function search() { setIsSearching(true); const results = await GameEndpoint.getPotentialMatches(searchTerm); let validResults = results.filter(result => result.coverUrls && result.coverUrls.length > 0); setSearchResults(validResults); setIsSearching(false); } return ( {(onClose) => { return (<> Enter a URL or search for a cover
setCoverUrlState("")} />
{ if (e.key === "Enter") { e.preventDefault(); await search(); } }} />
{searchResults.length === 0 && !isSearching &&

No results found.

} {searchResults.length === 0 && isSearching &&

Searching...

} {searchResults.flatMap(result => { if (!result.coverUrls) return []; return result.coverUrls.map((url, idx) => ({ id: `${result.id}-${idx}`, title: result.title, url: url.url, source: url.pluginId })) }).map(cover => (
{ setCoverUrl(cover.url); onOpenChange(); }} > {cover.title}

{cover.title}

))}
) }}
); }