1 |
|
2 |
|
3 | import React from "react";
|
4 | import { ErrorMessage, LoadingMessage } from "x25/Messages";
|
5 |
|
6 | type LoadingButtonPropTypes = {
|
7 | isFetching: bool;
|
8 | hasProblems: bool;
|
9 |
|
10 | onLoadMoreClick: () => void;
|
11 | };
|
12 |
|
13 | import words from "./words";
|
14 |
|
15 | class LoadingButton extends React.Component<LoadingButtonPropTypes> {
|
16 | props: LoadingButtonPropTypes;
|
17 |
|
18 | shouldComponentUpdate (nextProps : LoadingButtonPropTypes) {
|
19 | const { hasProblems, isFetching } = this.props;
|
20 |
|
21 | return (
|
22 | hasProblems !== nextProps.hasProblems ||
|
23 | isFetching !== nextProps.isFetching
|
24 | );
|
25 | }
|
26 |
|
27 | render () {
|
28 | const { isFetching, hasProblems, onLoadMoreClick } = this.props;
|
29 |
|
30 | return (
|
31 | <div className="text-center my-2">
|
32 | {
|
33 | hasProblems ? (
|
34 | <ErrorMessage message={words.ThereWasAProblem} />
|
35 | ) : null
|
36 | }
|
37 | {
|
38 | isFetching ? (
|
39 | <LoadingMessage message={words.LoadingData} sm />
|
40 | ) : (
|
41 | <button
|
42 | className="btn btn-outline-info d-print-none"
|
43 | disabled={isFetching}
|
44 | onClick={onLoadMoreClick}
|
45 | type="button">
|
46 | {isFetching ? words.Loading : words.LoadMore}
|
47 | </button>
|
48 | )
|
49 | }
|
50 | </div>
|
51 | );
|
52 | }
|
53 | }
|
54 |
|
55 | export default LoadingButton;
|