Skip to content

Commit

Permalink
Support batch updating auto-watering flag
Browse files Browse the repository at this point in the history
  • Loading branch information
repolevedavaj committed Apr 1, 2024
1 parent 34c312c commit 2612dee
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const i18n = new I18n({
ACTIVITY_TYPE_WATERED: 'gegossen',
ACTIVITY_TYPE_FERTILISED: 'gedüngt',
ACTIVITY_TYPE_SPRAYED: 'gespritzt',
ACTIVITY_TYPE_SWITCH_AUTO_WATERING: 'Automatische Bewässerung aktualisieren',
LAST_TIME_WATERED: 'Letztes Mal gegossen',
LAST_TIME_FERTILISED: 'Letztes Mal gedüngt',
LAST_TIME_SPRAYED: 'Letztes Mal gespritzt',
Expand Down
3 changes: 2 additions & 1 deletion src/model/ActivityType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum ActivityType {
ACTIVITY_TYPE_WATERED,
ACTIVITY_TYPE_FERTILISED,
ACTIVITY_TYPE_SPRAYED
ACTIVITY_TYPE_SPRAYED,
ACTIVITY_TYPE_SWITCH_AUTO_WATERING
}
2 changes: 1 addition & 1 deletion src/stacks/default/tabs/activities/ActivitiesStackRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type ActivitiesStackRouteParams = {
}
"activity-plant-selection": {
activityType: ActivityType,
activityDate: string
activityDate?: string
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ export default () => {
const navigation = useNavigation<ActivitiesStackNavigationProp<ActivitiesStackRoute.ACTIVITIES_OVERVIEW>>();
const route = useRoute<ActivitiesStackRouteProp<ActivitiesStackRoute.ACTIVITIES_OVERVIEW>>();

function needsDate(activityType: ActivityType) {
return activityType !== ActivityType.ACTIVITY_TYPE_SWITCH_AUTO_WATERING;
}

function executeActivity(activityType: ActivityType) {
navigation.navigate({
name: ActivitiesStackRoute.ACTIVITY_DATE_SELECTION,
params: {activityType}
});
if (needsDate(activityType)) {
navigation.navigate({
name: ActivitiesStackRoute.ACTIVITY_DATE_SELECTION,
params: {activityType}
});
} else {
navigation.navigate({
name: ActivitiesStackRoute.ACTIVITY_PLANT_SELECTION,
params: {activityType}
});
}
}

const renderActivityButtons = enumValues<ActivityType>(ActivityType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,22 @@ export default () => {
case ActivityType.ACTIVITY_TYPE_SPRAYED:
plant.lastTimeSprayed = activityDate;
break;
case ActivityType.ACTIVITY_TYPE_SWITCH_AUTO_WATERING:
plant.automaticallyWatered = true;
break;
}

await PlantService.savePlant(plant);
}

if (activityType === ActivityType.ACTIVITY_TYPE_SWITCH_AUTO_WATERING) {
const deselectedPlants = plants.filter(plant => !selectedPlants.find(selectedPlant => plant.id === selectedPlant.id));
for (const plant of deselectedPlants) {
plant.automaticallyWatered = false;
await PlantService.savePlant(plant);
}
}

navigation.dispatch(StackActions.popToTop());
}

Expand Down

0 comments on commit 2612dee

Please sign in to comment.