Skip to content

Commit

Permalink
feat: customizable min card width
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso committed Feb 20, 2025
1 parent 163f261 commit 72f410c
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/components/proxies/ProxyNodeGrid.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<template>
<div
class="grid max-h-96 gap-2 overflow-y-auto overflow-x-hidden"
:style="`grid-template-columns: repeat(auto-fill, minmax(${proxyCardSize === PROXY_CARD_SIZE.LARGE ? 145 : 130}px, 1fr));`"
:style="`grid-template-columns: repeat(auto-fill, minmax(${minProxyCardWidth}px, 1fr));`"
>
<slot />
</div>
</template>

<script lang="ts" setup>
import { PROXY_CARD_SIZE } from '@/constant'
import { proxyCardSize } from '@/store/settings'
import { minProxyCardWidth } from '@/store/settings'
</script>
7 changes: 7 additions & 0 deletions src/components/settings/ProxiesSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<select
class="select select-bordered select-sm min-w-24"
v-model="proxyCardSize"
@change="handlerProxyCardSizeChange"
>
<option
v-for="opt in Object.values(PROXY_CARD_SIZE)"
Expand Down Expand Up @@ -135,6 +136,7 @@
<script setup lang="ts">
import { PROXY_CARD_SIZE, PROXY_PREVIEW_TYPE } from '@/constant'
import { useTooltip } from '@/helper/tooltip'
import { getMinCardWidth } from '@/helper/utils'
import { proxyMap } from '@/store/proxies'
import {
iconMarginRight,
Expand All @@ -143,6 +145,7 @@ import {
IPv6test,
lowLatency,
mediumLatency,
minProxyCardWidth,
proxyCardSize,
proxyPreviewType,
speedtestTimeout,
Expand All @@ -164,4 +167,8 @@ const independentLatencyTestTip = (e: Event) => {
const hasIcon = computed(() => {
return Object.values(proxyMap.value).some((proxy) => !!proxy.icon)
})
const handlerProxyCardSizeChange = () => {
minProxyCardWidth.value = getMinCardWidth(proxyCardSize.value)
}
</script>
23 changes: 22 additions & 1 deletion src/components/sidebar/ProxiesCtrl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { updateProxyProviderAPI } from '@/api'
import { collapsedBus } from '@/composables/bus'
import { proxiesFilter, useProxies } from '@/composables/proxies'
import { PROXY_SORT_TYPE, PROXY_TAB_TYPE } from '@/constant'
import { isMiddleScreen } from '@/helper/utils'
import { getMinCardWidth, isMiddleScreen } from '@/helper/utils'
import { configs, updateConfigs } from '@/store/config'
import { allProxiesLatencyTest, fetchProxies, proxyProviederList } from '@/store/proxies'
import {
automaticDisconnection,
collapseGroupMap,
hideUnavailableProxies,
manageHiddenGroup,
minProxyCardWidth,
proxyCardSize,
proxySortType,
} from '@/store/settings'
import {
Expand Down Expand Up @@ -90,6 +92,10 @@ export default defineComponent({
})
}

const handlerResetProxyCardWidth = () => {
minProxyCardWidth.value = getMinCardWidth(proxyCardSize.value)
}

return () => {
const tabs = (
<div
Expand Down Expand Up @@ -234,6 +240,21 @@ export default defineComponent({
v-model={automaticDisconnection.value}
/>
</div>
<div class="flex items-center gap-2">
{t('minProxyCardWidth')}
<input
class="input input-sm input-bordered w-20"
type="number"
v-model={minProxyCardWidth.value}
/>
px
<button
class="btn btn-sm"
onClick={handlerResetProxyCardWidth}
>
{t('reset')}
</button>
</div>
</div>
</DialogWrapper>
</>
Expand Down
5 changes: 5 additions & 0 deletions src/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ export enum PROXY_CARD_SIZE {
LARGE = 'large',
}

export enum MIN_PROXY_CARD_WIDTH {
SMALL = 130,
LARGE = 145,
}

export enum PROXY_CHAIN_DIRECTION {
NORMAL = 'normal',
REVERSE = 'reverse',
Expand Down
5 changes: 5 additions & 0 deletions src/helper/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MIN_PROXY_CARD_WIDTH, PROXY_CARD_SIZE } from '@/constant'
import { useMediaQuery } from '@vueuse/core'

export const twoColumn = useMediaQuery('(min-width: 810px)')
Expand All @@ -7,6 +8,10 @@ export const isPWA = (() => {
return window.matchMedia('(display-mode: standalone)').matches || navigator.standalone
})()

export const getMinCardWidth = (size: PROXY_CARD_SIZE) => {
return size === PROXY_CARD_SIZE.LARGE ? MIN_PROXY_CARD_WIDTH.LARGE : MIN_PROXY_CARD_WIDTH.SMALL
}

const BACKGROUND_IMAGE = 'background-image'
export const LOCAL_IMAGE = 'local-image'

Expand Down
2 changes: 2 additions & 0 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ const en = {
simpleCardPreset: 'Simple Preset',
detailedCardPreset: 'Detailed Preset',
refresh: 'Refresh',
reset: 'Reset',
minProxyCardWidth: 'Min Proxy Card Width',
}

export type LANG_MESSAGE = typeof en
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ const ru: LANG_MESSAGE = {
simpleCardPreset: 'Простой карточки',
detailedCardPreset: 'Подробный карточки',
refresh: 'Обновить',
reset: 'Сбросить',
minProxyCardWidth: 'Минимальная ширина карточки прокси',
}

export default ru
2 changes: 2 additions & 0 deletions src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ const zh: LANG_MESSAGE = {
simpleCardPreset: '简洁预设',
detailedCardPreset: '详细预设',
refresh: '刷新',
reset: '重置',
minProxyCardWidth: '最小节点卡片宽度',
}

export default zh
6 changes: 5 additions & 1 deletion src/store/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TABLE_SIZE,
TABLE_WIDTH_MODE,
} from '@/constant'
import { isMiddleScreen } from '@/helper/utils'
import { getMinCardWidth, isMiddleScreen } from '@/helper/utils'
import type { SourceIPLabel } from '@/types'
import { useStorage } from '@vueuse/core'
import { isEmpty } from 'lodash'
Expand Down Expand Up @@ -79,6 +79,10 @@ export const proxyCardSize = useStorage<PROXY_CARD_SIZE>(
'config/proxy-card-size',
PROXY_CARD_SIZE.LARGE,
)
export const minProxyCardWidth = useStorage<number>(
'config/min-proxy-card-width',
getMinCardWidth(proxyCardSize.value),
)
export const manageHiddenGroup = ref(false)
export const iconSize = useStorage('config/icon-size', 14)
export const iconMarginRight = useStorage('config/icon-margin-right', 6)
Expand Down

0 comments on commit 72f410c

Please sign in to comment.