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 | 110 +++++++++++++++++++++++------------- src/signals/proxies.ts | 2 +- src/signals/rules.ts | 46 +++++++++++++++ 5 files changed, 122 insertions(+), 44 deletions(-) create mode 100644 src/signals/rules.ts diff --git a/src/pages/Proxies.tsx b/src/pages/Proxies.tsx index cd3577a..752683f 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 1101189..4c51994 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 fe70bf1..55d066c 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 0000000..426dc6f --- /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, + } +}