diff --git a/src/components/IconButton.tsx b/src/components/IconButton.tsx new file mode 100644 index 0000000..e69de29 diff --git a/src/helpers/proxies.ts b/src/helpers/proxies.ts index d6993d5..e29381e 100644 --- a/src/helpers/proxies.ts +++ b/src/helpers/proxies.ts @@ -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, 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) } diff --git a/src/pages/Proxies.tsx b/src/pages/Proxies.tsx index 69370da..39373a3 100644 --- a/src/pages/Proxies.tsx +++ b/src/pages/Proxies.tsx @@ -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', diff --git a/src/pages/ProxyProvider.tsx b/src/pages/ProxyProvider.tsx index 092a877..d16115a 100644 --- a/src/pages/ProxyProvider.tsx +++ b/src/pages/ProxyProvider.tsx @@ -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 ( diff --git a/src/pages/Rules.tsx b/src/pages/Rules.tsx index 80da633..1245408 100644 --- a/src/pages/Rules.tsx +++ b/src/pages/Rules.tsx @@ -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 (