From dc8d58357e70e7cfc8c1462cac47b64743e2f836 Mon Sep 17 00:00:00 2001 From: Brendan Nee Date: Tue, 6 Oct 2020 17:24:53 -0700 Subject: [PATCH] Update directions.js --- components/directions.js | 67 +++++++++++++--------------------------- 1 file changed, 22 insertions(+), 45 deletions(-) diff --git a/components/directions.js b/components/directions.js index d19fc40..4491ab3 100644 --- a/components/directions.js +++ b/components/directions.js @@ -1,26 +1,19 @@ /* global window */ -const React = require('react') -import PropTypes from 'prop-types' +import React from 'react' import Weather from './weather' import { formatDistance, formatTime, formatElevation, getElevationGain, metersToFeet } from '../lib/helper' import { getCenter } from '../lib/map' -class Directions extends React.Component { - constructor(props) { - super(props) - - this.state = {} - } - - getDirections() { - if (!this.props.directions) { +const Directions = ({ directions, startAddress, endAddress, startLocation, endLocation, distance, elevationProfile, isMobile, mobileView, height }) => { + const getDirections = () => { + if (!directions) { return '' } - const directionsList = this.props.directions.reduce((memo, direction, idx) => { + const directionsList = directions.reduce((memo, direction, idx) => { if (direction[1] !== 'nameless') { memo.push(
  • {direction[0]} on {direction[1]}
  • ) } @@ -29,18 +22,18 @@ class Directions extends React.Component { }, []) directionsList.push(( -
  • arrive at {this.props.endAddress}
  • +
  • arrive at {endAddress}
  • )) - const location = getCenter(this.props.startLocation, this.props.endLocation) + const location = getCenter(startLocation, endLocation) return (
    -

    Directions to {this.props.endAddress} from {this.props.startAddress}

    +

    Directions to {endAddress} from {startAddress}

    Ride Summary

    - {formatDistance(this.props.distance)}, {formatTime(this.props.distance)}
    - {formatElevation(metersToFeet(getElevationGain(this.props.elevationProfile)))} of total climbing + {formatDistance(distance)}, {formatTime(distance)}
    + {formatElevation(metersToFeet(getElevationGain(elevationProfile)))} of total climbing
    @@ -53,36 +46,20 @@ class Directions extends React.Component { ) } - render() { - const height = this.props.height ? `${this.props.height}px` : 'auto' + return ( +