Skip to content

Commit

Permalink
feat(rules): config for render rules in two columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso authored and Zephyruso committed Sep 6, 2023
1 parent 79ad0ac commit 7e2fe6a
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 92 deletions.
4 changes: 2 additions & 2 deletions src/components/Collapse.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,7 +27,7 @@ export const Collapse: ParentComponent<Props> = (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'
Expand Down
4 changes: 2 additions & 2 deletions src/components/ForTwoColumns.tsx
Original file line number Diff line number Diff line change
@@ -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()),
Expand Down
9 changes: 5 additions & 4 deletions src/helpers/proxies.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default {
ms: '毫秒',
updated: '更新于',
renderProxiesInSamePage: '将代理和代理提供者显示在同一页',
renderRulesAndProviderInTwoColumns: '规则和规则提供者双列渲染',
tableSize: '表格大小',
xs: '超小尺寸',
sm: '小尺寸',
Expand Down
166 changes: 86 additions & 80 deletions src/pages/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ import {
latencyTestTimeoutDuration,
proxiesOrderingType,
proxiesPreviewType,
renderInTwoColumn,
renderInTwoColumns,
renderProxiesInSamePage,
renderRulesAndProviderInTwoColumns,
setAutoCloseConns,
setAutoSwitchTheme,
setFavDayTheme,
setFavNightTheme,
setLatencyTestTimeoutDuration,
setProxiesOrderingType,
setProxiesPreviewType,
setRenderInTwoColumn,
setRenderInTwoColumns,
setRenderProxiesInSamePage,
setRenderRulesAndProviderInTwoColumns,
setSelectedEndpoint,
setTableSize,
setTwemoji,
Expand Down Expand Up @@ -270,98 +272,102 @@ const ConfigForXd = () => {
navigate(ROUTES.Setup)
}

return (
<div class="grid gap-4">
<div class="flex flex-col">
<ConfigTitle>{t('renderInTwoColumns')}</ConfigTitle>

<input
type="checkbox"
class="toggle"
checked={renderInTwoColumn()}
onChange={(e) => {
setRenderInTwoColumn(e.target.checked)
}}
/>
</div>
const autoSwitchThemeSubChild = () => (
<Show when={autoSwitchTheme()}>
<div class="flex flex-col">
<ConfigTitle>{t('renderProxiesInSamePage')}</ConfigTitle>
<ConfigTitle>{t('favDayTheme')}</ConfigTitle>

<input
type="checkbox"
class="toggle"
checked={renderProxiesInSamePage()}
<select
class="select select-bordered w-full max-w-xs"
onChange={(e) => {
setRenderProxiesInSamePage(e.target.checked)
setFavDayTheme(e.target.value)
applyThemeByMode()
}}
/>
>
<For each={themes}>
{(theme) => (
<option selected={favDayTheme() === theme} value={theme}>
{theme}
</option>
)}
</For>
</select>
</div>

<div class="flex flex-col">
<ConfigTitle>{t('autoSwitchTheme')}</ConfigTitle>
<ConfigTitle>{t('favNightTheme')}</ConfigTitle>

<input
type="checkbox"
class="toggle"
checked={autoSwitchTheme()}
<select
class="select select-bordered w-full max-w-xs"
onChange={(e) => {
setAutoSwitchTheme(e.target.checked)
setFavNightTheme(e.target.value)
applyThemeByMode()
}}
/>
>
<For each={themes}>
{(theme) => (
<option selected={favNightTheme() === theme} value={theme}>
{theme}
</option>
)}
</For>
</select>
</div>
</Show>
)

<Show when={autoSwitchTheme()}>
<div class="flex flex-col">
<ConfigTitle>{t('favDayTheme')}</ConfigTitle>

<select
class="select select-bordered w-full max-w-xs"
onChange={(e) => {
setFavDayTheme(e.target.value)
applyThemeByMode()
}}
>
<For each={themes}>
{(theme) => (
<option selected={favDayTheme() === theme} value={theme}>
{theme}
</option>
)}
</For>
</select>
</div>
<div class="flex flex-col">
<ConfigTitle>{t('favNightTheme')}</ConfigTitle>

<select
class="select select-bordered w-full max-w-xs"
onChange={(e) => {
setFavNightTheme(e.target.value)
applyThemeByMode()
}}
>
<For each={themes}>
{(theme) => (
<option selected={favNightTheme() === theme} value={theme}>
{theme}
</option>
)}
</For>
</select>
</div>
</Show>
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,
},
]

<div>
<ConfigTitle>{t('useTwemoji')}</ConfigTitle>
return (
<div class="grid gap-4">
<For each={checkboxList}>
{(checkbox) => (
<>
<div class="flex flex-col">
<ConfigTitle>{t(checkbox.label)}</ConfigTitle>

<input
class="toggle"
type="checkbox"
checked={useTwemoji()}
onChange={(e) => setTwemoji(e.target.checked)}
/>
</div>
<input
type="checkbox"
class="toggle"
checked={checkbox.value()}
onChange={(e) => {
checkbox.onChange(e.target.checked)
}}
/>
</div>
{checkbox.subChild?.()}
</>
)}
</For>

<div>
<ConfigTitle>{t('proxiesPreviewType')}</ConfigTitle>
Expand Down
9 changes: 7 additions & 2 deletions src/pages/Rules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -40,7 +40,12 @@ export default () => {
}

return (
<div class="flex w-full gap-4">
<div
class={twMerge(
'flex w-full flex-col gap-4',
renderRulesAndProviderInTwoColumns() && 'flex-row',
)}
>
<div class="flex-1">
<h1 class="pb-4 text-lg font-semibold">{t('rules')}</h1>

Expand Down
9 changes: 8 additions & 1 deletion src/signals/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
)
Expand All @@ -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>(TAILWINDCSS_SIZE.XS),
{ name: 'tableSize', storage: localStorage },
Expand Down

0 comments on commit 7e2fe6a

Please sign in to comment.