From b227828e55e69044f007f6b7851b6434765efcf9 Mon Sep 17 00:00:00 2001 From: csrapr <26280794+csrapr@users.noreply.github.com> Date: Tue, 23 Mar 2021 16:37:21 +0000 Subject: [PATCH] Chore: remove unneeded useEffect and useState hooks --- .../src/pages/Machines/Machines.js | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/new-lamassu-admin/src/pages/Machines/Machines.js b/new-lamassu-admin/src/pages/Machines/Machines.js index 2d489584..c27a6401 100644 --- a/new-lamassu-admin/src/pages/Machines/Machines.js +++ b/new-lamassu-admin/src/pages/Machines/Machines.js @@ -6,7 +6,7 @@ import NavigateNextIcon from '@material-ui/icons/NavigateNext' import classnames from 'classnames' import gql from 'graphql-tag' import * as R from 'ramda' -import React, { useState, useEffect } from 'react' +import React from 'react' import { Link, useLocation } from 'react-router-dom' import { TL1, TL2, Label3 } from 'src/components/typography' @@ -49,26 +49,18 @@ const GET_INFO = gql` const getMachines = R.path(['machines']) const Machines = () => { - const { data, refetch, loading } = useQuery(GET_INFO) + const { data, refetch } = useQuery(GET_INFO) const location = useLocation() - const [selectedMachine, setSelectedMachine] = useState('') const classes = useStyles() + const selectedMachine = + R.path(['state', 'selectedMachine'])(location) ?? + R.path(['machines', 0, 'name'])(data) ?? + '' const machines = getMachines(data) ?? [] const machineInfo = getMachineInfo(selectedMachine)(machines) ?? {} const timezone = R.path(['config', 'locale_timezone'], data) ?? {} - // pre-selects first machine from the list, if there is a machine configured. - useEffect(() => { - if (!loading && data && data.machines) { - if (location.state && location.state.selectedMachine) { - setSelectedMachine(location.state.selectedMachine) - } else { - setSelectedMachine(R.path(['machines', 0, 'name'])(data) ?? '') - } - } - }, [loading, data, location.state]) - return (