Browse Source

Fix ActivityIndicator to only spin on user interaction or outdated

master
Gaëtan Renaudeau 7 years ago
parent
commit
1145eed414
  1. 14
      src/components/TopBar/ActivityIndicator.js

14
src/components/TopBar/ActivityIndicator.js

@ -38,16 +38,24 @@ type Props = {
setSyncBehavior: *, setSyncBehavior: *,
} }
class ActivityIndicatorInner extends PureComponent<Props> { class ActivityIndicatorInner extends PureComponent<Props, { lastClickTime: number }> {
state = {
lastClickTime: 0,
}
onClick = () => { onClick = () => {
this.props.cvPoll() this.props.cvPoll()
this.props.setSyncBehavior({ type: 'SYNC_ALL_ACCOUNTS', priority: 5 }) this.props.setSyncBehavior({ type: 'SYNC_ALL_ACCOUNTS', priority: 5 })
this.lastClickTime = Date.now()
this.setState({ lastClickTime: Date.now() })
} }
render() { render() {
const { isUpToDate, isPending, isError, error, t } = this.props const { isUpToDate, isPending, isError, error, t } = this.props
const isDisabled = isError || isPending const { lastClickTime } = this.state
const isRotating = isPending const isUserClick = Date.now() - lastClickTime < 1000
const isRotating = isPending && (!isUpToDate || isUserClick)
const isDisabled = isError || isRotating
const content = ( const content = (
<ItemContainer disabled={isDisabled} onClick={isDisabled ? undefined : this.onClick}> <ItemContainer disabled={isDisabled} onClick={isDisabled ? undefined : this.onClick}>

Loading…
Cancel
Save