mirror of
https://github.com/woodchen-ink/clash-and-dashboard.git
synced 2025-07-18 14:01:56 +08:00
Feature: provider order
This commit is contained in:
parent
9cfd15b40a
commit
38dbc341c8
@ -1,9 +1,11 @@
|
|||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
|
import { useMemo } from 'react'
|
||||||
import { Card, Tag, Icon, Loading, useLoading } from '@components'
|
import { Card, Tag, Icon, Loading, useLoading } from '@components'
|
||||||
import { containers } from '@stores'
|
import { containers } from '@stores'
|
||||||
import { fromNow } from '@lib/date'
|
import { fromNow } from '@lib/date'
|
||||||
import { Provider as IProvider, Proxy as IProxy, updateProvider, healthCheckProvider } from '@lib/request'
|
import { Provider as IProvider, Proxy as IProxy, updateProvider, healthCheckProvider } from '@lib/request'
|
||||||
import { Proxy } from '../Proxy'
|
import { Proxy } from '../Proxy'
|
||||||
|
import { compareDesc } from '../../'
|
||||||
import './style.scss'
|
import './style.scss'
|
||||||
|
|
||||||
interface ProvidersProps {
|
interface ProvidersProps {
|
||||||
@ -29,6 +31,10 @@ export function Provider (props: ProvidersProps) {
|
|||||||
updateProvider(provider.name).then(() => fetch()).finally(() => hide())
|
updateProvider(provider.name).then(() => fetch()).finally(() => hide())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const proxies = useMemo(() => {
|
||||||
|
return (provider.proxies as IProxy[]).slice().sort((a, b) => -1 * compareDesc(a, b))
|
||||||
|
}, [provider.proxies])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="proxy-provider">
|
<Card className="proxy-provider">
|
||||||
<Loading visible={visible} />
|
<Loading visible={visible} />
|
||||||
@ -48,7 +54,7 @@ export function Provider (props: ProvidersProps) {
|
|||||||
</div>
|
</div>
|
||||||
<ul className="proxies-list">
|
<ul className="proxies-list">
|
||||||
{
|
{
|
||||||
provider.proxies.map((p: IProxy) => (
|
proxies.map((p: IProxy) => (
|
||||||
<li key={p.name}>
|
<li key={p.name}>
|
||||||
<Proxy className="proxy-provider-item" config={p} />
|
<Proxy className="proxy-provider-item" config={p} />
|
||||||
</li>
|
</li>
|
||||||
|
@ -21,7 +21,7 @@ const sortMap = {
|
|||||||
[sortType.Desc]: 'sort-descending'
|
[sortType.Desc]: 'sort-descending'
|
||||||
}
|
}
|
||||||
|
|
||||||
function compareDesc (a: API.Proxy, b: API.Proxy) {
|
export function compareDesc (a: API.Proxy, b: API.Proxy) {
|
||||||
const lastDelayA = a.history.length ? a.history.slice(-1)[0].delay : 0
|
const lastDelayA = a.history.length ? a.history.slice(-1)[0].delay : 0
|
||||||
const lastDelayB = b.history.length ? b.history.slice(-1)[0].delay : 0
|
const lastDelayB = b.history.length ? b.history.slice(-1)[0].delay : 0
|
||||||
return (lastDelayB || Number.MAX_SAFE_INTEGER) - (lastDelayA || Number.MAX_SAFE_INTEGER)
|
return (lastDelayB || Number.MAX_SAFE_INTEGER) - (lastDelayA || Number.MAX_SAFE_INTEGER)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user