Skip to content

Commit

Permalink
instead of dedicated state, use existing locations array to determine…
Browse files Browse the repository at this point in the history
… if clear data should be enabled
  • Loading branch information
bacalj committed Aug 26, 2024
1 parent 6a462ff commit b90fa3f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ export const App: React.FC = () => {
const [locationSearch, setLocationSearch] = useState<string>("");
const [selectedAttrs, setSelectedAttributes] = useState<string[]>(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<ICurrentDayLocation>({
Expand Down Expand Up @@ -204,7 +202,7 @@ export const App: React.FC = () => {
setSelectedAttributes={setSelectedAttributes}
setLocations={setLocations}
handleGetDataClick={handleGetDataClick}
clearDataEnabled={clearDataEnabled}
locations={locations}
/>
</div>
<div className={clsx("tab-content", { active: activeTab === "simulation" })}>
Expand Down
9 changes: 4 additions & 5 deletions src/components/location-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<LocationTabProps> = ({
Expand All @@ -33,13 +33,12 @@ export const LocationTab: React.FC<LocationTabProps> = ({
setSelectedAttributes,
setLocations,
handleGetDataClick,
clearDataEnabled
locations
}) => {

const enableGetData = latitude !== "" && longitude !== "";

const {
dataContext,
handleClearData,
updateAttributeVisibility,
} = useCodapData();
Expand Down Expand Up @@ -141,7 +140,7 @@ export const LocationTab: React.FC<LocationTabProps> = ({
<hr className="light"/>
</div>
<div className="plugin-row data-buttons">
<button onClick={handleClearDataClick} disabled={!clearDataEnabled}>
<button onClick={handleClearDataClick} disabled={locations.length < 1}>
Clear Data
</button>
<button disabled={!enableGetData} onClick={() => handleGetDataClick(latitude, longitude)}>
Expand Down

0 comments on commit b90fa3f

Please sign in to comment.