From 41b074e2074f66cc728f067448eab3031fe303da Mon Sep 17 00:00:00 2001 From: Josue Date: Wed, 14 Jul 2021 16:38:12 -0400 Subject: [PATCH] fix(front-end): change server page name, adjust paths, and add fetching vnc connection info --- striker-ui/components/Display/FullSize.tsx | 47 ++++++++++--------- striker-ui/components/Servers.tsx | 2 +- .../pages/server/{[uuid].tsx => index.tsx} | 0 3 files changed, 25 insertions(+), 24 deletions(-) rename striker-ui/pages/server/{[uuid].tsx => index.tsx} (100%) diff --git a/striker-ui/components/Display/FullSize.tsx b/striker-ui/components/Display/FullSize.tsx index fa1aa24f..8584dfe0 100644 --- a/striker-ui/components/Display/FullSize.tsx +++ b/striker-ui/components/Display/FullSize.tsx @@ -60,10 +60,9 @@ interface VncConnectionProps { const FullSize = ({ setMode, uuid }: PreviewProps): JSX.Element => { const [anchorEl, setAnchorEl] = useState(null); const rfb = useRef(undefined); - const vncConnection = useRef({ - protocol: '', - forward_port: 0, - }); + const [vncConnection, setVncConnection] = useState< + VncConnectionProps | undefined + >(undefined); const [displaySize, setDisplaySize] = useState< | { width: string | number; @@ -79,18 +78,18 @@ const FullSize = ({ setMode, uuid }: PreviewProps): JSX.Element => { height: '80vh', }); - (async () => { - const res = await putJSON( - 'http://108.168.17.168/cgi-bin/manage_vnc_pipes', - { - server_uuid: uuid, - is_open: true, - }, - ); - // console.log(res); - vncConnection.current = res.json(); - })(); - }, [uuid]); + if (!vncConnection) + (async () => { + const res = await putJSON( + `${process.env.NEXT_PUBLIC_API_URL}/manage_vnc_pipes`, + { + server_uuid: uuid, + is_open: true, + }, + ); + setVncConnection(await res.json()); + })(); + }, [uuid, vncConnection]); const handleClick = (event: React.MouseEvent): void => { setAnchorEl(event.currentTarget); @@ -117,13 +116,15 @@ const FullSize = ({ setMode, uuid }: PreviewProps): JSX.Element => { return ( - - - + {vncConnection && ( + + + + )} { className={classes.button} key={server.server_uuid} component="a" - href={`/server/${server.server_uuid}`} + href={`/server?uuid=${server.server_uuid}`} > {showCheckbox && ( diff --git a/striker-ui/pages/server/[uuid].tsx b/striker-ui/pages/server/index.tsx similarity index 100% rename from striker-ui/pages/server/[uuid].tsx rename to striker-ui/pages/server/index.tsx