From a371392eca0403c57c86b0c4a298b38c7d264868 Mon Sep 17 00:00:00 2001 From: Edouard Leurent Date: Sun, 15 Oct 2023 13:09:15 +0100 Subject: [PATCH] Send observation organ to backend --- frontend/contexts/ObservationContext.js | 9 +++++++++ frontend/screens/ObservationConfirm.js | 9 ++++----- frontend/screens/ObservationSelect.js | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/frontend/contexts/ObservationContext.js b/frontend/contexts/ObservationContext.js index 0038bad..5bd4f19 100644 --- a/frontend/contexts/ObservationContext.js +++ b/frontend/contexts/ObservationContext.js @@ -10,6 +10,7 @@ export const ObservationContext = React.createContext(); const initialState = { image: null, + organ: 'leaf', location: null, datetime: null, data: null, @@ -22,6 +23,11 @@ const observationReducer = (prevState, action) => { ...prevState, image: action.image, }; + case 'SET_ORGAN': + return { + ...prevState, + organ: action.organ, + }; case 'SET_LOCATION': return { ...prevState, @@ -51,6 +57,9 @@ export const useObservation = () => { setObservationImage: (imageBase64) => { dispatch({ type: 'SET_IMAGE', image: imageBase64 }); }, + setObservationOrgan: (organ) => { + dispatch({ type: 'SET_ORGAN', organ: organ }); + }, setObservationLocation: (location) => { dispatch({ type: 'SET_LOCATION', location: location }); }, diff --git a/frontend/screens/ObservationConfirm.js b/frontend/screens/ObservationConfirm.js index 879c7b2..d357d78 100644 --- a/frontend/screens/ObservationConfirm.js +++ b/frontend/screens/ObservationConfirm.js @@ -32,7 +32,6 @@ const ImageType = ({ selected, onSelect, name, text }) => { export default function ObservationConfirmScreen({ navigation, route }) { const [statusMessage, setStatusMessage] = useState(null); const { observationState, observationMethods } = useContext(ObservationContext); - const [selectedImageType, setSelectedImageType] = useState('leaf'); useEffect(() => { @@ -70,14 +69,14 @@ export default function ObservationConfirmScreen({ navigation, route }) { setSelectedImageType('leaf')} + selected={observationState.organ === 'leaf'} + onSelect={() => observationMethods.setObservationOrgan('leaf')} /> setSelectedImageType('flower')} + selected={observationState.organ === 'flower'} + onSelect={() => observationMethods.setObservationOrgan('flower')} /> { navigation.dispatch((state) => { - //update navigation state as you want. const routes = [ { name: 'Home' }, { name: 'SpeciesList' }, - { name: 'SpeciesDetail', params: { id: observationData.species } }, //you can also add params + { name: 'SpeciesDetail', params: { id: observationData.species } }, ]; return CommonActions.reset({