Skip to content

Commit

Permalink
Send observation organ to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
eleurent committed Oct 15, 2023
1 parent b7968ec commit a371392
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
9 changes: 9 additions & 0 deletions frontend/contexts/ObservationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const ObservationContext = React.createContext();

const initialState = {
image: null,
organ: 'leaf',
location: null,
datetime: null,
data: null,
Expand All @@ -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,
Expand Down Expand Up @@ -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 });
},
Expand Down
9 changes: 4 additions & 5 deletions frontend/screens/ObservationConfirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {

Expand Down Expand Up @@ -70,14 +69,14 @@ export default function ObservationConfirmScreen({ navigation, route }) {
<ImageType
name="leaf"
text="leaf"
selected={selectedImageType === 'leaf'}
onSelect={() => setSelectedImageType('leaf')}
selected={observationState.organ === 'leaf'}
onSelect={() => observationMethods.setObservationOrgan('leaf')}
/>
<ImageType
name="flower-outline"
text="flower"
selected={selectedImageType === 'flower'}
onSelect={() => setSelectedImageType('flower')}
selected={observationState.organ === 'flower'}
onSelect={() => observationMethods.setObservationOrgan('flower')}
/>
</View>
<MapView
Expand Down
4 changes: 2 additions & 2 deletions frontend/screens/ObservationSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const maybeSendObservationImageAsync = async (observationState, observationMetho
console.log('posting observation with location ' + JSON.stringify(observationState.location));
console.log('posting observation with datetime ' + JSON.stringify(observationState.datetime));
formData.append('image', observationState.image);
formData.append('organ', observationState.organ);
formData.append('location', JSON.stringify(observationState.location));
formData.append('datetime', observationState.datetime);
axios.post(URL_CREATE_OBSERVATION, formData, {
Expand Down Expand Up @@ -72,11 +73,10 @@ const confirmSpeciesAsync = async (observation_id, species_index, onConfirmRespo

const goToSpeciesDetails = (navigation, observationData) => {
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({
Expand Down

0 comments on commit a371392

Please sign in to comment.