import type { FormEvent } from "react"; import { toast } from "react-toastify"; import { useLichess } from "#/hooks/useLichess.ts"; interface IProps { setSelectedStudyId: (id: string) => void; } const LichessStudyLinkInput = ({ setSelectedStudyId }: IProps) => { const { parseLichessStudyLink } = useLichess(); const handleSubmit = (e: FormEvent) => { e.preventDefault(); const formData = new FormData(e.currentTarget); const studyLink = formData.get("lichess-study-link"); if (!studyLink) return; if (typeof studyLink !== "string") { toast.error("Invalid study link"); return; } const result = parseLichessStudyLink(studyLink); if (!result.ok) { toast.error(result.error); return; } console.log(result.data); setSelectedStudyId(result.data); toast.success("Study loaded — pick a chapter"); }; return (
); }; export default LichessStudyLinkInput;