mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-19 13:11:23 -04:00
Upload on ObsEdit takes user to MyObservations (#747)
* Upload now drops user on ObsList; fixes for upload status & toolbar * Fix for showing ObsUploadStatus UI
This commit is contained in:
committed by
GitHub
parent
ce92daeb0a
commit
8114015c70
@@ -53,12 +53,10 @@ const ToolbarContainer = ( {
|
||||
return t( "X-observations-uploaded", { count: totalUploadCount } );
|
||||
}
|
||||
|
||||
if ( numUnuploadedObs <= 0 ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( !uploadInProgress ) {
|
||||
return t( "Upload-x-observations", { count: numUnuploadedObs } );
|
||||
return numUnuploadedObs !== 0
|
||||
? t( "Upload-x-observations", { count: numUnuploadedObs } )
|
||||
: "";
|
||||
}
|
||||
|
||||
const translationParams = {
|
||||
|
||||
@@ -18,8 +18,6 @@ const DESIRED_LOCATION_ACCURACY = 4000000;
|
||||
const BottomButtons = ( ): Node => {
|
||||
const { t } = useTranslation( );
|
||||
const {
|
||||
saveCurrentObservation,
|
||||
saveAndUploadObservation,
|
||||
setNextScreen,
|
||||
currentObservation,
|
||||
unsavedChanges,
|
||||
@@ -47,18 +45,10 @@ const BottomButtons = ( ): Node => {
|
||||
return false;
|
||||
};
|
||||
|
||||
const handleSave = async ( ) => {
|
||||
const handlePress = type => {
|
||||
if ( showMissingEvidence( ) ) { return; }
|
||||
setButtonPressed( "save" );
|
||||
await saveCurrentObservation( );
|
||||
setNextScreen( );
|
||||
};
|
||||
|
||||
const handleUpload = async ( ) => {
|
||||
if ( showMissingEvidence( ) ) { return; }
|
||||
setButtonPressed( "upload" );
|
||||
await saveAndUploadObservation( );
|
||||
setNextScreen( );
|
||||
setButtonPressed( type );
|
||||
setNextScreen( { type } );
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -76,7 +66,7 @@ const BottomButtons = ( ): Node => {
|
||||
{currentObservation?._synced_at
|
||||
? (
|
||||
<Button
|
||||
onPress={handleSave}
|
||||
onPress={( ) => handlePress( "save" )}
|
||||
testID="ObsEdit.saveChangesButton"
|
||||
text={t( "SAVE-CHANGES" )}
|
||||
level={unsavedChanges
|
||||
@@ -93,7 +83,7 @@ const BottomButtons = ( ): Node => {
|
||||
>
|
||||
<Button
|
||||
className="px-[25px]"
|
||||
onPress={handleSave}
|
||||
onPress={( ) => handlePress( "save" )}
|
||||
testID="ObsEdit.saveButton"
|
||||
text={t( "SAVE" )}
|
||||
level="neutral"
|
||||
@@ -107,7 +97,7 @@ const BottomButtons = ( ): Node => {
|
||||
: "neutral"}
|
||||
text={t( "UPLOAD-NOW" )}
|
||||
testID="ObsEdit.uploadButton"
|
||||
onPress={handleUpload}
|
||||
onPress={( ) => handlePress( "upload" )}
|
||||
loading={buttonPressed === "upload"}
|
||||
disabled={buttonPressed !== null}
|
||||
/>
|
||||
|
||||
@@ -14,8 +14,7 @@ type Props = {
|
||||
width?: string,
|
||||
height?: string,
|
||||
style?: Object,
|
||||
setShowLoginSheet: Function,
|
||||
hideUploadStatus?: boolean
|
||||
setShowLoginSheet: Function
|
||||
};
|
||||
|
||||
const ObsGridItem = ( {
|
||||
@@ -23,8 +22,7 @@ const ObsGridItem = ( {
|
||||
width = "w-full",
|
||||
height,
|
||||
style,
|
||||
setShowLoginSheet,
|
||||
hideUploadStatus
|
||||
setShowLoginSheet
|
||||
}: Props ): Node => (
|
||||
<ObsImagePreview
|
||||
source={{
|
||||
@@ -41,15 +39,13 @@ const ObsGridItem = ( {
|
||||
testID={`MyObservations.gridItem.${observation.uuid}`}
|
||||
>
|
||||
<View className="absolute bottom-0 flex p-2 w-full">
|
||||
{!hideUploadStatus && (
|
||||
<ObsUploadStatus
|
||||
observation={observation}
|
||||
layout="horizontal"
|
||||
white
|
||||
classNameMargin="mb-1"
|
||||
setShowLoginSheet={setShowLoginSheet}
|
||||
/>
|
||||
)}
|
||||
<ObsUploadStatus
|
||||
observation={observation}
|
||||
layout="horizontal"
|
||||
white
|
||||
classNameMargin="mb-1"
|
||||
setShowLoginSheet={setShowLoginSheet}
|
||||
/>
|
||||
<DisplayTaxonName
|
||||
keyBase={observation?.uuid}
|
||||
taxon={observation?.taxon}
|
||||
|
||||
@@ -58,11 +58,12 @@ const ObsUploadStatus = ( {
|
||||
if ( !observation.id ) {
|
||||
const totalProgressIncrements = needsSync( observation ) + obsPhotos;
|
||||
|
||||
if ( typeof currentProgress === "number" ) { return null; }
|
||||
const progress = currentProgress / totalProgressIncrements;
|
||||
const progress = currentProgress === "number"
|
||||
? currentProgress / totalProgressIncrements
|
||||
: 0;
|
||||
return (
|
||||
<UploadStatus
|
||||
progress={progress || 0}
|
||||
progress={progress}
|
||||
uploadObservation={() => {
|
||||
if ( !isConnected ) {
|
||||
Alert.alert(
|
||||
@@ -76,7 +77,7 @@ const ObsUploadStatus = ( {
|
||||
setShowLoginSheet( true );
|
||||
return;
|
||||
}
|
||||
uploadObservation( observation, true );
|
||||
uploadObservation( observation, { isSingleUpload: true } );
|
||||
}}
|
||||
color={whiteColor}
|
||||
completeColor={whiteColor}
|
||||
|
||||
@@ -25,7 +25,6 @@ type Props = {
|
||||
currentUser?: ?Object,
|
||||
testID: string,
|
||||
handleScroll?: Function,
|
||||
hideUploadStatus?: boolean,
|
||||
status?: string,
|
||||
showObservationsEmptyScreen?: boolean
|
||||
};
|
||||
@@ -34,8 +33,7 @@ const GUTTER = 15;
|
||||
|
||||
const Item = React.memo(
|
||||
( {
|
||||
observation, layout, gridItemWidth, setShowLoginSheet = false,
|
||||
hideUploadStatus
|
||||
observation, layout, gridItemWidth, setShowLoginSheet = false
|
||||
} ) => (
|
||||
<MyObservationsPressable observation={observation}>
|
||||
{
|
||||
@@ -51,7 +49,6 @@ const Item = React.memo(
|
||||
margin: GUTTER / 2
|
||||
}}
|
||||
setShowLoginSheet={setShowLoginSheet}
|
||||
hideUploadStatus={hideUploadStatus}
|
||||
/>
|
||||
)
|
||||
: (
|
||||
@@ -74,7 +71,6 @@ const ObservationsFlashList = ( {
|
||||
currentUser,
|
||||
testID,
|
||||
handleScroll,
|
||||
hideUploadStatus,
|
||||
status,
|
||||
showObservationsEmptyScreen
|
||||
}: Props ): Node => {
|
||||
@@ -127,7 +123,6 @@ const ObservationsFlashList = ( {
|
||||
gridItemWidth={gridItemWidth}
|
||||
allObsToUpload={allObsToUpload}
|
||||
testID={testID}
|
||||
hideUploadStatus={hideUploadStatus}
|
||||
/>
|
||||
);
|
||||
|
||||
|
||||
@@ -372,30 +372,6 @@ const ObsEditProvider = ( { children }: Props ): Node => {
|
||||
setObservations( [...updatedObservations] );
|
||||
};
|
||||
|
||||
const setNextScreen = ( ) => {
|
||||
if ( observations.length === 1 ) {
|
||||
setCurrentObservationIndex( 0 );
|
||||
setObservations( [] );
|
||||
|
||||
navigation.navigate( "TabNavigator", {
|
||||
screen: "ObservationsStackNavigator",
|
||||
params: {
|
||||
screen: "ObsList"
|
||||
}
|
||||
} );
|
||||
} else if ( currentObservationIndex === observations.length - 1 ) {
|
||||
observations.pop( );
|
||||
setCurrentObservationIndex( observations.length - 1 );
|
||||
setObservations( observations );
|
||||
} else {
|
||||
observations.splice( currentObservationIndex, 1 );
|
||||
setCurrentObservationIndex( currentObservationIndex );
|
||||
// this seems necessary for rerendering the ObsEdit screen
|
||||
setObservations( [] );
|
||||
setObservations( observations );
|
||||
}
|
||||
};
|
||||
|
||||
const deleteLocalObservation = uuid => {
|
||||
const localObservation = realm.objectForPrimaryKey( "Observation", uuid );
|
||||
if ( !localObservation ) { return; }
|
||||
@@ -510,8 +486,8 @@ const ObsEditProvider = ( { children }: Props ): Node => {
|
||||
return responses[0];
|
||||
};
|
||||
|
||||
const uploadObservation = async ( obs, isSingleUpload ) => {
|
||||
if ( isSingleUpload ) {
|
||||
const uploadObservation = async ( obs, uploadOptions ) => {
|
||||
if ( uploadOptions?.isSingleUpload ) {
|
||||
dispatch( {
|
||||
type: "UPLOAD_SINGLE_OBSERVATION",
|
||||
observation: obs
|
||||
@@ -605,9 +581,33 @@ const ObsEditProvider = ( { children }: Props ): Node => {
|
||||
return response;
|
||||
};
|
||||
|
||||
const saveAndUploadObservation = async ( ) => {
|
||||
const setNextScreen = async ( { type }: Object ) => {
|
||||
const savedObservation = await saveCurrentObservation( );
|
||||
return uploadObservation( savedObservation );
|
||||
if ( type === "upload" ) {
|
||||
uploadObservation( savedObservation, { isSingleUpload: true } );
|
||||
}
|
||||
|
||||
if ( observations.length === 1 ) {
|
||||
setCurrentObservationIndex( 0 );
|
||||
setObservations( [] );
|
||||
|
||||
navigation.navigate( "TabNavigator", {
|
||||
screen: "ObservationsStackNavigator",
|
||||
params: {
|
||||
screen: "ObsList"
|
||||
}
|
||||
} );
|
||||
} else if ( currentObservationIndex === observations.length - 1 ) {
|
||||
observations.pop( );
|
||||
setCurrentObservationIndex( observations.length - 1 );
|
||||
setObservations( observations );
|
||||
} else {
|
||||
observations.splice( currentObservationIndex, 1 );
|
||||
setCurrentObservationIndex( currentObservationIndex );
|
||||
// this seems necessary for rerendering the ObsEdit screen
|
||||
setObservations( [] );
|
||||
setObservations( observations );
|
||||
}
|
||||
};
|
||||
|
||||
const removePhotoFromList = ( list, photo ) => {
|
||||
@@ -730,7 +730,6 @@ const ObsEditProvider = ( { children }: Props ): Node => {
|
||||
addCameraPhotosToCurrentObservation,
|
||||
resetObsEditContext,
|
||||
saveCurrentObservation,
|
||||
saveAndUploadObservation,
|
||||
deleteLocalObservation,
|
||||
album,
|
||||
setAlbum,
|
||||
|
||||
Reference in New Issue
Block a user