mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-04-20 06:53:56 -04:00
* Add KebabMenu to shared components index * Separate EvidenceList from PhotoCarousel component * Remove unneeded props from PhotoCarousel * Create notes bottom sheet * Fix tests for delete obs sheet * Add wild status sheet * Show date from observations uploaded via website * Move media viewer modal into evidence section * Fix mock * Move location fetching into its own hook * Refactor ObsEdit header; move code into Header component * Add discard changes sheet * Styling updates and save changes button * Add classes to buttons based on evidence/id missing * Add imprecise location sheet * Add jest.fn from provider to ObsEdit tests * Remove fakeTimers from ObsEditWithoutProvider.test.js; minor cleanup * Show discard obs sheet anytime a user tries to navigate back * Fixes to bottom sheet backdrop, evidence, add discard changes sheet * Switch to paper radio buttons instead of checkmarks * Fix bottom sheet backdrop in android by wrapping with GestureHandlerRootView * Update bottom sheet for add comment & notes * Fix test * Remove fake timer from ObsEdit test to get tests passing * Force update github actions cache --------- Co-authored-by: Ken-ichi Ueda <kenichi.ueda@gmail.com>
111 lines
3.2 KiB
JavaScript
111 lines
3.2 KiB
JavaScript
// @flow
|
|
|
|
import classnames from "classnames";
|
|
import {
|
|
Button, StickyToolbar
|
|
} from "components/SharedComponents";
|
|
import { View } from "components/styledComponents";
|
|
import { ObsEditContext } from "providers/contexts";
|
|
import type { Node } from "react";
|
|
import React, { useContext, useState } from "react";
|
|
import useTranslation from "sharedHooks/useTranslation";
|
|
|
|
import ImpreciseLocationSheet from "./Sheets/ImpreciseLocationSheet";
|
|
import MissingEvidenceSheet from "./Sheets/MissingEvidenceSheet";
|
|
|
|
const DESIRED_LOCATION_ACCURACY = 4000000;
|
|
|
|
const BottomButtons = ( ): Node => {
|
|
const { t } = useTranslation( );
|
|
const {
|
|
saveObservation,
|
|
saveAndUploadObservation,
|
|
setNextScreen,
|
|
setLoading,
|
|
currentObservation,
|
|
unsavedChanges,
|
|
passesEvidenceTest,
|
|
passesIdentificationTest
|
|
} = useContext( ObsEditContext );
|
|
const [showMissingEvidenceSheet, setShowMissingEvidenceSheet] = useState( false );
|
|
const [showImpreciseLocationSheet, setShowImpreciseLocationSheet] = useState( false );
|
|
const [allowUserToUpload, setAllowUserToUpload] = useState( false );
|
|
|
|
const showMissingEvidence = ( ) => {
|
|
if ( allowUserToUpload ) { return false; }
|
|
// missing evidence sheet takes precedence over the location imprecise sheet
|
|
if ( !passesEvidenceTest ) {
|
|
setShowMissingEvidenceSheet( true );
|
|
setAllowUserToUpload( true );
|
|
return true;
|
|
}
|
|
if ( currentObservation.positional_accuracy
|
|
&& currentObservation.positional_accuracy > DESIRED_LOCATION_ACCURACY ) {
|
|
setShowImpreciseLocationSheet( true );
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
|
|
const handleSave = async ( ) => {
|
|
if ( showMissingEvidence( ) ) { return; }
|
|
setLoading( true );
|
|
await saveObservation( );
|
|
setLoading( false );
|
|
setNextScreen( );
|
|
};
|
|
|
|
const handleUpload = async ( ) => {
|
|
if ( showMissingEvidence( ) ) { return; }
|
|
setLoading( true );
|
|
await saveAndUploadObservation( );
|
|
setLoading( false );
|
|
setNextScreen( );
|
|
};
|
|
|
|
return (
|
|
<StickyToolbar containerClass="bottom-6">
|
|
{showMissingEvidenceSheet && (
|
|
<MissingEvidenceSheet
|
|
setShowMissingEvidenceSheet={setShowMissingEvidenceSheet}
|
|
/>
|
|
)}
|
|
{showImpreciseLocationSheet && (
|
|
<ImpreciseLocationSheet
|
|
setShowImpreciseLocationSheet={setShowImpreciseLocationSheet}
|
|
/>
|
|
)}
|
|
{currentObservation._synced_at ? (
|
|
<Button
|
|
onPress={handleSave}
|
|
testID="ObsEdit.saveChangesButton"
|
|
text={t( "SAVE-CHANGES" )}
|
|
level={unsavedChanges ? "focus" : "neutral"}
|
|
/>
|
|
) : (
|
|
<View className={classnames( "flex-row justify-evenly", {
|
|
"opacity-50": !passesEvidenceTest
|
|
} )}
|
|
>
|
|
<Button
|
|
className="px-[25px]"
|
|
onPress={handleSave}
|
|
testID="ObsEdit.saveButton"
|
|
text={t( "SAVE" )}
|
|
level="neutral"
|
|
/>
|
|
<Button
|
|
className="ml-3 grow"
|
|
level={passesEvidenceTest && passesIdentificationTest ? "focus" : "neutral"}
|
|
text={t( "UPLOAD-NOW" )}
|
|
testID="ObsEdit.uploadButton"
|
|
onPress={handleUpload}
|
|
/>
|
|
</View>
|
|
)}
|
|
</StickyToolbar>
|
|
);
|
|
};
|
|
|
|
export default BottomButtons;
|