From ce583a78f9cbf9a36ca506648c86b012f5772070 Mon Sep 17 00:00:00 2001 From: Eric Wang Date: Thu, 15 Sep 2022 22:53:02 +0000 Subject: [PATCH] Fix mobile responsiveness --- frontend/src/components/Benchmarks.tsx | 25 +++++++++--- frontend/src/components/Button.tsx | 2 +- frontend/src/components/Dropdown.tsx | 2 +- frontend/src/components/NetworkTests.tsx | 50 +++++++++++++----------- 4 files changed, 50 insertions(+), 29 deletions(-) diff --git a/frontend/src/components/Benchmarks.tsx b/frontend/src/components/Benchmarks.tsx index 55881c2..8c07e14 100644 --- a/frontend/src/components/Benchmarks.tsx +++ b/frontend/src/components/Benchmarks.tsx @@ -12,7 +12,15 @@ interface Progress { const Benchmarks = () => { const [testRunning, setTestRunning] = useState(false) - const [bytesPerSecond, setBytesPerSecond] = useState(0) + const [bpsHistory, setBpsHistory] = useState([]) + const bytesPerSecond = useMemo(() => { + // get largest number in bps bpsHistory + let largest = 0 + for (let i = 0; i < bpsHistory.length; i++) { + if (bpsHistory[i] > largest) largest = bpsHistory[i] + } + return largest + }, [bpsHistory]) const [latency, setLatency] = useState(0) const calculateGraph = (): number => { @@ -66,7 +74,7 @@ const Benchmarks = () => { const handleBenchmark = async () => { setTestRunning(true) - setBytesPerSecond(0) + setBpsHistory([]) let time = performance.now() await http.get('/benchmark/latency') @@ -94,7 +102,13 @@ const Benchmarks = () => { let topDiff = delta.size - x.size let bottomDiff = delta.time - x.time - setBytesPerSecond(topDiff / bottomDiff) + setBpsHistory((old) => { + let newHistory = [...old, topDiff / bottomDiff] + // only keep last 10 values + if (newHistory.length > 10) newHistory.shift() + + return newHistory + }) } if (progressEvent.loaded === progressEvent.total) setTestRunning(false) @@ -107,7 +121,7 @@ const Benchmarks = () => {

Benchmarks

-
+

{humanSize}

@@ -158,7 +172,7 @@ const Benchmarks = () => {
-
+
diff --git a/frontend/src/components/Button.tsx b/frontend/src/components/Button.tsx index b7e4eb6..0566d88 100644 --- a/frontend/src/components/Button.tsx +++ b/frontend/src/components/Button.tsx @@ -10,7 +10,7 @@ const ButtonStyle = styled.button` ${(props) => !props.isOutlined && css` - ${tw`hover:bg-white hover:text-black border-black bg-black text-white`} + ${tw`hover:bg-white hover:text-black border-black bg-black text-white active:bg-gray-200 active:text-black`} `} ${(props) => props.isOutlined && diff --git a/frontend/src/components/Dropdown.tsx b/frontend/src/components/Dropdown.tsx index 4fc2643..b9d2408 100644 --- a/frontend/src/components/Dropdown.tsx +++ b/frontend/src/components/Dropdown.tsx @@ -33,7 +33,7 @@ const Dropdown = (props: DropdownProps) => { onChange={(...args) => callback(...args)} value={props.value} className={ - 'bg-white transition-colors border hover:border-neutral-700 border-neutral-300 text-sm outline-none rounded px-2.5 py-2 appearance-none ' + + 'bg-white transition-colors border w-full hover:border-neutral-700 border-neutral-300 text-sm outline-none rounded px-2.5 py-2 appearance-none ' + props.className } > diff --git a/frontend/src/components/NetworkTests.tsx b/frontend/src/components/NetworkTests.tsx index 04a1acc..c69c689 100644 --- a/frontend/src/components/NetworkTests.tsx +++ b/frontend/src/components/NetworkTests.tsx @@ -3,7 +3,7 @@ import Input from '@/components/Textbox' import Dropdown from '@/components/Dropdown' import Button from '@/components/Button' import { ChevronDownIcon } from '@heroicons/react/outline' -import React, { useState } from 'react' +import React, { FormEvent, useState } from 'react' import http from '@/util/http' import Spinner from '@/components/Spinner' @@ -31,7 +31,9 @@ const NetworkTests = () => { const [testType, setTestType] = useState('ping') const [runningTest, setRunningTest] = useState(false) - const runTest = async () => { + const runTest = async (e: FormEvent ) => { + e.preventDefault() + setRunningTest(true) if (testType === 'ping') { try { @@ -63,26 +65,30 @@ const NetworkTests = () => {

Network Tests

-
- setAddress(e.target.value)} - placeholder='Address' - > - ) => - setTestType(e.target.value) - } - />{' '} - -
+
+
+ setAddress(e.target.value)} + placeholder='Address' + > + ) => + setTestType(e.target.value) + } + /> +
+ +
+
+