From 7cb4e491ba0861f626a2a91e10bbf67bd3761a5b Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Sat, 16 Nov 2024 13:46:48 -0500 Subject: [PATCH] fix playground --- astro/components/playground/form.tsx | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/astro/components/playground/form.tsx b/astro/components/playground/form.tsx index f343596..a2e65e3 100644 --- a/astro/components/playground/form.tsx +++ b/astro/components/playground/form.tsx @@ -1,6 +1,6 @@ import WASM from '@/lib/wasm/wasm.js' import { ChevronDown, Loader2 } from 'lucide-react' -import { useCallback, useEffect, useMemo, useState } from 'react' +import { useCallback, useEffect, useState } from 'react' import { useForm } from 'react-hook-form' import ParsingResult, { type WASMResponse } from './result' import styles from './styles/form.module.css' @@ -14,19 +14,18 @@ const versions = ['2.9.2', '2.9.1', '2.9.0', '2.8.0'] function toJS(obj: Record): any { const result: Record = {} - for (const key of Object.keys(obj.__proto__)) { + for (const key in obj.__proto__) { result[key] = typeof obj[key] === 'object' ? toJS(obj[key]) : obj[key] } return result } export default function PlaygroundForm() { - //const router = useRouter() const { toast } = useToast() const { handleSubmit, register, formState } = useForm<{ url: string; version: string }>() const [output, setOutput] = useState() - const [defaultValue, setdefaultValue] = useState('') + const [defaultValue, setDefaultValue] = useState() const onSubmit = useCallback( async (data: { url: string; version: string }) => { try { @@ -52,12 +51,10 @@ export default function PlaygroundForm() { useEffect(() => { const searchParams = new URLSearchParams(window.location.search) const search = searchParams.get('url') - setdefaultValue(search ? decodeURI(search) : window.location.href) - }, []) - - useEffect(() => { - onSubmit({ url: defaultValue, version: versions[0] }) - }, [defaultValue, onSubmit]) + const value = search ? decodeURI(search) : window.location.href + setDefaultValue(value) + onSubmit({ url: value, version: versions.at(0) ?? '' }) + }, [onSubmit]) return (