Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear data button should be disabled when there are no locations #34

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading