From 65346ca743bf823da841d73c1f31022b1292c53a Mon Sep 17 00:00:00 2001 From: Zephyruso <127948745+Zephyruso@users.noreply.github.com> Date: Sat, 2 Sep 2023 17:42:13 +0800 Subject: [PATCH] feat: rules provider pages --- src/pages/Proxies.tsx | 4 +- src/pages/ProxyProvider.tsx | 4 +- src/pages/Rules.tsx | 106 +++++++++++++++++++++++------------- src/signals/proxies.ts | 2 +- src/signals/rules.ts | 46 ++++++++++++++++ 5 files changed, 120 insertions(+), 42 deletions(-) create mode 100644 src/signals/rules.ts diff --git a/src/pages/Proxies.tsx b/src/pages/Proxies.tsx index cd3577a8..752683fd 100644 --- a/src/pages/Proxies.tsx +++ b/src/pages/Proxies.tsx @@ -32,7 +32,9 @@ export default () => { return (
-

{t('proxies')}

+

+ {t('proxies')} +

{ const title = ( diff --git a/src/pages/ProxyProvider.tsx b/src/pages/ProxyProvider.tsx index 11011894..4c519941 100644 --- a/src/pages/ProxyProvider.tsx +++ b/src/pages/ProxyProvider.tsx @@ -51,7 +51,7 @@ export default () => { return (
-

+

{t('proxyProviders')} +

-
{(rulesProvider) => ( -
-
{rulesProvider.name}
+
+
+ {rulesProvider.name} +
+ +
+
{rulesProvider.vehicleType} :: {rulesProvider.behavior} ( {rulesProvider.ruleCount}) @@ -65,7 +95,7 @@ export default () => { )}
-
+
) } diff --git a/src/signals/proxies.ts b/src/signals/proxies.ts index fe70bf1a..55d066c0 100644 --- a/src/signals/proxies.ts +++ b/src/signals/proxies.ts @@ -85,7 +85,7 @@ export function useProxies() { proxyGroup.now = proxyName setProxies(proxyGroupList) - queueMicrotask(updateProxy) + // queueMicrotask(updateProxy) } const delayTestByProxyGroupName = async (proxyGroupName: string) => { diff --git a/src/signals/rules.ts b/src/signals/rules.ts new file mode 100644 index 00000000..426dc6f7 --- /dev/null +++ b/src/signals/rules.ts @@ -0,0 +1,46 @@ +import { createSignal } from 'solid-js' +import { useRequest } from '~/signals' +import type { Rule, RuleProvider } from '~/types' + +const request = useRequest() + +export const useRules = () => { + const [rules, setRules] = createSignal([]) + const [rulesProviders, setRulesProviders] = createSignal([]) + + const updateRules = async () => { + const { rules } = await request + .get('rules') + .json<{ rules: Record }>() + + setRules(Object.values(rules)) + + const { providers } = await request + .get('providers/rules') + .json<{ providers: Record }>() + + setRulesProviders(Object.values(providers)) + } + + const updateAllRuleProvider = async () => { + await Promise.all( + rulesProviders().map((provider) => { + return request.put(`providers/rules/${provider.name}`) + }), + ) + await updateRules() + } + + const updateRuleProviderByName = async (name: string) => { + await request.put(`providers/rules/${name}`) + await updateRules() + } + + return { + rules, + rulesProviders, + updateRules, + updateAllRuleProvider, + updateRuleProviderByName, + } +}