refactor: dns query button

This commit is contained in:
kunish 2023-09-03 02:22:38 +08:00
parent 8e5654332d
commit 737378ac74
No known key found for this signature in database
GPG Key ID: 647A12B4F782C430
2 changed files with 18 additions and 17 deletions

View File

@ -2,9 +2,7 @@ import { JSX, ParentComponent, Show, splitProps } from 'solid-js'
import { twMerge } from 'tailwind-merge'
export const Button: ParentComponent<
JSX.HTMLAttributes<HTMLButtonElement> & {
loading?: boolean
}
JSX.ButtonHTMLAttributes<HTMLButtonElement> & { loading?: boolean }
> = (props) => {
const [local, others] = splitProps(props, ['class', 'loading'])

View File

@ -35,19 +35,21 @@ const DNSQueryForm = () => {
const [t] = useI18n()
const request = useRequest()
const { form } = createForm<z.infer<typeof dnsQueryFormSchema>>({
extend: validator({ schema: dnsQueryFormSchema }),
onSubmit: async (values) => {
request
.get('dns/query', {
searchParams: { name: values.name, type: values.type },
})
.json<DNSQuery>()
.then(({ Answer }) =>
setDNSQueryResult(Answer?.map(({ data }) => data) || []),
)
const { form, isSubmitting } = createForm<z.infer<typeof dnsQueryFormSchema>>(
{
extend: validator({ schema: dnsQueryFormSchema }),
onSubmit: async (values) => {
request
.get('dns/query', {
searchParams: { name: values.name, type: values.type },
})
.json<DNSQuery>()
.then(({ Answer }) =>
setDNSQueryResult(Answer?.map(({ data }) => data) || []),
)
},
},
})
)
const [DNSQueryResult, setDNSQueryResult] = createSignal<string[]>([])
@ -64,9 +66,10 @@ const DNSQueryForm = () => {
<option>AAAA</option>
<option>MX</option>
</select>
<button type="submit" class="btn btn-primary">
<Button type="submit" class="btn-primary" loading={isSubmitting()}>
{t('dnsQuery')}
</button>
</Button>
</div>
</form>