lbry-desktop/src/ui/component/transactionRefreshButton/view.jsx

47 lines
1.2 KiB
React
Raw Normal View History

2018-11-08 18:13:36 +01:00
// @flow
import React, { PureComponent } from 'react';
import Button from 'component/button';
type Props = {
fetchTransactions: () => void,
fetchingTransactions: boolean,
};
type State = {
label: string,
disabled: boolean,
};
2019-02-13 17:27:20 +01:00
class TransactionRefreshButton extends PureComponent<Props, State> {
2018-11-08 18:13:36 +01:00
constructor() {
super();
this.state = { label: __('Refresh'), disabled: false };
(this: any).handleClick = this.handleClick.bind(this);
}
handleClick() {
const { fetchTransactions } = this.props;
// The fetchTransactions call will be super fast most of the time.
// Instead of showing a loading spinner for 100ms, change the label and show as "Refreshed!"
fetchTransactions();
this.setState({ label: __('Refreshed!'), disabled: true });
setTimeout(() => {
this.setState({ label: __('Refresh'), disabled: false });
}, 2000);
}
render() {
const { fetchingTransactions } = this.props;
const { label, disabled } = this.state;
return (
2019-05-07 23:38:29 +02:00
<Button button="inverse" label={label} onClick={this.handleClick} disabled={disabled || fetchingTransactions} />
2018-11-08 18:13:36 +01:00
);
}
}
2019-02-13 17:27:20 +01:00
export default TransactionRefreshButton;