diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 146edde..a2ee778 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -33,4 +33,5 @@ export default { destination: 'Destination', close: 'Close', reset: 'Reset', + dnsQuery: 'DNS Query', } diff --git a/src/i18n/zh.ts b/src/i18n/zh.ts index 90e77ad..5f618ee 100644 --- a/src/i18n/zh.ts +++ b/src/i18n/zh.ts @@ -33,4 +33,5 @@ export default { destination: '目标地址', close: '关闭', reset: '重置', + dnsQuery: 'DNS 查询', } diff --git a/src/pages/Config.tsx b/src/pages/Config.tsx index 667838f..fd9813a 100644 --- a/src/pages/Config.tsx +++ b/src/pages/Config.tsx @@ -1,11 +1,66 @@ import { createForm } from '@felte/solid' import { validator } from '@felte/validator-zod' +import { useI18n } from '@solid-primitives/i18n' +import { makePersisted } from '@solid-primitives/storage' import { For, Show, createSignal, onMount } from 'solid-js' import { z } from 'zod' +import { PROXIES_PREVIEW_TYPE } from '~/config/enum' import { useRequest } from '~/signals' import type { DNSQuery, Config as IConfig } from '~/types' -const schema = z.object({ +const dnsQueryFormSchema = z.object({ + name: z.string(), + type: z.string(), +}) + +const DNSQueryForm = () => { + const [t] = useI18n() + const request = useRequest() + + const { form } = createForm>({ + extend: validator({ schema: dnsQueryFormSchema }), + onSubmit: async (values) => { + request + .get('dns/query', { + searchParams: { name: values.name, type: values.type }, + }) + .json() + .then(({ Answer }) => + setDNSQueryResult(Answer?.map(({ data }) => data) || []), + ) + }, + }) + + const [DNSQueryResult, setDNSQueryResult] = createSignal([]) + + return ( +
+
+ + + + + +
+ + 0}> +
+ + {(item) =>
{item}
} +
+
+
+
+ ) +} + +const configFormSchema = z.object({ port: z.number(), 'socks-port': z.number(), 'redir-port': z.number(), @@ -13,35 +68,9 @@ const schema = z.object({ 'mixed-port': z.number(), }) -import { makePersisted } from '@solid-primitives/storage' -import { PROXIES_PREVIEW_TYPE } from '~/config/enum' - -export const [proxiesPreviewType, setProxiesPreviewType] = makePersisted( - createSignal(PROXIES_PREVIEW_TYPE.BAR), - { - name: 'proxiesPreviewType', - storage: localStorage, - }, -) - -export default () => { +const ConfigForm = () => { const request = useRequest() - const [DNSQueryName, setDNSQueryName] = createSignal('') - const [DNSQueryResult, setDNSQueryResult] = createSignal([]) - - const onDNSQuery = () => - request - .get('dns/query', { - searchParams: { - name: DNSQueryName(), - }, - }) - .json() - .then(({ Answer }) => { - setDNSQueryResult(Answer.map(({ data }) => data)) - }) - const portsList = [ { label: 'Http Port', @@ -65,9 +94,9 @@ export default () => { }, ] - const { form, setInitialValues, reset } = createForm>({ - extend: validator({ schema }), - }) + const { form, setInitialValues, reset } = createForm< + z.infer + >({ extend: validator({ schema: configFormSchema }) }) onMount(async () => { const configs = await request.get('configs').json() @@ -78,35 +107,42 @@ export default () => { return (
-
{ - e.preventDefault() - onDNSQuery() - }} - > - setDNSQueryName(e.target.value)} - /> - - + + + {(item) => ( +
+ + +
+ )} +
+
+ ) +} - 0}> -
- - {(item) =>
{item}
} -
-
-
+export const [proxiesPreviewType, setProxiesPreviewType] = makePersisted( + createSignal(PROXIES_PREVIEW_TYPE.BAR), + { name: 'proxiesPreviewType', storage: localStorage }, +) -
+export default () => { + return ( +
+ + + + +
Proxies preview type:
+
- -
- - {(item) => ( -
- - -
- )} -
-
) } diff --git a/src/types.d.ts b/src/types.d.ts index f722b6f..2e8d58a 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,8 +1,7 @@ declare module 'solid-js' { namespace JSX { interface Directives { - form: {} - sortable: {} + [name: string]: {} } } } @@ -157,7 +156,7 @@ export type DNSQuery = { Qtype: number Qclass: number }[] - Answer: { + Answer?: { TTL: number data: string name: string