Skip to content

Commit

Permalink
update attribute visibility synchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
bacalj committed Aug 12, 2024
1 parent 5f7e545 commit 2a64a34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 9 additions & 10 deletions src/components/location-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,16 @@ export const LocationTab: React.FC<LocationTabProps> = ({
getUniqueLocationsInCodapData
} = useCodapData();

// TODO - this is causing re-render issues in v2, need to address attr visibility in a different way
// useEffect(() => {
// const updateAttributesVisibility = async () => {
// for (const attr of kChildCollectionAttributes) {
// const isSelected = selectedAttrs.includes(attr.name);
// await updateAttributeVisibility(attr.name, !isSelected);
// }
// };
useEffect(() => {
const updateEachAttrVisibility = () => {
for (const attr of kChildCollectionAttributes) {
const isSelected = selectedAttrs.includes(attr.name);
updateAttributeVisibility(attr.name, !isSelected);
}
};

// updateAttributesVisibility();
// }, [selectedAttrs, updateAttributeVisibility]);
updateEachAttrVisibility();
}, [selectedAttrs, updateAttributeVisibility]);

const handleLatChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setLatitude(event.target.value);
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useCodapData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ export const useCodapData = () => {
}
};

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

try {
await updateAttribute(
updateAttribute(
kDataContextName,
kChildCollectionName,
attributeName,
Expand Down

0 comments on commit 2a64a34

Please sign in to comment.