feat: update provider && rule pages style

This commit is contained in:
Zephyruso 2023-08-31 10:50:43 +08:00
parent 4c271d9e68
commit c0fee9d929
4 changed files with 48 additions and 14 deletions

View File

@ -55,7 +55,7 @@ export default (props: {
<div class="flex items-center justify-between gap-1"> <div class="flex items-center justify-between gap-1">
<div class="truncate text-xs text-slate-500"> <div class="truncate text-xs text-slate-500">
{formatProxyType(proxyNode().type)} {formatProxyType(proxyNode().type)}
{proxyNode().udp ? ' :: udp' : ''} {proxyNode().udp && ' :: udp'}
</div> </div>
<div class="text-xs">{Delay(proxyName)}</div> <div class="text-xs">{Delay(proxyName)}</div>
</div> </div>

View File

@ -1,4 +1,4 @@
import { IconBrandSpeedtest } from '@tabler/icons-solidjs' import { IconBrandSpeedtest, IconReload } from '@tabler/icons-solidjs'
import { For, createSignal, onMount } from 'solid-js' import { For, createSignal, onMount } from 'solid-js'
import Collapse from '~/components/Collpase' import Collapse from '~/components/Collpase'
import ProxyNodeCard from '~/components/ProxyNodeCard' import ProxyNodeCard from '~/components/ProxyNodeCard'
@ -10,8 +10,9 @@ export default () => {
proxies, proxies,
proxyProviders, proxyProviders,
updateProxy, updateProxy,
setProxiesByProxyName, setProxyGroupByProxyName,
delayTestByProxyGroupName, delayTestByProxyGroupName,
updateProxyProviderByProviderName,
} = useProxies() } = useProxies()
const [collapsedMap, setCollapsedMap] = createSignal<Record<string, boolean>>( const [collapsedMap, setCollapsedMap] = createSignal<Record<string, boolean>>(
@ -23,7 +24,7 @@ export default () => {
}) })
const onProxyNodeClick = async (proxy: Proxy, proxyName: string) => { const onProxyNodeClick = async (proxy: Proxy, proxyName: string) => {
setProxiesByProxyName(proxy, proxyName) setProxyGroupByProxyName(proxy, proxyName)
} }
const onSpeedTestClick = (e: MouseEvent, name: string) => { const onSpeedTestClick = (e: MouseEvent, name: string) => {
@ -31,6 +32,11 @@ export default () => {
delayTestByProxyGroupName(name) delayTestByProxyGroupName(name)
} }
const onUpdateProviderClick = (e: MouseEvent, name: string) => {
e.stopPropagation()
updateProxyProviderByProviderName(name)
}
return ( return (
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
<div> <div>
@ -94,7 +100,27 @@ export default () => {
<div class="grid grid-cols-1 gap-2 sm:grid-cols-2"> <div class="grid grid-cols-1 gap-2 sm:grid-cols-2">
<For each={proxyProviders()}> <For each={proxyProviders()}>
{(proxyProvider) => { {(proxyProvider) => {
const title = <>{proxyProvider.name}</> const title = (
<div class="flex items-center justify-between">
<div class="flex flex-col">
<span>{proxyProvider.name}</span>
<div class="text-sm text-slate-500">
{proxyProvider.vehicleType} :: Updated at{' '}
{new Date(proxyProvider.updatedAt).toLocaleString()}
</div>
</div>
<button
class="btn btn-circle btn-sm"
onClick={(e) =>
onUpdateProviderClick(e, proxyProvider.name)
}
>
<IconReload />
</button>
</div>
)
const content = ( const content = (
<For each={proxyProvider.proxies}> <For each={proxyProvider.proxies}>
{(proxy) => <ProxyNodeCard proxyName={proxy.name} />} {(proxy) => <ProxyNodeCard proxyName={proxy.name} />}

View File

@ -26,13 +26,13 @@ export default () => {
<div> <div>
<h1 class="pb-4 text-lg font-semibold">Rules</h1> <h1 class="pb-4 text-lg font-semibold">Rules</h1>
<div class="grid grid-cols-2 gap-2 sm:grid-cols-1"> <div class="grid grid-cols-1 gap-2 sm:grid-cols-1">
<For each={rules()}> <For each={rules()}>
{(rule) => ( {(rule) => (
<div class="card card-bordered card-compact border-secondary p-4"> <div class="card card-bordered card-compact border-secondary p-4">
<div>{rule.payload}</div> <div class="break-all">{rule.payload}</div>
<div> <div class="text-xs text-slate-500">
{rule.type}: {rule.proxy} {rule.type} :: {rule.proxy}
</div> </div>
</div> </div>
)} )}
@ -43,13 +43,13 @@ export default () => {
<div> <div>
<h1 class="pb-4 text-lg font-semibold">Rules Providers</h1> <h1 class="pb-4 text-lg font-semibold">Rules Providers</h1>
<div class="grid grid-cols-2 gap-2 sm:grid-cols-1"> <div class="grid grid-cols-1 gap-2 sm:grid-cols-1">
<For each={rulesProviders()}> <For each={rulesProviders()}>
{(rulesProvider) => ( {(rulesProvider) => (
<div class="card card-bordered card-compact border-secondary p-4"> <div class="card card-bordered card-compact border-secondary p-4">
<div>{rulesProvider.name}</div> <div>{rulesProvider.name}</div>
<div> <div class="text-xs text-slate-500">
{rulesProvider.vehicleType}: {rulesProvider.behavior} ( {rulesProvider.vehicleType} :: {rulesProvider.behavior} (
{rulesProvider.ruleCount}) {rulesProvider.ruleCount})
</div> </div>
</div> </div>

View File

@ -50,7 +50,7 @@ export function useProxies() {
) )
} }
const setProxiesByProxyName = async (proxy: Proxy, proxyName: string) => { const setProxyGroupByProxyName = async (proxy: Proxy, proxyName: string) => {
await request.put(`proxies/${proxy.name}`, { await request.put(`proxies/${proxy.name}`, {
body: JSON.stringify({ body: JSON.stringify({
name: proxyName, name: proxyName,
@ -74,6 +74,13 @@ export function useProxies() {
setDelayMap({ ...dMap }) setDelayMap({ ...dMap })
} }
const updateProxyProviderByProviderName = async (
proxyProviderName: string,
) => {
await request.put(`/providers/proxies/${proxyProviderName}`)
await updateProxy()
}
return { return {
proxies, proxies,
proxyProviders, proxyProviders,
@ -81,6 +88,7 @@ export function useProxies() {
proxyNodeMap, proxyNodeMap,
delayMap, delayMap,
updateProxy, updateProxy,
setProxiesByProxyName, setProxyGroupByProxyName,
updateProxyProviderByProviderName,
} }
} }