|
| 1 | +import useSWR from "swr"; |
| 2 | + |
| 3 | +async function fetchAPI(key) { |
| 4 | + const response = await fetch(key); |
| 5 | + const responseBody = await response.json(); |
| 6 | + return responseBody; |
| 7 | +} |
| 8 | + |
| 9 | +export default function StatusPage() { |
| 10 | + return ( |
| 11 | + <> |
| 12 | + <h1>Status</h1> |
| 13 | + <UpdatedAt></UpdatedAt> |
| 14 | + <br /> |
| 15 | + <DatabaseStatus></DatabaseStatus> |
| 16 | + </> |
| 17 | + ); |
| 18 | +} |
| 19 | + |
| 20 | +function UpdatedAt() { |
| 21 | + const { isLoading, data } = useSWR("/api/v1/status", fetchAPI, { |
| 22 | + refreshInterval: 5000, |
| 23 | + }); |
| 24 | + |
| 25 | + let updateAtText = "Loading..."; |
| 26 | + |
| 27 | + if (!isLoading && data) { |
| 28 | + const updatedAt = new Date(data.updated_at); |
| 29 | + updateAtText = updatedAt.toLocaleString(); |
| 30 | + } |
| 31 | + |
| 32 | + return <div>Last Update: {updateAtText}</div>; |
| 33 | +} |
| 34 | + |
| 35 | +function DatabaseStatus() { |
| 36 | + const { isLoading, data } = useSWR("/api/v1/status", fetchAPI, { |
| 37 | + refreshInterval: 5000, |
| 38 | + }); |
| 39 | + |
| 40 | + let version = "Loading..."; |
| 41 | + let max_connections = "Loading..."; |
| 42 | + let opened_connections = "Loading..."; |
| 43 | + |
| 44 | + if (!isLoading && data) { |
| 45 | + const database = data.dependecies.database; |
| 46 | + version = database.version.toString(); |
| 47 | + max_connections = database.max_connections.toString(); |
| 48 | + opened_connections = database.opened_connections.toString(); |
| 49 | + } |
| 50 | + |
| 51 | + return ( |
| 52 | + <> |
| 53 | + <h2>Database</h2> |
| 54 | + <div>Version: {version}</div> |
| 55 | + <div>Max Connections: {max_connections}</div> |
| 56 | + <div>Opened Connections: {opened_connections}</div> |
| 57 | + </> |
| 58 | + ); |
| 59 | +} |
0 commit comments