import { createPortal } from "react-dom"; import React, { useCallback, useState, useRef } from "react"; import { useDispatch } from "react-redux"; import useSWRImmutable from "swr/immutable"; import AddModData from "./AddModData"; import SearchBar from "./SearchBar"; import { jsonFetcher } from "../lib/api"; import { updateFetchedPlugin, PluginsByHashWithMods } from "../slices/plugins"; import styles from "../styles/AddModDialog.module.css"; type Props = { counts: Record | null; }; const AddModDialog: React.FC = ({ counts }) => { const [selectedMod, setSelectedMod] = useState(null); const [selectedPlugin, setSelectedPlugin] = useState(null); const [dialogShown, setDialogShown] = useState(false); const searchInput = useRef(null); const dispatch = useDispatch(); const { data, error } = useSWRImmutable( selectedPlugin ? `https://plugins.modmapper.com/${selectedPlugin}.json` : null, (_) => jsonFetcher(_) ); const onAddModButtonClick = useCallback(async () => { setSelectedMod(null); setDialogShown(true); requestAnimationFrame(() => { if (searchInput.current) searchInput.current.focus(); }); }, [setSelectedMod, setDialogShown]); return ( <> {typeof window !== "undefined" && createPortal(

Add mod

{ if (selectedItem) { setSelectedMod(selectedItem.id); } }} inputRef={searchInput} /> {selectedMod && ( )}
, document.body )} ); }; export default AddModDialog;