Skip to content

Commit

Permalink
Fix to have three states, loading, empty and notEmpty (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddsaura committed Aug 3, 2022
1 parent 4c85525 commit d234857
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions frontend/src/components/App/FishbowlList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface Props {

const FishbowlList: React.FC<Props> = ({ selectedFishbowlParam }) => {
const [selectedFishbowl, setSelectedFishbowl] = useState<Fishbowl>();
const [fishbowls, setFishbowls] = useState<Fishbowl[]>([]);
const [fishbowls, setFishbowls] = useState<Fishbowl[]>();
const { width: windowWidth } = useWindowSize();
const { t, lang } = useTranslation('fishbowl-list');
const router = useRouter();
Expand All @@ -63,11 +63,13 @@ const FishbowlList: React.FC<Props> = ({ selectedFishbowlParam }) => {
};

useEffect(() => {
fishbowls.forEach(fishbowl => {
if (fishbowl.slug === selectedFishbowlParam) {
setSelectedFishbowl(fishbowl);
}
});
if (fishbowls) {
fishbowls.forEach(fishbowl => {
if (fishbowl.slug === selectedFishbowlParam) {
setSelectedFishbowl(fishbowl);
}
});
}
}, [fishbowls]); // eslint-disable-line react-hooks/exhaustive-deps

const params = new URLSearchParams([
Expand Down Expand Up @@ -95,13 +97,15 @@ const FishbowlList: React.FC<Props> = ({ selectedFishbowlParam }) => {

const handleUpdateFishbowl = updatedFishbowl => {
setFishbowls(currentFishbowls => {
return currentFishbowls.map(fishbowl => {
if (fishbowl.id !== updatedFishbowl.id) {
return fishbowl;
} else {
return { ...fishbowl, ...updatedFishbowl };
}
});
if (currentFishbowls) {
return currentFishbowls.map(fishbowl => {
if (fishbowl.id !== updatedFishbowl.id) {
return fishbowl;
} else {
return { ...fishbowl, ...updatedFishbowl };
}
});
}
});
};

Expand Down

0 comments on commit d234857

Please sign in to comment.