feat: reset visible

This commit is contained in:
Zephyruso 2023-09-02 17:49:40 +08:00
parent 65346ca743
commit 350fd56bc9
3 changed files with 20 additions and 9 deletions

View File

@ -14,7 +14,11 @@ import {
useDragDropContext, useDragDropContext,
} from '@thisbeyond/solid-dnd' } from '@thisbeyond/solid-dnd'
import { For, Show, createSignal } from 'solid-js' import { For, Show, createSignal } from 'solid-js'
import { AccessorKey } from '~/config/enum' import {
AccessorKey,
initColumnOrder,
initColumnVisibility,
} from '~/config/enum'
type ColumnVisibility = Partial<Record<AccessorKey, boolean>> type ColumnVisibility = Partial<Record<AccessorKey, boolean>>
type ColumnOrder = AccessorKey[] type ColumnOrder = AccessorKey[]
@ -107,7 +111,10 @@ export default (props: {
<button <button
class="btn btn-neutral btn-sm ml-auto mt-4 block" class="btn btn-neutral btn-sm ml-auto mt-4 block"
onClick={() => props.onOrderChange(Object.values(AccessorKey))} onClick={() => {
props.onOrderChange(initColumnOrder)
props.onVisibleChange(initColumnVisibility)
}}
> >
{t('reset')} {t('reset')}
</button> </button>

View File

@ -40,3 +40,9 @@ export enum LANG {
EN = 'en-US', EN = 'en-US',
ZH = 'zh-CN', ZH = 'zh-CN',
} }
export const initColumnOrder = Object.values(AccessorKey)
export const initColumnVisibility = {
...Object.fromEntries(initColumnOrder.map((i) => [i, true])),
[AccessorKey.ID]: false,
}

View File

@ -21,7 +21,11 @@ import { isIPv6 } from 'is-ip'
import { For, createEffect, createSignal } from 'solid-js' import { For, createEffect, createSignal } from 'solid-js'
import { twMerge } from 'tailwind-merge' import { twMerge } from 'tailwind-merge'
import ConnectionsModal from '~/components/ConnectionsModal' import ConnectionsModal from '~/components/ConnectionsModal'
import { AccessorKey } from '~/config/enum' import {
AccessorKey,
initColumnOrder,
initColumnVisibility,
} from '~/config/enum'
import { secret, useRequest, wsEndpointURL } from '~/signals' import { secret, useRequest, wsEndpointURL } from '~/signals'
import type { Connection } from '~/types' import type { Connection } from '~/types'
@ -33,12 +37,6 @@ type ConnectionWithSpeed = Connection & {
type ColumnVisibility = Partial<Record<AccessorKey, boolean>> type ColumnVisibility = Partial<Record<AccessorKey, boolean>>
type ColumnOrder = AccessorKey[] type ColumnOrder = AccessorKey[]
const initColumnOrder = Object.values(AccessorKey)
const initColumnVisibility = {
...Object.fromEntries(initColumnOrder.map((i) => [i, true])),
[AccessorKey.ID]: false,
}
export default () => { export default () => {
const [t] = useI18n() const [t] = useI18n()
const [columnVisibility, setColumnVisibility] = makePersisted( const [columnVisibility, setColumnVisibility] = makePersisted(