import { Input } from '@heroui/input' import { useEffect, useState } from 'react' import { Controller, useForm } from 'react-hook-form' import toast from 'react-hot-toast' import SaveButtons from '@/components/button/save_buttons' import PageLoading from '@/components/page_loading' import SwitchCard from '@/components/switch_card' import useConfig from '@/hooks/use-config' const OneBotConfigCard = () => { const { config, saveConfigWithoutNetwork, refreshConfig } = useConfig() const [loading, setLoading] = useState(false) const { control, handleSubmit: handleOnebotSubmit, formState: { isSubmitting }, setValue: setOnebotValue } = useForm({ defaultValues: { musicSignUrl: '', enableLocalFile2Url: false, parseMultMsg: false } }) const reset = () => { setOnebotValue('musicSignUrl', config.musicSignUrl) setOnebotValue('enableLocalFile2Url', config.enableLocalFile2Url) setOnebotValue('parseMultMsg', config.parseMultMsg) } const onSubmit = handleOnebotSubmit(async (data) => { try { await saveConfigWithoutNetwork(data) toast.success('保存成功') } catch (error) { const msg = (error as Error).message toast.error(`保存失败: ${msg}`) } }) const onRefresh = async (shotTip = true) => { try { setLoading(true) await refreshConfig() if (shotTip) toast.success('刷新成功') } catch (error) { const msg = (error as Error).message toast.error(`刷新失败: ${msg}`) } finally { setLoading(false) } } useEffect(() => { reset() }, [config]) useEffect(() => { onRefresh(false) }, []) if (loading) return return ( <> OneBot配置 - NapCat WebUI ( )} /> ( )} /> ( )} /> ) } export default OneBotConfigCard