From ba4df918a35b504b6f84b5c268bc93b448971303 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Fri, 29 Sep 2023 12:40:17 -0700 Subject: [PATCH] fix(ui): refactor stat row --- .../Plugins/Minecraft/Minecraft.tsx | 46 ++++++----- frontend/src/components/QuickStats.tsx | 82 +++++++++---------- frontend/src/components/Stats/Stat.css | 41 ++++++++++ frontend/src/components/Stats/Stat.tsx | 19 +++++ frontend/src/components/Stats/StatRow.css | 35 ++++++++ frontend/src/components/Stats/StatRow.tsx | 21 +++++ 6 files changed, 181 insertions(+), 63 deletions(-) create mode 100644 frontend/src/components/Stats/Stat.css create mode 100644 frontend/src/components/Stats/Stat.tsx create mode 100644 frontend/src/components/Stats/StatRow.css create mode 100644 frontend/src/components/Stats/StatRow.tsx diff --git a/frontend/src/components/Plugins/Minecraft/Minecraft.tsx b/frontend/src/components/Plugins/Minecraft/Minecraft.tsx index 5a1ffe9..c0363f4 100644 --- a/frontend/src/components/Plugins/Minecraft/Minecraft.tsx +++ b/frontend/src/components/Plugins/Minecraft/Minecraft.tsx @@ -1,4 +1,7 @@ import { useEffect, useState } from 'preact/hooks' +import { StatRow } from '../../Stats/StatRow' +import { Stat } from '../../Stats/Stat' + import './Minecraft.css' interface McData { @@ -20,27 +23,26 @@ export function Minecraft() { }, []) return ( -
-
- Minecraft Server ({data.address}) -
- -
-
- {data.players} - Players Online -
- -
- {data.version} - Version -
- -
- {data.latency}ms - Latency -
-
-
+ + + + + + + + + ) } \ No newline at end of file diff --git a/frontend/src/components/QuickStats.tsx b/frontend/src/components/QuickStats.tsx index 24edd29..a347148 100644 --- a/frontend/src/components/QuickStats.tsx +++ b/frontend/src/components/QuickStats.tsx @@ -1,5 +1,7 @@ import { bytesToReadable } from '../util/byte' import './QuickStats.css' +import { Stat } from './Stats/Stat' +import { StatRow } from './Stats/StatRow' import { ArrowDown } from './icons/ArrowDown' import { ArrowUp } from './icons/ArrowUp' @@ -18,45 +20,44 @@ export function QuickStats(props: Props) { const swapUse = props.swapData[props.swapData.length - 1]?.used const diskUse = Object.keys(props.diskData).map(d => props.diskData[d][props.diskData[d].length - 1].used).reduce((a, b) => a + b) const diskTotal = Object.keys(props.diskData).map(d => props.diskData[d][props.diskData[d].length - 1].total).reduce((a, b) => a + b) + const diskDeviceCount = Object.keys(props.diskData).length const netRecieve = Object.keys(props.networkData).map(n => props.networkData[n][props.networkData[n].length - 1].recieve).reduce((a, b) => a + b) const netTransmit = Object.keys(props.networkData).map(n => props.networkData[n][props.networkData[n].length - 1].transmit).reduce((a, b) => a + b) + const netDeviceCount = Object.keys(props.networkData).length const cpuPct = props.cpuData[props.cpuData.length - 1]?.used return ( -
-
- Quick Stats -
+ + -
-
- {bytesToReadable(memoryUse)} - { - ((memoryUse / props.sysinfo.mem_size * 100) || 0).toFixed(2) - }% of total memory ({bytesToReadable(props.sysinfo.mem_size)}) -
+ -
- {bytesToReadable(swapUse)} - { - ((swapUse / props.sysinfo.swap_size * 100) || 0).toFixed(2) - }% of total swap ({bytesToReadable(props.sysinfo.swap_size)}) -
+ -
- {cpuPct.toFixed(2)}% - - ({props.sysinfo.cpu_brand}) - -
- -
- {props.processList.length} - Active Processes -
+ -
- + {bytesToReadable(netRecieve)} @@ -67,17 +68,16 @@ export function QuickStats(props: Props) { {bytesToReadable(netTransmit)} - Network RX / TX ({props.networkData.length} devices) -
- -
- {bytesToReadable(diskUse)} - { - (diskUse / diskTotal * 100).toFixed(2) - }% of {props.diskData.length} disks -
-
-
+ )} + small={'Network RX / TX (' + netDeviceCount + ' devices)'} + /> + + ) } \ No newline at end of file diff --git a/frontend/src/components/Stats/Stat.css b/frontend/src/components/Stats/Stat.css new file mode 100644 index 0000000..b5200c3 --- /dev/null +++ b/frontend/src/components/Stats/Stat.css @@ -0,0 +1,41 @@ + +.stat-mini { + font-size: 12px; +} + +.stat { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + + width: 100%; +} + +.stat-big { + font-size: 28px; + font-weight: bold; +} + +.stat-small { + font-size: 14px; + font-weight: normal; +} + +.network-stat { + display: flex; + flex-direction: row; + + align-items: center; +} + +.network-stat span { + display: flex; + flex-direction: row; + + align-items: center; +} + +.stat-seperator { + padding: 4px; +} \ No newline at end of file diff --git a/frontend/src/components/Stats/Stat.tsx b/frontend/src/components/Stats/Stat.tsx new file mode 100644 index 0000000..f16cd35 --- /dev/null +++ b/frontend/src/components/Stats/Stat.tsx @@ -0,0 +1,19 @@ +import { VNode } from 'preact' +import './Stat.css' + +interface Props { + big: string | VNode + small?: string + mini?: boolean +} + +export function Stat(props: Props) { + return ( +
+ {props.big} + + {props.small} + +
+ ) +} \ No newline at end of file diff --git a/frontend/src/components/Stats/StatRow.css b/frontend/src/components/Stats/StatRow.css new file mode 100644 index 0000000..46b3629 --- /dev/null +++ b/frontend/src/components/Stats/StatRow.css @@ -0,0 +1,35 @@ +.stat-row-outer { + display: flex; + flex-direction: column; + justify-content: space-evenly; + align-items: center; + + width: 90%; + height: 120px; + + padding-bottom: 32px; +} + +.stat-row { + display: flex; + flex-direction: row; + justify-content: space-evenly; + align-items: center; + + width: 100%; + height: 100%; + + text-align: center; +} + +.stat-row-header { + margin: 18px; +} + +.stat-row-title { + width: 100%; + text-align: center; + + font-size: 28px; + font-weight: bold; +} diff --git a/frontend/src/components/Stats/StatRow.tsx b/frontend/src/components/Stats/StatRow.tsx new file mode 100644 index 0000000..1773152 --- /dev/null +++ b/frontend/src/components/Stats/StatRow.tsx @@ -0,0 +1,21 @@ +import { VNode } from 'preact' +import './StatRow.css' + +interface Props { + children?: VNode | VNode[] + header?: string +} + +export function StatRow(props: Props) { + return ( +
+
+ {props.header} +
+ +
+ {props.children} +
+
+ ) +} \ No newline at end of file