updated styling when network is selected

This commit is contained in:
Jamie Hewitt 2022-10-10 15:13:56 +03:00
parent ca46f15d13
commit dfbb01661f
3 changed files with 20 additions and 5 deletions

View File

@ -5,12 +5,12 @@ import styles from '../styles/Home.module.css'
import { getData, getSummary, getNetworks } from '../utils/getData' import { getData, getSummary, getNetworks } from '../utils/getData'
export default function HomePage(): ReactElement { export default function HomePage(): ReactElement {
const [network, setNetwork] = useState<number>(3) const [network, setNetwork] = useState<number>(1)
const [networks, setNetworks] = useState<string[]>() const [networks, setNetworks] = useState<string[]>()
const [statuses, setStatuses] = useState<Status[]>() const [statuses, setStatuses] = useState<Status[]>()
const [summary, setSummary] = useState<Summary[]>() const [summary, setSummary] = useState<Summary[]>()
function style(state: State) { function statusStyle(state: State) {
console.log('state', state) console.log('state', state)
if (state === State.Down) { if (state === State.Down) {
return styles.down return styles.down
@ -21,6 +21,12 @@ export default function HomePage(): ReactElement {
} }
} }
function networkStyle(networkIndex: number) {
if (networkIndex === network) {
return styles.networkSelected
} else return
}
useEffect(() => { useEffect(() => {
async function getStatuses() { async function getStatuses() {
const statusData = await getData() const statusData = await getData()
@ -55,8 +61,11 @@ export default function HomePage(): ReactElement {
<div className={styles.grid}> <div className={styles.grid}>
{networks && ( {networks && (
<> <>
{networks.map((value: string) => ( {networks.map((value: string, index: number) => (
<div key={value} className={`${styles.network}`}> <div
key={value}
className={`${styles.network} ${networkStyle(index)}`}
>
{value} {value}
</div> </div>
))} ))}
@ -69,7 +78,7 @@ export default function HomePage(): ReactElement {
{summary.map((value: Summary) => ( {summary.map((value: Summary) => (
<div <div
key={value.component} key={value.component}
className={`${styles.card} ${style(value.status)}`} className={`${styles.card} ${statusStyle(value.status)}`}
> >
<h2>{value?.component}</h2> <h2>{value?.component}</h2>
<p>{value?.status}</p> <p>{value?.status}</p>

View File

@ -105,6 +105,11 @@
font-weight: 600; font-weight: 600;
transition: 0.2s ease-out; transition: 0.2s ease-out;
} }
.networkSelected {
color: #fcfcfc;
background: #41474e;
border-color: #fcfcfc;
}
.up { .up {
border: 2px solid #5fb359; border: 2px solid #5fb359;
} }

View File

@ -11,6 +11,7 @@ export async function getData(): Promise<Status[]> {
const data = [...response.data] const data = [...response.data]
console.log('1. data length', data.length) console.log('1. data length', data.length)
console.log('1. data ', data)
return data return data
} catch (error) { } catch (error) {