From b90fa3f7ca6413bd9974e85ca4ff5b688220556f Mon Sep 17 00:00:00 2001 From: Joe Bacal Date: Mon, 26 Aug 2024 11:54:15 -0400 Subject: [PATCH] instead of dedicated state, use existing locations array to determine if clear data should be enabled --- src/components/App.tsx | 4 +--- src/components/location-tab.tsx | 9 ++++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 70c514b..02fab10 100755 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -50,13 +50,11 @@ export const App: React.FC = () => { const [locationSearch, setLocationSearch] = useState(""); const [selectedAttrs, setSelectedAttributes] = useState(kDefaultOnAttributes); const [simEnabled, setSimEnabled] = useState(false); - const [clearDataEnabled, setClearDataEnabled] = useState(false); const { getDayLengthData, dataContext, getUniqueLocationsInCodapData } = useCodapData(); useEffect(() => { setSimEnabled(!!dataContext); - setClearDataEnabled(!!dataContext); }, [dataContext]); const currentDayLocationRef = useRef({ @@ -204,7 +202,7 @@ export const App: React.FC = () => { setSelectedAttributes={setSelectedAttributes} setLocations={setLocations} handleGetDataClick={handleGetDataClick} - clearDataEnabled={clearDataEnabled} + locations={locations} />
diff --git a/src/components/location-tab.tsx b/src/components/location-tab.tsx index b054464..6b53bbb 100644 --- a/src/components/location-tab.tsx +++ b/src/components/location-tab.tsx @@ -3,9 +3,9 @@ import { useCodapData } from "../hooks/useCodapData"; import { kChildCollectionAttributes } from "../constants"; import { ICodapDataContextInfo, ILocation } from "../types"; import { LocationPicker } from "./location-picker"; +import { formatLatLongNumber } from "../utils/daylight-utils"; import "../assets/scss/location-tab.scss"; -import { formatLatLongNumber } from "../utils/daylight-utils"; interface LocationTabProps { latitude: string; @@ -19,7 +19,7 @@ interface LocationTabProps { setSelectedAttributes: (attrs: string[]) => void; setLocations: (locations: ILocation[]) => void; handleGetDataClick: (latitude: string, longitude: string) => void; - clearDataEnabled: boolean; + locations: ILocation[]; } export const LocationTab: React.FC = ({ @@ -33,13 +33,12 @@ export const LocationTab: React.FC = ({ setSelectedAttributes, setLocations, handleGetDataClick, - clearDataEnabled + locations }) => { const enableGetData = latitude !== "" && longitude !== ""; const { - dataContext, handleClearData, updateAttributeVisibility, } = useCodapData(); @@ -141,7 +140,7 @@ export const LocationTab: React.FC = ({
-