Ne pas afficher l'animatedValue en cas de changement de période

pull/693/head
Maxime Quandalle 2019-09-24 14:29:58 +02:00
parent cbcbcd5139
commit 76d2101d87
No known key found for this signature in database
GPG Key ID: 428641C03D29CA10
1 changed files with 11 additions and 2 deletions

View File

@ -3,6 +3,7 @@ import React, { useRef } from 'react'
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
import { useTranslation } from 'react-i18next'
import { formatCurrency } from 'Engine/format'
import { usePeriod } from 'Selectors/analyseSelectors'
import './AnimatedTargetValue.css'
type Props = {
@ -18,13 +19,21 @@ export default function AnimatedTargetValue({ value, children }: Props) {
const previousValue = useRef()
const { language } = useTranslation().i18n
// We don't want to show the animated if the difference comes from a change in the period
const currentPeriod = usePeriod()
const previousPeriod = useRef(currentPeriod)
const difference =
previousValue.current === value || Number.isNaN(value)
? null
: (value || 0) - (previousValue.current || 0)
previousValue.current = value
const shouldDisplayDifference =
difference !== null && Math.abs(difference) > 1
difference !== null &&
previousPeriod.current === currentPeriod &&
Math.abs(difference) > 1
previousValue.current = value
previousPeriod.current = currentPeriod
return (
<>