Skip to content

Commit 0ef449e

Browse files
committed
Move data into state
1 parent b7d0ab8 commit 0ef449e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

web/src/Header.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useQuery, gql } from "@apollo/client";
2+
import { useState, useEffect } from "react";
23

34
export const SERVER_INFO = gql`
45
query GetServerInfo {
@@ -31,14 +32,24 @@ function ServerInfo(props) {
3132
d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"
3233
/>
3334
</svg>
34-
Listening on: http://{props.data.serverInfo.request_address}:
35-
{props.data.serverInfo.request_port}
35+
Listening on: {props.url}
3636
</div>
3737
);
3838
}
3939

4040
function Header(props) {
4141
const { loading, error, data } = useQuery(SERVER_INFO);
42+
const [url, setUrl] = useState("");
43+
const [version, setVersion] = useState("");
44+
45+
useEffect(() => {
46+
if (data) {
47+
setUrl(
48+
`http://${data.serverInfo.request_address}:${data.serverInfo.request_port}`
49+
);
50+
setVersion(data.serverInfo.build_info["version"]);
51+
}
52+
}, [data]);
4253

4354
return (
4455
<header className="text-gray-600 body-font border-b-2 bg-white">
@@ -49,11 +60,11 @@ function Header(props) {
4960
>
5061
<span className="text-xl">Request Hole</span>
5162
<h2 className="tracking-widest text-sm ml-2 title-font font-light text-gray-400">
52-
{data ? data.serverInfo.build_info["version"] : ""}
63+
{version}
5364
</h2>
5465
</a>
5566
<div className="md:mr-auto md:ml-4 md:py-1 md:pl-4 md:border-l md:border-gray-400 flex flex-wrap items-center text-base justify-center">
56-
<ServerInfo loading={loading} error={error} data={data} />
67+
<ServerInfo loading={loading} error={error} url={url} />
5768
</div>
5869
<nav className="md:ml-auto flex flex-wrap items-center text-base justify-center">
5970
<button

0 commit comments

Comments
 (0)