chore: rename func and fix params type

This commit is contained in:
Zephyruso 2023-09-04 18:17:19 +08:00
parent 1729329c58
commit 16cb0debb9
5 changed files with 21 additions and 12 deletions

View File

View File

@ -5,9 +5,9 @@ export const formatTimeFromNow = (time: number | string) => {
return dayjs(time).fromNow()
}
export const handlerBtnClickWithAnimate = async (
export const handleAnimatedBtnClickWithCallback = async (
event: MouseEvent,
cb: () => void,
callback: () => Promise<void>,
className = 'animate-spin',
) => {
let el = event.target as HTMLElement
@ -19,7 +19,7 @@ export const handlerBtnClickWithAnimate = async (
el.classList.add(className)
try {
await cb()
await callback()
} catch {}
el.classList.remove(className)
}

View File

@ -9,7 +9,7 @@ import {
ProxyNodePreview,
} from '~/components'
import {
handlerBtnClickWithAnimate,
handleAnimatedBtnClickWithCallback,
sortProxiesByOrderingType,
} from '~/helpers'
import { proxiesOrderingType, useProxies } from '~/signals'
@ -33,7 +33,7 @@ export default () => {
}
const onSpeedTestClick = (e: MouseEvent, name: string) => {
handlerBtnClickWithAnimate(
handleAnimatedBtnClickWithCallback(
e,
latencyTestByProxyGroupName.bind(null, name),
'animate-pulse',

View File

@ -11,7 +11,7 @@ import {
} from '~/components'
import {
formatTimeFromNow,
handlerBtnClickWithAnimate,
handleAnimatedBtnClickWithCallback,
sortProxiesByOrderingType,
} from '~/helpers'
import { proxiesOrderingType, useProxies } from '~/signals'
@ -31,7 +31,7 @@ export default () => {
)
const onHealthCheckClick = (e: MouseEvent, name: string) => {
handlerBtnClickWithAnimate(
handleAnimatedBtnClickWithCallback(
e,
healthCheckByProviderName.bind(null, name),
'animate-pulse',
@ -39,11 +39,14 @@ export default () => {
}
const onUpdateProviderClick = (e: MouseEvent, name: string) => {
handlerBtnClickWithAnimate(e, updateProviderByProviderName.bind(null, name))
handleAnimatedBtnClickWithCallback(
e,
updateProviderByProviderName.bind(null, name),
)
}
const onUpdateAllProviderClick = (e: MouseEvent) => {
handlerBtnClickWithAnimate(e, updateAllProvider)
handleAnimatedBtnClickWithCallback(e, updateAllProvider)
}
return (

View File

@ -3,7 +3,10 @@ import { IconReload } from '@tabler/icons-solidjs'
import InfiniteScroll from 'solid-infinite-scroll'
import { For, Show, createMemo, createSignal, onMount } from 'solid-js'
import { Button } from '~/components'
import { formatTimeFromNow, handlerBtnClickWithAnimate } from '~/helpers'
import {
formatTimeFromNow,
handleAnimatedBtnClickWithCallback,
} from '~/helpers'
import { useRules } from '~/signals'
export default () => {
@ -21,11 +24,14 @@ export default () => {
onMount(updateRules)
const onUpdateProviderClick = (e: MouseEvent, name: string) => {
handlerBtnClickWithAnimate(e, updateRuleProviderByName.bind(null, name))
handleAnimatedBtnClickWithCallback(
e,
updateRuleProviderByName.bind(null, name),
)
}
const onUpdateAllProviderClick = (e: MouseEvent) => {
handlerBtnClickWithAnimate(e, updateAllRuleProvider)
handleAnimatedBtnClickWithCallback(e, updateAllRuleProvider)
}
return (