Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | 2x 2x 2x 6x 6x 6x 6x 6x 6x 4x | import { Button } from "@wintermuted/ui-react";
import React from "react";
import type { Arrival, StopLocation } from "@overworld/trimet-client";
import type { ArrivalRowProps } from "./ArrivalRow";
import "./Arrivals.css";
import ArrivalsTable from "./ArrivalsTable";
export interface ArrivalsTableLoadMoreProps {
loading: boolean;
arrivals: Arrival[];
now: number;
stopLocation: StopLocation;
renderRouteIndicator: ArrivalRowProps["renderRouteIndicator"];
formatDistance: ArrivalRowProps["formatDistance"];
}
interface State {
showMore: boolean;
}
export default class ArrivalsTableLoadMore extends React.Component<
ArrivalsTableLoadMoreProps,
State
> {
constructor(props: ArrivalsTableLoadMoreProps) {
super(props);
this.state = {
showMore: false
};
this.toggleShowMore = this.toggleShowMore.bind(this);
}
public render() {
const {
arrivals,
loading = true,
now,
renderRouteIndicator,
formatDistance,
stopLocation
} = this.props;
const { showMore } = this.state;
const arrivalsCount = arrivals && arrivals.length;
return (
<div className="arrivals-wrapper">
<ArrivalsTable
arrivals={arrivals}
loading={loading}
now={now}
renderRouteIndicator={renderRouteIndicator}
formatDistance={formatDistance}
stopLocation={stopLocation}
showMore={showMore}
/>
{arrivalsCount > 5 && this.showLoadMoreControl(showMore, arrivalsCount)}
</div>
);
}
private showLoadMoreControl(showMore: boolean, arrivalCount: number) {
const additionalArrivals = arrivalCount - 5;
return (
<div className="arrivals-load-more-control">
<div className="load-more-flex-container">
{showMore && (
<Button onClick={this.toggleShowMore}>Only show 5 arrivals</Button>
)}
{!showMore && (
<Button onClick={this.toggleShowMore}>
Show {additionalArrivals} more arrivals
</Button>
)}
</div>
</div>
);
}
private toggleShowMore() {
this.setState({
showMore: !this.state.showMore
});
}
}
|