diff --git a/src/components/Collapse.tsx b/src/components/Collapse.tsx index fe40d40..b88775b 100644 --- a/src/components/Collapse.tsx +++ b/src/components/Collapse.tsx @@ -1,6 +1,6 @@ import { JSX, ParentComponent, Show, createMemo } from 'solid-js' import { twMerge } from 'tailwind-merge' -import { renderInTwoColumn } from '~/signals' +import { renderInTwoColumns } from '~/signals' type Props = { title: JSX.Element @@ -27,7 +27,7 @@ export const Collapse: ParentComponent = (props) => { } const mediaQueryClassName = createMemo(() => { - if (renderInTwoColumn()) { + if (renderInTwoColumns()) { return 'lg:grid-cols-3 xl:grid-cols-4' } else { return 'sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 2xl:grid-cols-7' diff --git a/src/components/ForTwoColumns.tsx b/src/components/ForTwoColumns.tsx index e11da02..49fbd1e 100644 --- a/src/components/ForTwoColumns.tsx +++ b/src/components/ForTwoColumns.tsx @@ -1,11 +1,11 @@ import { createWindowSize } from '@solid-primitives/resize-observer' import { JSX, Show, createMemo } from 'solid-js' -import { renderInTwoColumn } from '~/signals' +import { renderInTwoColumns } from '~/signals' export const ForTwoColumns = (props: { subChild: JSX.Element[] }) => { const windowSize = createWindowSize() const isShowTwoColumns = createMemo( - () => windowSize.width >= 640 && renderInTwoColumn(), + () => windowSize.width >= 640 && renderInTwoColumns(), ) // 640 is sm size in daisyui const leftCloumns = createMemo(() => props.subChild.filter((_, index) => index % 2 === 0 || !isShowTwoColumns()), diff --git a/src/helpers/proxies.ts b/src/helpers/proxies.ts index c876f1f..369e964 100644 --- a/src/helpers/proxies.ts +++ b/src/helpers/proxies.ts @@ -1,5 +1,6 @@ import dayjs from 'dayjs' import { PROXIES_ORDERING_TYPE } from '~/constants' +import { latencyQualityMap } from '~/signals' export const formatTimeFromNow = (time: number | string) => { return dayjs(time).fromNow() @@ -45,16 +46,16 @@ export const sortProxiesByOrderingType = ( switch (orderingType) { case PROXIES_ORDERING_TYPE.LATENCY_ASC: - if (prevLatency === -1) return 1 + if (prevLatency === latencyQualityMap().NOT_CONNECTED) return 1 - if (nextLatency === -1) return -1 + if (nextLatency === latencyQualityMap().NOT_CONNECTED) return -1 return prevLatency - nextLatency case PROXIES_ORDERING_TYPE.LATENCY_DESC: - if (prevLatency === -1) return 1 + if (prevLatency === latencyQualityMap().NOT_CONNECTED) return 1 - if (nextLatency === -1) return -1 + if (nextLatency === latencyQualityMap().NOT_CONNECTED) return -1 return nextLatency - prevLatency diff --git a/src/i18n/en.ts b/src/i18n/en.ts index cba333a..b033ac0 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -47,7 +47,7 @@ export default { autoSwitchTheme: 'Automatically switch theme', favDayTheme: 'Favorite light theme', favNightTheme: 'Favorite dark theme', - renderInTwoColumns: 'Render Proxies in two columns', + renderInTwoColumns: 'Render proxies in two columns', updateGEODatabases: 'Update GEO Databases', restartCore: 'Restart Core', upgradeCore: 'Upgrade Core', @@ -60,6 +60,8 @@ export default { ms: 'ms', updated: 'Updated', renderProxiesInSamePage: 'Render proxies and proxy provider in same page', + renderRulesAndProviderInTwoColumns: + 'Render rules and rule provider in two columns', tableSize: 'Table size', xs: 'Extra small size', sm: 'Small size', diff --git a/src/i18n/zh.ts b/src/i18n/zh.ts index e1f24e2..dc35694 100644 --- a/src/i18n/zh.ts +++ b/src/i18n/zh.ts @@ -60,6 +60,7 @@ export default { ms: '毫秒', updated: '更新于', renderProxiesInSamePage: '将代理和代理提供者显示在同一页', + renderRulesAndProviderInTwoColumns: '规则和规则提供者双列渲染', tableSize: '表格大小', xs: '超小尺寸', sm: '小尺寸', diff --git a/src/pages/Config.tsx b/src/pages/Config.tsx index 3c22093..a4888cd 100644 --- a/src/pages/Config.tsx +++ b/src/pages/Config.tsx @@ -29,8 +29,9 @@ import { latencyTestTimeoutDuration, proxiesOrderingType, proxiesPreviewType, - renderInTwoColumn, + renderInTwoColumns, renderProxiesInSamePage, + renderRulesAndProviderInTwoColumns, setAutoCloseConns, setAutoSwitchTheme, setFavDayTheme, @@ -38,8 +39,9 @@ import { setLatencyTestTimeoutDuration, setProxiesOrderingType, setProxiesPreviewType, - setRenderInTwoColumn, + setRenderInTwoColumns, setRenderProxiesInSamePage, + setRenderRulesAndProviderInTwoColumns, setSelectedEndpoint, setTableSize, setTwemoji, @@ -270,98 +272,102 @@ const ConfigForXd = () => { navigate(ROUTES.Setup) } - return ( -
+ const autoSwitchThemeSubChild = () => ( +
- {t('renderInTwoColumns')} + {t('favDayTheme')} - { - setRenderInTwoColumn(e.target.checked) - }} - /> -
-
- {t('renderProxiesInSamePage')} - - { - setRenderProxiesInSamePage(e.target.checked) - }} - /> -
- -
- {t('autoSwitchTheme')} - - { - setAutoSwitchTheme(e.target.checked) + setFavDayTheme(e.target.value) applyThemeByMode() }} - /> + > + + {(theme) => ( + + )} + +
+
+ {t('favNightTheme')} - -
- {t('favDayTheme')} - - -
-
- {t('favNightTheme')} - - -
-
- -
- {t('useTwemoji')} - - setTwemoji(e.target.checked)} - /> +
+ + ) + + const checkboxList = [ + { + label: 'renderInTwoColumns', + value: renderInTwoColumns, + onChange: setRenderInTwoColumns, + }, + { + label: 'renderRulesAndProviderInTwoColumns', + value: renderRulesAndProviderInTwoColumns, + onChange: setRenderRulesAndProviderInTwoColumns, + }, + { + label: 'renderProxiesInSamePage', + value: renderProxiesInSamePage, + onChange: setRenderProxiesInSamePage, + }, + { + label: 'autoSwitchTheme', + value: autoSwitchTheme, + onChange: (value: boolean) => { + setAutoSwitchTheme(value) + applyThemeByMode() + }, + subChild: autoSwitchThemeSubChild, + }, + { + label: 'useTwemoji', + value: useTwemoji, + onChange: setTwemoji, + }, + ] + + return ( +
+ + {(checkbox) => ( + <> +
+ {t(checkbox.label)} + + { + checkbox.onChange(e.target.checked) + }} + /> +
+ {checkbox.subChild?.()} + + )} +
{t('proxiesPreviewType')} diff --git a/src/pages/Rules.tsx b/src/pages/Rules.tsx index 3698c24..b4d0312 100644 --- a/src/pages/Rules.tsx +++ b/src/pages/Rules.tsx @@ -5,7 +5,7 @@ import { For, Show, createMemo, createSignal, onMount } from 'solid-js' import { twMerge } from 'tailwind-merge' import { Button } from '~/components' import { formatTimeFromNow, useStringBooleanMap } from '~/helpers' -import { useRules } from '~/signals' +import { renderRulesAndProviderInTwoColumns, useRules } from '~/signals' export default () => { const [t] = useI18n() @@ -40,7 +40,12 @@ export default () => { } return ( -
+

{t('rules')}

diff --git a/src/signals/config.ts b/src/signals/config.ts index 9240380..ea71b9c 100644 --- a/src/signals/config.ts +++ b/src/signals/config.ts @@ -41,7 +41,7 @@ export const [favNightTheme, setFavNightTheme] = makePersisted( createSignal('night'), { name: 'favNightTheme', storage: localStorage }, ) -export const [renderInTwoColumn, setRenderInTwoColumn] = makePersisted( +export const [renderInTwoColumns, setRenderInTwoColumns] = makePersisted( createSignal(true), { name: 'renderInTwoColumn', storage: localStorage }, ) @@ -50,6 +50,13 @@ export const [renderProxiesInSamePage, setRenderProxiesInSamePage] = name: 'renderProxiesInSamePage', storage: localStorage, }) +export const [ + renderRulesAndProviderInTwoColumns, + setRenderRulesAndProviderInTwoColumns, +] = makePersisted(createSignal(true), { + name: 'renderRulesAndProviderInTwoColumns', + storage: localStorage, +}) export const [tableSize, setTableSize] = makePersisted( createSignal(TAILWINDCSS_SIZE.XS), { name: 'tableSize', storage: localStorage },