Skip to content

Commit

Permalink
Merge pull request #33 from concord-consortium/click-handle-fix
Browse files Browse the repository at this point in the history
do not depend on dataContext to define attribute visibility
  • Loading branch information
pjanik authored Aug 26, 2024
2 parents 87d7c4d + 88919b9 commit 6a462ff
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/assets/scss/header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $about-tab-width: 60px;
}

&:hover:not(.active) {
background-color: #e0e0e0;
background-color: $codap-teal-lightest;
}

&.location {
Expand Down
9 changes: 6 additions & 3 deletions src/assets/scss/location-tab.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,19 @@
&.on {
background-color: $codap-teal-lightest;
border: 1px solid $codap-teal;
&:hover {
background-color: rgba(114, 191, 202, 0.5);
}
}

&.off {
background-color: white;
border: 1px solid $codap-teal;
&:hover {
background-color: rgba(161, 161, 161, 0.25);
}
}
}
li.token:hover {
background-color: $codap-teal-lightest;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ 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 @@ -202,6 +204,7 @@ export const App: React.FC = () => {
setSelectedAttributes={setSelectedAttributes}
setLocations={setLocations}
handleGetDataClick={handleGetDataClick}
clearDataEnabled={clearDataEnabled}
/>
</div>
<div className={clsx("tab-content", { active: activeTab === "simulation" })}>
Expand Down
6 changes: 4 additions & 2 deletions src/components/location-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface LocationTabProps {
setSelectedAttributes: (attrs: string[]) => void;
setLocations: (locations: ILocation[]) => void;
handleGetDataClick: (latitude: string, longitude: string) => void;
clearDataEnabled: boolean;
}

export const LocationTab: React.FC<LocationTabProps> = ({
Expand All @@ -31,7 +32,8 @@ export const LocationTab: React.FC<LocationTabProps> = ({
setLocationSearch,
setSelectedAttributes,
setLocations,
handleGetDataClick
handleGetDataClick,
clearDataEnabled
}) => {

const enableGetData = latitude !== "" && longitude !== "";
Expand Down Expand Up @@ -139,7 +141,7 @@ export const LocationTab: React.FC<LocationTabProps> = ({
<hr className="light"/>
</div>
<div className="plugin-row data-buttons">
<button onClick={handleClearDataClick} disabled={!dataContext}>
<button onClick={handleClearDataClick} disabled={!clearDataEnabled}>
Clear Data
</button>
<button disabled={!enableGetData} onClick={() => handleGetDataClick(latitude, longitude)}>
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/useCodapData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ export const useCodapData = () => {
};

const updateAttributeVisibility = useCallback((attributeName: string, hidden: boolean) => {
if (!dataContext) return;

try {
updateAttribute(
kDataContextName,
Expand All @@ -94,7 +92,7 @@ export const useCodapData = () => {
} catch (error) {
console.error("Error updating attribute visibility:", error);
}
}, [dataContext]);
}, []);

const extractUniqueLocations = (allItems: any): ILocation[] => {
const uniqueLocations: ILocation[] = [];
Expand Down

0 comments on commit 6a462ff

Please sign in to comment.