Files
iNaturalistReactNative/src/components/ObsEdit/ObsEditSearch.js
Amanda Bullington 37743f0652 Merge photo gallery and obs edit into main (#45)
* Add gallery library; hide camera stack in drawer navigation since we can't use a tab navigator

* Add gallery permissions ios and android

* Move to obs edit screen when a photo is selected from gallery

* Make sure camera options modal closes on navigate

* Create shared hook for reverse geocoded locations

* Obs edit; dismiss keyboard; uuid generator

* Use popup modal to search for projects / taxa from obs edit & add to obs

* Obs edit updates

* Add i18next mock for global testing

* Add tests for photo gallery

* Add test for obs edit

* Get album picker working and store albums + photos in ObsEditProvider

* Maintain photo selection across multiple photo albums

* Create GroupPhotos screen with photos sorted by timestamp across all albums

* Add styling for group photos

* Pseudocode for grouping photos

* Combine photos into observations in photo gallery

* Remove photos from camera roll selection on group photos screen

* Fix remove photos function

* Finish combine, separate, remove photo functionality

* Display multiple obs and multiple photos on obs edit screen

* Code cleanup

* Code cleanup again

* Show number observation at top of obs edit screen

* Update navigation

* Get one photo gallery test passing

* Fix obs edit test

* Fix warning eslint

* Make tests happy

* Remove unused variable
2022-02-04 09:59:49 -08:00

88 lines
2.4 KiB
JavaScript

// @flow
import * as React from "react";
import { FlatList, Pressable, Text, Image } from "react-native";
import ViewNoFooter from "../SharedComponents/ViewNoFooter";
import useRemoteObsEditSearchResults from "../../sharedHooks/useRemoteSearchResults";
import InputField from "../SharedComponents/InputField";
import { viewStyles, imageStyles } from "../../styles/search/search";
type Props = {
source: string,
closeModal: Function,
updateTaxaId: Function,
updateProjectIds: Function
}
const ObsEditSearch = ( {
source,
closeModal,
updateTaxaId,
updateProjectIds
}: Props ): React.Node => {
const [q, setQ] = React.useState( "" );
// choose users or taxa
const list = useRemoteObsEditSearchResults( q, source );
const updateObsAndCloseModal = id => {
if ( source === "taxa" ) {
updateTaxaId( id );
} else {
updateProjectIds( id );
}
closeModal( );
};
// TODO: when UI is finalized, make sure these list results are not duplicate UI
// with Search or Projects; share components if possible
const renderItem = ( { item } ) => {
if ( source === "taxa" ) {
const imageUrl = ( item && item.default_photo ) && { uri: item.default_photo.square_url };
return (
<Pressable
onPress={( ) => updateObsAndCloseModal( item.id )}
style={viewStyles.row}
testID={`ObsEditSearch.taxa.${item.id}`}
>
<Image source={imageUrl} style={imageStyles.squareImage} testID={`ObsEditSearch.taxa.${item.id}.photo`} />
<Text>{`${item.preferred_common_name} (${item.rank} ${item.name})`}</Text>
</Pressable>
);
} else {
return (
<Pressable
onPress={( ) => updateObsAndCloseModal( item.id )}
style={viewStyles.row}
testID={`ObsEditSearch.project.${item.id}`}
>
<Image
source={{ uri: item.icon }}
style={imageStyles.squareImage}
testID={`ObsEditSearch.project.${item.id}.photo`}
/>
<Text>{item.title}</Text>
</Pressable>
);
}
};
return (
<ViewNoFooter>
<InputField
handleTextChange={setQ}
placeholder={source === "taxa" ? "search for taxa" : "search for projects"}
text={q}
type="none"
/>
<FlatList
data={list}
renderItem={renderItem}
testID="ObsEditSearch.listView"
/>
</ViewNoFooter>
);
};
export default ObsEditSearch;