Skip to content

Commit

Permalink
fixed Show tileset age nilsnolde#56
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshhotker committed Feb 21, 2023
1 parent 60dcf13 commit be2bc21
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/Controls/Directions/Summary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ 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 @@ -28,18 +42,30 @@ class Summary extends React.Component {
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

0 comments on commit be2bc21

Please sign in to comment.