From 116c69b4ec5353331de187520e13c8304c13bde9 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 15 Oct 2023 01:35:20 +0800 Subject: [PATCH] feat: add add server guide --- src/client/pages/Servers.tsx | 130 ++++++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 8 deletions(-) diff --git a/src/client/pages/Servers.tsx b/src/client/pages/Servers.tsx index 5aef4c7..68302db 100644 --- a/src/client/pages/Servers.tsx +++ b/src/client/pages/Servers.tsx @@ -1,5 +1,14 @@ -import React, { useMemo, useState } from 'react'; -import { Badge, Button, Form, Input, Modal, Table } from 'antd'; +import React, { useEffect, useMemo, useRef, useState } from 'react'; +import { + Badge, + Button, + Form, + Input, + Modal, + Steps, + Table, + Typography, +} from 'antd'; import { ColumnsType } from 'antd/es/table'; import { PlusOutlined } from '@ant-design/icons'; import { ServerStatusInfo } from '../../types'; @@ -9,6 +18,10 @@ import prettyMilliseconds from 'pretty-ms'; import { UpDownCounter } from '../components/UpDownCounter'; import { max } from 'lodash-es'; import dayjs from 'dayjs'; +import { useCurrentWorkspaceId } from '../store/user'; +import { useWatch } from '../hooks/useWatch'; +import { Loading } from '../components/Loading'; +import { without } from 'lodash-es'; export const Servers: React.FC = React.memo(() => { const [isModalOpen, setIsModalOpen] = useState(false); @@ -38,26 +51,32 @@ export const Servers: React.FC = React.memo(() => { setIsModalOpen(false)} > -
- - - -
+
+ +
); }); Servers.displayName = 'Servers'; -export const ServerList: React.FC = React.memo(() => { +function useServerMap(): Record { const serverMap = useSocketSubscribe>( 'onServerStatusUpdate', {} ); + return serverMap; +} + +export const ServerList: React.FC = React.memo(() => { + const serverMap = useServerMap(); + const dataSource = Object.values(serverMap); const lastUpdatedAt = max(dataSource.map((d) => d.updatedAt)); @@ -160,3 +179,98 @@ export const ServerList: React.FC = React.memo(() => { ); }); ServerList.displayName = 'ServerList'; + +export const AddServerStep: React.FC = React.memo(() => { + const workspaceId = useCurrentWorkspaceId(); + const [current, setCurrent] = useState(0); + const serverMap = useServerMap(); + const [checking, setChecking] = useState(false); + const oldServerMapNames = useRef([]); + const [diffServerNames, setDiffServerNames] = useState([]); + + const allServerNames = useMemo(() => Object.keys(serverMap), [serverMap]); + + useWatch([checking], () => { + if (checking === true) { + oldServerMapNames.current = [...allServerNames]; + } + }); + + useWatch([allServerNames], () => { + if (checking === true) { + setDiffServerNames(without(allServerNames, ...oldServerMapNames.current)); + } + }); + + return ( + + Download reporter from{' '} + { + if (current === 0) { + setCurrent(1); + setChecking(true); + } + }} + > + Releases Page + + + ), + }, + { + title: 'Run', + description: ( +
+ run reporter with{' '} + + ./reporter --url {window.location.origin} --workspace{' '} + {workspaceId} + + +
+ ), + }, + { + title: 'Waiting for receive UDP pack', + description: ( +
+ {diffServerNames.length === 0 || checking === false ? ( + + ) : ( +
+ Is this your servers? + {diffServerNames.map((n) => ( +
- {n}
+ ))} +
+ )} +
+ ), + }, + ]} + /> + ); +}); +AddServerStep.displayName = 'AddServerStep';