From e64b291a01a9c6b860370441e7b48c1371092827 Mon Sep 17 00:00:00 2001 From: Piotr Grundas Date: Fri, 14 Dec 2018 17:44:27 +0100 Subject: [PATCH] [138] Reduced animation speed, hover effect + disabling actions while animating --- CHANGELOG.md | 1 + .../ProductDescription/AddToCartButton.tsx | 28 +++++++++++++------ .../ProductDescription/scss/index.scss | 3 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 552a6bfa9d..88564f798d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,3 +4,4 @@ All notable, unreleased changes to this project will be documented in this file. ## [Unreleased] Hide filters and sorting when there are no search results, add trending products to empty search, categories #151 by @piotrgrundas Add fetching menus from the API #127 by @piotrgrundas +Add add to cart indicator #138 by @piotrgrundas diff --git a/src/components/ProductDescription/AddToCartButton.tsx b/src/components/ProductDescription/AddToCartButton.tsx index 4cd6f8df39..3f58e0e8cf 100644 --- a/src/components/ProductDescription/AddToCartButton.tsx +++ b/src/components/ProductDescription/AddToCartButton.tsx @@ -6,25 +6,32 @@ import { Button, ButtonProps } from ".."; interface AddToCartButtonState { animate: boolean; + disabled: boolean; } class AddToCartButton extends React.PureComponent< ButtonProps, AddToCartButtonState > { - state = { animate: false }; + state = { animate: false, disabled: false }; animationTimeout = 800; timeout; handleAnimation = (evt: React.MouseEvent) => { - clearTimeout(this.timeout); - this.props.onClick(evt); - - this.setState({ animate: true }, () => { - this.timeout = setTimeout(() => { - this.setState({ animate: false }); - }, this.animationTimeout); - }); + if (!this.state.disabled) { + this.props.onClick(evt); + + this.setState({ animate: true, disabled: true }, () => { + setTimeout(() => { + this.setState({ animate: false }, () => { + setTimeout( + () => this.setState({ disabled: false }), + this.animationTimeout + ); + }); + }, this.animationTimeout); + }); + } }; render() { @@ -33,6 +40,9 @@ class AddToCartButton extends React.PureComponent< return (