Skip to content

Commit

Permalink
Show delete sensor option when user has one (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Agustinefe authored Jun 15, 2024
1 parent ce9be43 commit b24cc5b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions hanagotchi-app/src/screens/SettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ const SettingsScreen: React.FC<SettingsScreenProps> = ({navigation}) => {
[],
[myPlants]
);
const [hasDevicePlants, setHasDevicePlants] = useState<boolean>(false);
const [somePlantHasSensor, setSomePlantHasSensor] = useState<boolean>(false);
const [allPlantsHaveSensor, setAllPlantsHaveSensor] = useState<boolean>(true);

useEffect(() => {
if (myPlants && myPlants.length > 0) {
const filteredPlants = myPlants.filter((plant) => devicePlants!.some((it) => it.id_plant === plant.id));
setHasDevicePlants(filteredPlants.length > 0);
setSomePlantHasSensor(filteredPlants.length > 0);
setAllPlantsHaveSensor(myPlants.length === filteredPlants.length)
}
}, [myPlants, devicePlants]);
Expand Down Expand Up @@ -71,16 +71,18 @@ const SettingsScreen: React.FC<SettingsScreenProps> = ({navigation}) => {
<Text style={style.text}>Eliminar planta</Text>
<Icon source={chevronRight} size={23}/>
</Pressable>
{!allPlantsHaveSensor && <>
{!allPlantsHaveSensor &&
<Pressable style={style.item} onPress={() => navigation.navigate("AddSensor")}>
<Text style={style.text}>Agregar sensor</Text>
<Icon source={chevronRight} size={23}/>
</Pressable>
{hasDevicePlants && <Pressable style={style.item} onPress={() => navigation.navigate("DeleteSensor")}>
}
{somePlantHasSensor &&
<Pressable style={style.item} onPress={() => navigation.navigate("DeleteSensor")}>
<Text style={style.text}>Eliminar sensor</Text>
<Icon source={chevronRight} size={23}/>
</Pressable>}
</>}
</Pressable>
}
</>
}
</View>
Expand Down

0 comments on commit b24cc5b

Please sign in to comment.