diff --git a/src/components/Button.tsx b/src/components/Button.tsx index 7053f188..86793018 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -33,7 +33,12 @@ export const Button: ParentComponent<
- + {props.icon || props.children} diff --git a/src/components/Collapse.tsx b/src/components/Collapse.tsx index f9cc7980..230d68a9 100644 --- a/src/components/Collapse.tsx +++ b/src/components/Collapse.tsx @@ -28,7 +28,7 @@ export const Collapse: ParentComponent = (props) => {
{ } export const ConnectionsSettingsModal = (props: { + ref?: (el: HTMLDialogElement) => void order: ConnectionsTableColumnOrder visible: ConnectionsTableColumnVisibility onOrderChange: (value: ConnectionsTableColumnOrder) => void onVisibleChange: (value: ConnectionsTableColumnVisibility) => void }) => { - const modalID = MODAL.CONNECTIONS_SETTINGS const [t] = useI18n() + const [activeKey, setActiveKey] = createSignal(null) @@ -179,25 +179,23 @@ export const ConnectionsSettingsModal = (props: { } return ( - - + ) } diff --git a/src/components/ConnectionsTableDetailsModal.tsx b/src/components/ConnectionsTableDetailsModal.tsx index 6da77bdd..4aba491f 100644 --- a/src/components/ConnectionsTableDetailsModal.tsx +++ b/src/components/ConnectionsTableDetailsModal.tsx @@ -1,50 +1,34 @@ -import { IconX } from '@tabler/icons-solidjs' +import { IconNetwork } from '@tabler/icons-solidjs' import { Component, Show } from 'solid-js' -import { MODAL } from '~/constants' +import { Modal } from '~/components' +import { useI18n } from '~/i18n' import { allConnections } from '~/signals' -import { Button } from './Button' export const ConnectionsTableDetailsModal: Component<{ + ref?: (el: HTMLDialogElement) => void selectedConnectionID?: string }> = (props) => { - const modalID = MODAL.CONNECTIONS_TABLE_DETAILS + const [t] = useI18n() return ( - - - - + props.ref?.(el)} + icon={} + title={t('connectionsDetails')} + > + +
+          
+            {JSON.stringify(
+              allConnections().find(
+                ({ id }) => id === props.selectedConnectionID,
+              ),
+              null,
+              2,
+            )}
+          
+        
+
+
) } diff --git a/src/components/LogsSettingsModal.tsx b/src/components/LogsSettingsModal.tsx index abdf6f4c..66b5b3dc 100644 --- a/src/components/LogsSettingsModal.tsx +++ b/src/components/LogsSettingsModal.tsx @@ -1,10 +1,9 @@ -import { IconX } from '@tabler/icons-solidjs' -import { For } from 'solid-js' -import { Button, ConfigTitle } from '~/components' +import { IconFileStack } from '@tabler/icons-solidjs' +import { Component, For } from 'solid-js' +import { ConfigTitle, Modal } from '~/components' import { LOGS_TABLE_MAX_ROWS_LIST, LOG_LEVEL, - MODAL, TAILWINDCSS_SIZE, } from '~/constants' import { useI18n } from '~/i18n' @@ -17,27 +16,18 @@ import { setLogsTableSize, } from '~/signals' -export const LogsSettingsModal = () => { - const modalID = MODAL.LOGS_SETTINGS +export const LogsSettingsModal: Component<{ + ref?: (el: HTMLDialogElement) => void +}> = (props) => { const [t] = useI18n() return ( - - + ) } diff --git a/src/components/Modal.tsx b/src/components/Modal.tsx new file mode 100644 index 00000000..6ebde08d --- /dev/null +++ b/src/components/Modal.tsx @@ -0,0 +1,53 @@ +import { IconX } from '@tabler/icons-solidjs' +import { JSX, ParentComponent, Show, children } from 'solid-js' +import { twMerge } from 'tailwind-merge' +import { Button } from '~/components' + +type Props = { + ref?: (el: HTMLDialogElement) => void + icon?: JSX.Element + title?: JSX.Element + action?: JSX.Element +} + +const actionClass = + 'sticky bottom-0 z-50 flex items-center justify-end bg-base-100 bg-opacity-80 p-6 backdrop-blur' + +export const Modal: ParentComponent = (props) => { + let dialogRef: HTMLDialogElement | undefined + + return ( + (dialogRef = el) && props.ref?.(el)} + class="modal modal-bottom sm:modal-middle" + > + + + + ) +} diff --git a/src/components/ProxiesSettingsModal.tsx b/src/components/ProxiesSettingsModal.tsx index 3fed43ab..55cbd12b 100644 --- a/src/components/ProxiesSettingsModal.tsx +++ b/src/components/ProxiesSettingsModal.tsx @@ -1,7 +1,7 @@ -import { IconX } from '@tabler/icons-solidjs' -import { For } from 'solid-js' -import { Button, ConfigTitle } from '~/components' -import { MODAL, PROXIES_ORDERING_TYPE, PROXIES_PREVIEW_TYPE } from '~/constants' +import { IconGlobe } from '@tabler/icons-solidjs' +import { Component, For } from 'solid-js' +import { ConfigTitle, Modal } from '~/components' +import { PROXIES_ORDERING_TYPE, PROXIES_PREVIEW_TYPE } from '~/constants' import { useI18n } from '~/i18n' import { autoCloseConns, @@ -18,27 +18,18 @@ import { urlForLatencyTest, } from '~/signals' -export const ProxiesSettingsModal = () => { - const modalID = MODAL.PROXIES_SETTINGS +export const ProxiesSettingsModal: Component<{ + ref?: (el: HTMLDialogElement) => void +}> = (props) => { const [t] = useI18n() return ( - - + ) } diff --git a/src/components/index.ts b/src/components/index.ts index b6289df7..fa6f27ee 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -7,6 +7,7 @@ export * from './Header' export * from './Latency' export * from './LogoText' export * from './LogsSettingsModal' +export * from './Modal' export * from './ProxiesSettingsModal' export * from './ProxyCardGroups' export * from './ProxyNodeCard' diff --git a/src/constants/index.ts b/src/constants/index.ts index 6cc86a56..064c1a94 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -163,11 +163,3 @@ export enum LOG_LEVEL { export const LOGS_TABLE_MAX_ROWS_LIST = [200, 300, 500, 800, 1000] export const DEFAULT_LOGS_TABLE_MAX_ROWS = LOGS_TABLE_MAX_ROWS_LIST[0] - -export enum MODAL { - PROXIES_SETTINGS = 'proxies-settings', - RULES_SETTINGS = 'rules-settings', - CONNECTIONS_SETTINGS = 'connections-settings', - CONNECTIONS_TABLE_DETAILS = 'connections-table-details', - LOGS_SETTINGS = 'logs-settings', -} diff --git a/src/i18n/en.ts b/src/i18n/en.ts index c91131af..e940c090 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -2,9 +2,13 @@ export default { add: 'Add', overview: 'Overview', proxies: 'Proxies', + proxiesSettings: 'Proxies Settings', rules: 'Rules', connections: 'Connections', + connectionsSettings: 'Connections Settings', + connectionsDetails: 'Connections Details', logs: 'Logs', + logsSettings: 'Logs Settings', config: 'Config', upload: 'Upload', download: 'Download', diff --git a/src/i18n/zh.ts b/src/i18n/zh.ts index 715fef26..9ac91b0a 100644 --- a/src/i18n/zh.ts +++ b/src/i18n/zh.ts @@ -4,9 +4,13 @@ export default { add: '添加', overview: '概览', proxies: '代理', + proxiesSettings: '代理设置', rules: '规则', connections: '连接', + connectionsSettings: '连接设置', + connectionsDetails: '连接详情', logs: '日志', + logsSettings: '日志设置', config: '配置', upload: '上传', download: '下载', diff --git a/src/pages/Connections.tsx b/src/pages/Connections.tsx index c04fcdc1..0ea11122 100644 --- a/src/pages/Connections.tsx +++ b/src/pages/Connections.tsx @@ -43,7 +43,7 @@ import { ConnectionsSettingsModal, ConnectionsTableDetailsModal, } from '~/components' -import { CONNECTIONS_TABLE_ACCESSOR_KEY, MODAL } from '~/constants' +import { CONNECTIONS_TABLE_ACCESSOR_KEY } from '~/constants' import { useI18n } from '~/i18n' import { allConnections, @@ -78,6 +78,9 @@ const fuzzyFilter: FilterFn = (row, columnId, value, addMeta) => { } export default () => { + let connectionsSettingsModalRef: HTMLDialogElement | undefined + let connectionsDetailsModalRef: HTMLDialogElement | undefined + const [t] = useI18n() const [activeTab, setActiveTab] = createSignal(ActiveTab.activeConnections) @@ -103,11 +106,7 @@ export default () => { onClick={() => { setSelectedConnectionID(row.original.id) - const modal = document.querySelector( - `#${MODAL.CONNECTIONS_TABLE_DETAILS}`, - ) as HTMLDialogElement | null - - modal?.showModal() + connectionsDetailsModalRef?.showModal() }} icon={} /> @@ -397,13 +396,7 @@ export default () => {
@@ -531,6 +524,7 @@ export default () => {
(connectionsSettingsModalRef = el)} order={connectionsTableColumnOrder()} visible={connectionsTableColumnVisibility()} onOrderChange={(data) => setConnectionsTableColumnOrder(data)} @@ -540,6 +534,7 @@ export default () => { /> (connectionsDetailsModalRef = el)} selectedConnectionID={selectedConnectionID()} />
diff --git a/src/pages/Logs.tsx b/src/pages/Logs.tsx index 9d25b972..0d42cfdd 100644 --- a/src/pages/Logs.tsx +++ b/src/pages/Logs.tsx @@ -18,7 +18,7 @@ import { import { For, Index, createEffect, createSignal } from 'solid-js' import { twMerge } from 'tailwind-merge' import { Button, LogsSettingsModal } from '~/components' -import { LOG_LEVEL, MODAL } from '~/constants' +import { LOG_LEVEL } from '~/constants' import { useI18n } from '~/i18n' import { logsTableSize, tableSizeClassName, useWsRequest } from '~/signals' import { logLevel, logMaxRows } from '~/signals/config' @@ -40,7 +40,10 @@ const fuzzyFilter: FilterFn = (row, columnId, value, addMeta) => { } export default () => { + let logsSettingsModalRef: HTMLDialogElement | undefined + const [t] = useI18n() + let seq = 1 const [logs, setLogs] = createSignal([]) @@ -139,13 +142,7 @@ export default () => {