From be2bc214dc55e071abe2533980afc4349819908a Mon Sep 17 00:00:00 2001 From: rakesh Date: Tue, 21 Feb 2023 23:20:50 +0530 Subject: [PATCH] fixed Show tileset age #56 --- src/Controls/Directions/Summary.jsx | 32 ++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Controls/Directions/Summary.jsx b/src/Controls/Directions/Summary.jsx index 64362b4..f247bf5 100644 --- a/src/Controls/Directions/Summary.jsx +++ b/src/Controls/Directions/Summary.jsx @@ -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, @@ -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 ( {summary ? (
- Directions + Directions   + + TileSet_Last_Modified:  + {`${this.tileLastModifiedTime( + this.state.tileset_last_modified + )}`} +  ago +