Skip to content

Commit

Permalink
fix: btn animate
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso authored and Zephyruso committed Sep 2, 2023
1 parent 5d43ea0 commit a29e638
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/pages/Proxies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ProxyCardGroups from '~/components/ProxyCardGroups'
import ProxyNodePreview from '~/components/ProxyNodePreview'
import { useProxies } from '~/signals/proxies'
import type { Proxy } from '~/types'
import { getBtnElFromClickEvent } from '~/utils/proxies'

export default () => {
const [t] = useI18n()
Expand All @@ -22,7 +23,7 @@ export default () => {
}

const onSpeedTestClick = async (e: MouseEvent, name: string) => {
const el = e.target as HTMLElement
const el = getBtnElFromClickEvent(e)

el.classList.add('animate-pulse')
e.stopPropagation()
Expand Down
8 changes: 4 additions & 4 deletions src/pages/ProxyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ProxyCardGroups from '~/components/ProxyCardGroups'
import ProxyNodePreview from '~/components/ProxyNodePreview'
import SubscriptionInfo from '~/components/SubscriptionInfo'
import { useProxies } from '~/signals/proxies'
import { formatTimeFromNow } from '~/utils/proxies'
import { formatTimeFromNow, getBtnElFromClickEvent } from '~/utils/proxies'

export default () => {
const [t] = useI18n()
Expand All @@ -23,7 +23,7 @@ export default () => {
)

const onHealthCheckClick = async (e: MouseEvent, name: string) => {
const el = e.target as HTMLElement
const el = getBtnElFromClickEvent(e)

el.classList.add('animate-pulse')
e.stopPropagation()
Expand All @@ -32,7 +32,7 @@ export default () => {
}

const onUpdateProviderClick = async (e: MouseEvent, name: string) => {
const el = e.target as HTMLElement
const el = getBtnElFromClickEvent(e)

el.classList.add('animate-spin')
e.stopPropagation()
Expand All @@ -41,7 +41,7 @@ export default () => {
}

const onUpdateAllProviderClick = async (e: MouseEvent) => {
const el = e.target as HTMLElement
const el = getBtnElFromClickEvent(e)

el.classList.add('animate-spin')
e.stopPropagation()
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Rules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IconReload } from '@tabler/icons-solidjs'
import InfiniteScroll from 'solid-infinite-scroll'
import { For, Show, createMemo, createSignal, onMount } from 'solid-js'
import { useRules } from '~/signals/rules'
import { formatTimeFromNow } from '~/utils/proxies'
import { formatTimeFromNow, getBtnElFromClickEvent } from '~/utils/proxies'

export default () => {
const [t] = useI18n()
Expand All @@ -22,7 +22,7 @@ export default () => {
})

const onUpdateProviderClick = async (e: MouseEvent, name: string) => {
const el = e.target as HTMLElement
const el = getBtnElFromClickEvent(e)

el.classList.add('animate-spin')
e.stopPropagation()
Expand All @@ -31,7 +31,7 @@ export default () => {
}

const onUpdateAllProviderClick = async (e: MouseEvent) => {
const el = e.target as HTMLElement
const el = getBtnElFromClickEvent(e)

el.classList.add('animate-spin')
e.stopPropagation()
Expand Down
10 changes: 10 additions & 0 deletions src/utils/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ dayjs.extend(relativeTime)
export function formatTimeFromNow(time: number | string) {
return dayjs(time).fromNow()
}

export function getBtnElFromClickEvent(event: MouseEvent) {
let el = event.target as HTMLElement

while (el && !el.classList.contains('btn')) {
el = el.parentElement!
}

return el
}

0 comments on commit a29e638

Please sign in to comment.