Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/188181577-attr-categories'
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanik committed Sep 13, 2024
2 parents 865d7ca + e90f341 commit ddb34af
Show file tree
Hide file tree
Showing 17 changed files with 254 additions and 284 deletions.
10 changes: 0 additions & 10 deletions src/assets/images/checkbox.svg

This file was deleted.

8 changes: 0 additions & 8 deletions src/assets/images/day-length.svg

This file was deleted.

6 changes: 6 additions & 0 deletions src/assets/images/done.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions src/assets/images/forward-back-icon.svg

This file was deleted.

6 changes: 0 additions & 6 deletions src/assets/images/forward-back-jump-icon.svg

This file was deleted.

47 changes: 0 additions & 47 deletions src/assets/images/orbital-sun.svg

This file was deleted.

6 changes: 0 additions & 6 deletions src/assets/images/pause-icon.svg

This file was deleted.

6 changes: 0 additions & 6 deletions src/assets/images/play-icon.svg

This file was deleted.

6 changes: 6 additions & 0 deletions src/assets/images/progress-indicator.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 0 additions & 18 deletions src/assets/images/slider-thumb.svg

This file was deleted.

6 changes: 6 additions & 0 deletions src/assets/images/warning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/components/header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$tab-height: 26px;
$general-tab-width: 80px;
$location-tab-width: 104px;
$simulation-tab-width: 73px;
$simulation-tab-width: 72px;
$about-tab-width: 60px;
$left-tab-margin: 3px;

Expand All @@ -22,7 +22,7 @@ $left-tab-margin: 3px;
.tab {
position: absolute;
text-align: center;
padding: 4px $tab-padding;
padding: 4px 10px;
color: #222;
border: 1px solid #222;
margin-right: -1px;
Expand Down
44 changes: 41 additions & 3 deletions src/components/location-tab.scss
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,48 @@

.data-buttons.plugin-row {
margin-top: -5px;
justify-content: flex-end;
justify-content: space-between;

button {
margin-left: 10px;
.button-container {
display: flex;
justify-content: flex-end;
flex-direction: row;

button {
margin-left: 10px;
white-space: nowrap;
}
}

.app-message div {
color: $teal-dark;
display: flex;
align-items: center;
justify-content: center;
font-size: 11.5px;

svg {
margin-right: 5px;
}

&.progress-indicator {
@keyframes rotateClockwise {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

svg {
animation: rotateClockwise 1s linear infinite;
}
}

&.done, &.incomplete, &.error {
font-weight: 600;
}
}
}

Expand Down
76 changes: 50 additions & 26 deletions src/components/location-tab.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import React, { useEffect, useState } from "react";
import { useCodapData } from "../hooks/useCodapData";
import { getDayLengthAndNASAData, clearData, updateAttributeVisibility } from "../utils/codap-utils";
import { kAttrCategories, kChildCollectionAttributes } from "../constants";
import { AttributeCategory, ILocation } from "../types";
import { LocationPicker } from "./location-picker";
import { formatLatLongNumber } from "../utils/daylight-utils";

import ProgressIndicator from "../assets/images/progress-indicator.svg";
import DoneIcon from "../assets/images/done.svg";
import WarningIcon from "../assets/images/warning.svg";

import "./location-tab.scss";
import "./get-data-button.scss";

type DataStatus = "" | "retrieving" | "retrieved" | "incomplete" | "error";

export const LocationTab: React.FC = () => {
const [latitude, setLatitude] = useState("");
const [longitude, setLongitude] = useState("");
const [startDate, setStartDate] = useState("");
const [endDate, setEndDate] = useState("");
const [locationSearch, setLocationSearch] = useState<string>("");
const [selectedAttrCategories, setSelectedAttrCategories] = useState<AttributeCategory[]>(kAttrCategories);
const [requestInProgress, setRequestInProgress] = useState(false);
const [anyDataRequested, setAnyDataRequested] = useState(false);
const { handleClearData, getDayLengthAndNASAData, updateAttributeVisibility } = useCodapData();
const [dataStatus, setDataStatus] = useState<DataStatus>("");
const [anyDataToClear, setAnyDataToClear] = useState(false);

const enableGetData = latitude !== "" && longitude !== "" && startDate !== "" && endDate !== "" && !requestInProgress;
const enableGetData = latitude !== "" && longitude !== "" && startDate !== "" && endDate !== "" && dataStatus !== "retrieving";

useEffect(() => {
const updateEachAttrVisibility = () => {
Expand All @@ -32,7 +37,7 @@ export const LocationTab: React.FC = () => {
};

updateEachAttrVisibility();
}, [selectedAttrCategories, updateAttributeVisibility]);
}, [selectedAttrCategories]);

const handleLatChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setLatitude(event.target.value);
Expand Down Expand Up @@ -71,7 +76,9 @@ export const LocationTab: React.FC = () => {
};

const handleClearDataClick = async () => {
await handleClearData();
await clearData();
setAnyDataToClear(false);
setDataStatus("");
};

const handleGetDataClick = async () => {
Expand All @@ -80,14 +87,14 @@ export const LocationTab: React.FC = () => {
if (!latitude || !longitude || !startDate || !endDate) return;

// if the location does not already exist, and we have params, get the data
setRequestInProgress(true);
setDataStatus("retrieving");
try {
await getDayLengthAndNASAData(currentLocation, startDate, endDate, selectedAttrCategories);
setAnyDataRequested(true);
const { dataComplete } = await getDayLengthAndNASAData(currentLocation, startDate, endDate, selectedAttrCategories);
setAnyDataToClear(true);
setDataStatus(dataComplete ? "retrieved" : "incomplete");
} catch (error: any) {
window.alert(error.message);
} finally {
setRequestInProgress(false);
setDataStatus("error");
}
};

Expand Down Expand Up @@ -166,20 +173,37 @@ export const LocationTab: React.FC = () => {
<hr className="light"/>
</div>
<div className="plugin-row data-buttons">
<button
className="clear-data-button"
disabled={!anyDataRequested}
onClick={handleClearDataClick}
>
Clear Data
</button>
<button
className="get-data-button"
disabled={!enableGetData}
onClick={handleGetDataClick}
>
Get Data
</button>
<div className="app-message">
{
dataStatus === "retrieving" &&
<div className="progress-indicator"><ProgressIndicator /> Retrieving data...</div>
}
{
dataStatus === "retrieved" && <div className="done"><DoneIcon /> Retrieved data</div>
}
{
dataStatus === "incomplete" && <div className="incomplete"><WarningIcon /> Some data requested are not available</div>
}
{
dataStatus === "error" && <div className="error"><WarningIcon /> Error retrieving data</div>
}
</div>
<div className="button-container">
<button
className="clear-data-button"
disabled={!anyDataToClear}
onClick={handleClearDataClick}
>
Clear Data
</button>
<button
className="get-data-button"
disabled={!enableGetData}
onClick={handleGetDataClick}
>
Get Data
</button>
</div>
</div>
</div>
);
Expand Down
Loading

0 comments on commit ddb34af

Please sign in to comment.