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