1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00

89 lines
2.1 KiB
React
Raw Normal View History

2017-06-28 14:02:54 +02:00
import React from 'react'
import {connect} from 'react-redux'
2018-10-01 15:12:26 +02:00
import moment from 'moment'
2018-10-03 15:30:41 +02:00
import RelativeTime from 'components/datetime/relative'
2017-06-28 14:02:54 +02:00
2018-10-01 15:12:26 +02:00
const RefreshState = function(props) {
if (!props.cachedAt || !props.cacheTtl) {
return null;
}
const cachedAt = moment.utc(props.cachedAt);
const cacheTtl = moment.utc(props.cacheTtl);
if (cacheTtl.isBefore(moment.utc())) {
// This means cache is currently being rebuilt
return (
<li>
2018-10-03 16:07:40 +02:00
Routes cache was built <b><RelativeTime fuzzyNow={5}
pastEvent={true}
value={cachedAt} /> </b>
2018-10-01 15:12:26 +02:00
and is currently being refreshed.
</li>
);
}
return (
<li>
2018-10-03 15:30:41 +02:00
Routes cache was built <b><RelativeTime fuzzyNow={5} value={cachedAt} /> </b>
2018-10-03 16:07:40 +02:00
and will be refreshed <b><RelativeTime value={cacheTtl} futureEvent={true} /></b>.
2018-10-01 15:12:26 +02:00
</li>
);
}
2017-06-28 14:02:54 +02:00
class ResultsBox extends React.Component {
render() {
if (this.props.query == '') {
return null;
}
2018-10-18 17:13:39 +02:00
if (this.props.isLoading) {
return null;
}
2017-06-28 14:02:54 +02:00
const queryDuration = this.props.queryDuration.toFixed(2);
2018-09-25 22:32:31 +02:00
const cachedAt = this.props.cachedAt;
const cacheTtl = this.props.cacheTtl;
2017-06-28 14:02:54 +02:00
return (
<div className="card">
<div className="lookup-result-summary">
<ul>
<li>
2018-09-25 22:44:53 +02:00
Found <b>{this.props.totalImported}</b> received
2018-09-25 22:32:31 +02:00
and <b>{this.props.totalFiltered}</b> filtered routes.
</li>
<li>Query took <b>{queryDuration} ms</b> to complete.</li>
2018-10-01 15:12:26 +02:00
<RefreshState cachedAt={this.props.cachedAt}
cacheTtl={this.props.cacheTtl} />
2017-06-28 14:02:54 +02:00
</ul>
</div>
</div>
);
}
}
export default connect(
(state) => {
return {
2018-10-18 17:13:39 +02:00
isLoading: state.lookup.isLoading,
2018-09-25 22:32:31 +02:00
totalImported: state.lookup.totalRoutesImported,
totalFiltered: state.lookup.totalRoutesFiltered,
cachedAt: state.lookup.cachedAt,
cacheTtl: state.lookup.cacheTtl,
2017-06-28 14:02:54 +02:00
queryDuration: state.lookup.queryDurationMs
}
}
)(ResultsBox)