Browse Source

Refactoring old code for reusability purposes

master
GabrielTrettel 3 years ago
parent
commit
fc47bebb71
  1. 18
      src/app/components/MapModal.js
  2. 4
      src/app/components/SelfClosingModal.js
  3. 4
      src/app/components/map/OpenStreetMap.js

18
src/app/components/MapModal.js

@ -24,7 +24,7 @@ function notImplemented() {
}); });
} }
function topBar(setMarkerToRender) {
function topBar(setShowModal) {
return ( return (
<View style={styles.topBar}> <View style={styles.topBar}>
<TouchableOpacity <TouchableOpacity
@ -53,7 +53,7 @@ function topBar(setMarkerToRender) {
<TouchableOpacity <TouchableOpacity
style={styles.topBarIcon} style={styles.topBarIcon}
onPress={() => setMarkerToRender(null)}
onPress={() => setShowModal(null)}
> >
<MaterialCommunityIcons <MaterialCommunityIcons
name="close" name="close"
@ -205,21 +205,21 @@ function isPluviometer(name) {
return name === "pluviometer" || name === "officialPluviometer"; return name === "pluviometer" || name === "officialPluviometer";
} }
function MapModal({markerToRender, setMarkerToRender, markers}) {
function MapModal({showModal, setShowModal, markers}) {
var currentMarker = undefined; var currentMarker = undefined;
if (markers && markerToRender != null && markers.has(markerToRender)) {
currentMarker = markers.get(markerToRender);
if (markers && showModal != null && markers.has(showModal)) {
currentMarker = markers.get(showModal);
} }
if (currentMarker != undefined && markerToRender != null) {
if (currentMarker != undefined && showModal != null) {
return ( return (
<SelfClosingModal <SelfClosingModal
animationType="slide" animationType="slide"
transparent={true} transparent={true}
markerToRender={markerToRender}
setMarkerToRender={setMarkerToRender}
showModal={showModal}
setShowModal={setShowModal}
> >
{topBar(setMarkerToRender)}
{topBar(setShowModal)}
{componentBody(currentMarker)} {componentBody(currentMarker)}
{isPluviometer(currentMarker.name) ? moreInfo(currentMarker) : null} {isPluviometer(currentMarker.name) ? moreInfo(currentMarker) : null}
{!isPluviometer(currentMarker.name) ? reviews(currentMarker) : null} {!isPluviometer(currentMarker.name) ? reviews(currentMarker) : null}

4
src/app/components/SelfClosingModal.js

@ -14,10 +14,10 @@ export default function SelfClosingModal(props) {
<Modal <Modal
animationType={props.animationType} animationType={props.animationType}
transparent={props.transparent} transparent={props.transparent}
visible={props.markerToRender != null}
visible={props.showModal != null}
> >
<TouchableWithoutFeedback <TouchableWithoutFeedback
onPress={() => props.setMarkerToRender(null)}
onPress={() => props.setShowModal(null)}
> >
<View style={styles.modalOverlay} /> <View style={styles.modalOverlay} />
</TouchableWithoutFeedback> </TouchableWithoutFeedback>

4
src/app/components/map/OpenStreetMap.js

@ -83,8 +83,8 @@ export default function OpenStreetMap({
)} )}
<View> <View>
<MapModal <MapModal
markerToRender={markerListener}
setMarkerToRender={setMarkerListener}
showModal={markerListener}
setShowModal={setMarkerListener}
markers={markersList} markers={markersList}
/> />
</View> </View>

Loading…
Cancel
Save