Last active
March 12, 2021 22:49
-
-
Save QuadradS/80a260b12a6ba796a15e1d28bca0ee72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const InitialItem = ({ pickUp, dropOff, Icon, onClick, rating }) => | |
<div className="Initial__item" onClick={onClick}> | |
<div className={'Initial__cont'}> | |
{Icon} | |
<div className={'Initial__adress'}> | |
{dropOff && <div className={'Initial__marker'}> | |
<div className={'marker__typeBorder'}/> | |
<div className={'marker__typeDot'}/> | |
<div className={'marker__typeDot'}/> | |
<div className={'marker__typeCircle'}/> | |
</div>} | |
<div className="initial__row"> | |
{dropOff && <p className={'Initial__date'}> date </p>} | |
{rating && | |
<div className="initial__rating">{Rating(rating, 'initial__ratingStar')}</div>} | |
</div> | |
<p className={'Initial__pickUp'}>{pickUp}</p> | |
{dropOff && <p className={'Initial__pickUp'}>{dropOff}</p>} | |
</div> | |
</div> | |
</div>; | |
class GoogleAutoComplete extends React.PureComponent { | |
constructor(props) { | |
super(props); | |
this.state = { | |
startPosition: true, | |
destination: '', | |
origin: '' | |
}; | |
} | |
setPosition = (coordinates) => { | |
const isPickupDropOffPresent = coordinates.pickUp && coordinates.pickUp.coordinates && coordinates.dropOff && coordinates.dropOff.coordinates; | |
if (!isPickupDropOffPresent) { | |
return; | |
} | |
store.dispatch({ | |
type: 'setMapProps', | |
props: { | |
origin: { | |
lat: coordinates.pickUp.coordinates.latitude, | |
lng: coordinates.pickUp.coordinates.longitude | |
}, | |
destination: { | |
lat: coordinates.dropOff.coordinates.latitude, | |
lng: coordinates.dropOff.coordinates.longitude | |
} | |
} | |
}); | |
this.paveRoad(); | |
}; | |
handleClick = (location) => { | |
const pointType = this.state.startPosition ? 'destination' : 'origin'; | |
this.setState({ | |
[pointType]: location.id | |
}); | |
this.handleLocationChange(pointType)({ | |
lat: location.geometry.coordinates[1], | |
lng: location.geometry.coordinates[0] | |
}); | |
this.paveRoad(); | |
}; | |
handleLocationChange = property => (coordinates) => { | |
this.setState({ | |
[property]: coordinates.id | |
}); | |
const isCoordinatesPresent = coordinates.lat && coordinates.lng; | |
if (!isCoordinatesPresent) { | |
return null; | |
} | |
store.dispatch({ | |
type: 'setMapProps', | |
props: { [property]: { lat: coordinates.lat, lng: coordinates.lng } } | |
}); | |
this.paveRoad(); | |
}; | |
handlePosition = (startPosition) => () => { | |
this.setState({ | |
startPosition | |
}); | |
this.paveRoad(); | |
}; | |
recentTrips = () => { | |
if (!this.props.recentTrips) { | |
return null; | |
} | |
return ( | |
this.props.recentTrips | |
.filter((recentTrip, key) => key < 2) | |
.map((recentTrip) => { | |
return ( | |
<InitialItem | |
key={recentTrip._id} | |
pickUp={recentTrip.pickUpLocation.fullAddress} | |
dropOff={recentTrip.dropOffLocation.fullAddress} | |
Icon={() => (<RecentTrips className={'Initial__icon'}/>)} | |
onClick={() => this.setPosition({ | |
pickUp: recentTrip.pickUpLocation.geometry, | |
dropOff: recentTrip.dropOffLocation.geometry | |
})} | |
rating={4} | |
/> | |
); | |
}) | |
); | |
}; | |
paveRoad = () => { | |
this.props.onPavedRoad(); | |
}; | |
favoritesPositions = () => { | |
if (!this.props.locationDetails) { | |
return null; | |
} | |
return ( | |
this.props.locationDetails.map((favoriteLocation) => | |
<InitialItem | |
key={favoriteLocation.id} | |
pickUp={favoriteLocation.fullAddress} | |
Icon={<FavoritePositionIcon className={'Initial__icon'}/>} | |
onClick={() => this.handleClick(favoriteLocation)} | |
/>) | |
); | |
}; | |
render() { | |
return ( | |
<div className={'locationContainer'}> | |
<PlacePredictionsAutoComplete | |
value={this.state.pickup} | |
handleChange={this.handleLocationChange('destination')} | |
favoriteLocations={this.props.locationDetails} | |
recentTrips={this.props.recentTrips} | |
iconClass={'greenFill autoComplete__marker'} | |
placeholder={'Choose starting point'} | |
onHandlePosition={this.handlePosition(true)} | |
/> | |
<div className={'divider'}> | |
<div className={'divider__item'}/> | |
<div className={'divider__item'}/> | |
<div className={'divider__item'}/> | |
</div> | |
<PlacePredictionsAutoComplete | |
value={this.state.pickup} | |
handleChange={this.handleLocationChange('origin')} | |
favoriteLocations={this.props.locationDetails} | |
recentTrips={this.props.recentTrips} | |
iconClass={'redFill autoComplete__marker'} | |
placeholder={'Choose destination'} | |
onHandlePosition={this.handlePosition(false)} | |
/> | |
<div className={'tripsList__container'}> | |
<section className={'tripsList'}> | |
<p className={'tripsList__title'}>Recent Trips</p> | |
{this.recentTrips()} | |
</section> | |
<section className={'tripsList'}> | |
<p className={'tripsList__title'}>Favorites</p> | |
{this.favoritesPositions()} | |
</section> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default GoogleAutoComplete; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
+import PropTypes from 'prop-types'; | |
+import { Checkbox, FormControlLabel, FormGroup, FormHelperText, FormLabel } from 'material-ui'; | |
+ | |
+export default function MaterialCheckboxGroup(props) { | |
+ const { label, error, helperText, options, values, onChange, isChecked, containerClassName } = props; | |
+ return ( | |
+ <FormGroup className={containerClassName}> | |
+ <FormLabel component="legend">{label}</FormLabel> | |
+ <FormHelperText error={error}>{helperText}</FormHelperText> | |
+ { | |
+ options.map(it => { | |
+ return ( | |
+ <FormControlLabel | |
+ key={it.value} | |
+ control={ | |
+ <Checkbox | |
+ checked={isChecked(values, it.value)} | |
+ onChange={onChange} | |
+ value={it.value} | |
+ /> | |
+ } | |
+ label={it.label} | |
+ /> | |
+ ); | |
+ }) | |
+ } | |
+ </FormGroup> | |
+ ); | |
+} | |
+ | |
+MaterialCheckboxGroup.propTypes = { | |
+ options: PropTypes.arrayOf(PropTypes.shape({ | |
+ value: PropTypes.string, | |
+ label: PropTypes.string | |
+ })).isRequired, | |
+ values: PropTypes.arrayOf(PropTypes.string).isRequired, | |
+ onChange: PropTypes.func.isRequired, | |
+ isChecked: PropTypes.func, | |
+ label: PropTypes.string, | |
+ containerClassName: PropTypes.string, | |
+ helperText: PropTypes.string, | |
+ error: PropTypes.bool | |
+}; | |
+ | |
+MaterialCheckboxGroup.defaultProps = { | |
+ options: [], | |
+ isChecked: (values, value) => values.includes(value) | |
+}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment