Skip to content

Commit

Permalink
fix: reduce dom for proxy group
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso committed Dec 12, 2024
1 parent b19128d commit 86cf36c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 67 deletions.
23 changes: 7 additions & 16 deletions src/components/proxies/ProxyGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@
type="checkbox"
v-model="showCollapse"
/>
<div class="collapse-content flex flex-col gap-2 max-sm:px-2">
<ProxyNodeGrid v-if="showContent">
<div
class="collapse-content flex flex-col gap-2 max-sm:px-2"
@transitionstart="showContent = showCollapse"
>
<ProxyNodeGrid>
<ProxyNodeCard
v-for="node in sortedProxies"
:key="node"
:name="node"
:active="node === proxyGroup.now"
:show-content="showContent"
@click="selectProxy(proxyGroup.name, node)"
/>
</ProxyNodeGrid>
Expand All @@ -60,7 +64,7 @@ import { activeConnections } from '@/store/connections'
import { proxyGroupLatencyTest, proxyMap, selectProxy } from '@/store/proxies'
import { collapseGroupMap } from '@/store/settings'
import { twMerge } from 'tailwind-merge'
import { computed, ref, watch } from 'vue'
import { computed, ref } from 'vue'
import LatencyTag from './LatencyTag.vue'
import ProxyIcon from './ProxyIcon.vue'
import ProxyNodeCard from './ProxyNodeCard.vue'
Expand All @@ -80,19 +84,6 @@ const showCollapse = computed({
},
})
const showContent = ref(showCollapse.value)
watch(showCollapse, (value) => {
if (value) {
showContent.value = value
} else {
setTimeout(() => {
if (value === showCollapse.value) {
showContent.value = value
}
}, 1000)
}
})
const proxyGroup = computed(() => proxyMap.value[props.name])
const sortedProxies = computed(() => {
return sortAndFilterProxyNodes(proxyGroup.value.all ?? [])
Expand Down
77 changes: 41 additions & 36 deletions src/components/proxies/ProxyNodeCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,53 @@
<div
:class="
twMerge(
'flex cursor-pointer flex-wrap items-center justify-end gap-1 rounded-md bg-base-200 p-2',
'flex h-9 cursor-pointer flex-wrap items-center justify-end gap-1 rounded-md bg-base-200 p-2',
active ? 'bg-primary text-primary-content' : 'shadow sm:hover:bg-base-300',
truncateProxyName && isTruncated && 'tooltip text-left',
)
"
:data-tip="node.name"
>
<ProxyIcon
v-if="node.icon"
:icon="node.icon"
:fill="active ? 'fill-primary-content' : 'fill-base-content'"
/>
<div
:class="
twMerge('flex-1 whitespace-nowrap text-xs md:text-sm', truncateProxyName && 'truncate')
"
ref="nameRef"
>
{{ node.name }}
</div>
<div
:class="
twMerge(
'flex items-center text-xs sm:gap-2',
twoColumnNodeForMobile ? 'gap-[2px]' : 'gap-1',
)
"
>
<div class="flex-1">
<span>{{ typeFormatter(node.type) }}</span>
<template v-if="node.udp">
<span :class="twMerge('hidden sm:hidden', twoColumnNodeForMobile && 'inline')">:udp</span>
<span :class="twMerge('hidden sm:inline', !twoColumnNodeForMobile && 'inline')">
| udp
</span>
</template>
</div>
<LatencyTag
:class="isLatencyTesting ? 'animate-pulse' : ''"
:name="node.name"
@click.stop="handlerLatencyTest"
<template v-if="showContent">
<ProxyIcon
v-if="node.icon"
:icon="node.icon"
:fill="active ? 'fill-primary-content' : 'fill-base-content'"
/>
</div>
<div
:class="
twMerge('flex-1 whitespace-nowrap text-xs md:text-sm', truncateProxyName && 'truncate')
"
ref="nameRef"
>
{{ node.name }}
</div>
<div
:class="
twMerge(
'flex items-center text-xs sm:gap-2',
twoColumnNodeForMobile ? 'gap-[2px]' : 'gap-1',
)
"
>
<div class="flex-1">
<span>{{ typeFormatter(node.type) }}</span>
<template v-if="node.udp">
<span :class="twMerge('hidden sm:hidden', twoColumnNodeForMobile && 'inline')"
>:udp</span
>
<span :class="twMerge('hidden sm:inline', !twoColumnNodeForMobile && 'inline')">
| udp
</span>
</template>
</div>
<LatencyTag
:class="isLatencyTesting ? 'animate-pulse' : ''"
:name="node.name"
@click.stop="handlerLatencyTest"
/>
</div>
</template>
</div>
</template>

Expand All @@ -59,6 +63,7 @@ import ProxyIcon from './ProxyIcon.vue'
const props = defineProps<{
name: string
active?: boolean
showContent: boolean
}>()
const nameRef = ref()
const isTruncated = ref(false)
Expand Down
22 changes: 7 additions & 15 deletions src/components/proxies/ProxyProvider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@
type="checkbox"
v-model="showCollapse"
/>
<div class="collapse-content flex flex-col gap-2">
<ProxyNodeGrid v-if="showContent">
<div
class="collapse-content flex flex-col gap-2"
@transitionstart="showContent = showCollapse"
>
<ProxyNodeGrid>
<ProxyNodeCard
v-for="node in sortedProxies"
:key="node"
:name="node"
:show-content="showContent"
/>
</ProxyNodeGrid>
</div>
Expand All @@ -72,7 +76,7 @@ import { ArrowPathIcon, BoltIcon } from '@heroicons/vue/24/outline'
import dayjs from 'dayjs'
import { toFinite } from 'lodash'
import { twMerge } from 'tailwind-merge'
import { computed, ref, watch } from 'vue'
import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import ProxyNodeCard from './ProxyNodeCard.vue'
import ProxyNodeGrid from './ProxyNodeGrid.vue'
Expand All @@ -91,18 +95,6 @@ const showCollapse = computed({
})
const showContent = ref(showCollapse.value)
watch(showCollapse, (value) => {
if (value) {
showContent.value = value
} else {
setTimeout(() => {
if (value === showCollapse.value) {
showContent.value = value
}
}, 1000)
}
})
const getSubscriptionsInfo = (subscriptionInfo: SubscriptionInfo) => {
const { Download = 0, Upload = 0, Total = 0, Expire = 0 } = subscriptionInfo
Expand Down

0 comments on commit 86cf36c

Please sign in to comment.