Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route summary reporting error fixed #62

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 35 additions & 23 deletions src/Controls/Directions/Summary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@ import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import * as R from 'ramda'
import { intervalToDuration } from 'date-fns'
//import { intervalToDuration } from 'date-fns'

import { Icon, Checkbox, Popup } from 'semantic-ui-react'
import { showProvider } from '../../actions/directionsActions'

class Summary extends React.Component {
constructor(props) {
super(props)
this.state = { tileset_last_modified: 0 }
}
componentDidMount() {
this.getTileModifiedData()
}
async getTileModifiedData() {
const res = await (
await fetch('https://valhalla1.openstreetmap.de/status')
).json()
console.log(res)
this.setState({ tileset_last_modified: res.tileset_last_modified })
}
static propTypes = {
dispatch: PropTypes.func.isRequired,
results: PropTypes.object,
Expand All @@ -22,38 +36,36 @@ class Summary extends React.Component {
}

formatDuration = (durationInSeconds) => {
const duration = intervalToDuration({
start: 0,
end: durationInSeconds * 1000,
})

let durationStr = ''
if (duration.days > 0) {
durationStr += duration.days + 'd '
}
if (duration.hours > 0) {
durationStr += duration.hours + 'h '
}
if (duration.minutes > 0) {
durationStr += duration.minutes + 'min '
}
if (duration.seconds > 0) {
durationStr += duration.seconds + 'sec'
}
return durationStr
const date = new Date(durationInSeconds * 1000)
const days = date.getDate() - 1 > 0 ? date.getDate() - 1 + 'd ' : ''
const hours = date.getHours() > 0 ? date.getHours() + 'h ' : ''
const minutes = date.getMinutes() > 0 ? date.getMinutes() + 'min' : ''
return days + hours + minutes
}
tileLastModifiedTime = (durationInSeconds) => {
const date = new Date(durationInSeconds * 1000)
const days = new Date().getDate() - date.getDate() + 'd'
const hours = new Date().getHours() - date.getHours() + 'h'
return days + ' ' + hours
}

render() {
const { provider, results, inclineDeclineTotal } = this.props

const summary = R.path([provider, 'data', 'trip', 'summary'], results)

console.log(summary.time)
return (
<React.Fragment>
{summary ? (
<React.Fragment>
<div className="flex mb1">
<span className="b">Directions</span>
<span className="b">Directions</span>&nbsp;&nbsp;
<span className="b">
TileSet_Last_Modified:&nbsp;
{`${this.tileLastModifiedTime(
this.state.tileset_last_modified
)}`}
&nbsp;ago
</span>
</div>
<div className={'flex justify-between pb2 pointer'}>
<div
Expand Down