From 16cb0debb9b19384b149adf5c974bf4e4c560870 Mon Sep 17 00:00:00 2001 From: Zephyruso <127948745+Zephyruso@users.noreply.github.com> Date: Mon, 4 Sep 2023 18:17:19 +0800 Subject: [PATCH] chore: rename func and fix params type --- src/components/IconButton.tsx | 0 src/helpers/proxies.ts | 6 +++--- src/pages/Proxies.tsx | 4 ++-- src/pages/ProxyProvider.tsx | 11 +++++++---- src/pages/Rules.tsx | 12 +++++++++--- 5 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 src/components/IconButton.tsx 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 (