1- import React from 'react'
1+ import React , { useEffect , useState } from 'react'
22import { Query } from 'react-apollo'
33import classNames from 'classnames'
44
@@ -68,24 +68,25 @@ const LocationViewer = props => {
6868 const lastLocationEvents = React . useRef (
6969 initialiseLocationEvents ( firstDeviceStatus , latestDeviceStatus )
7070 )
71- React . useEffect (
72- ( ) => {
73- const currentSet = lastLocationEvents . current
74- const lastLocationEvent = currentSet [ 0 ] || { }
75- const latestLocationEvent = latestDeviceStatus . location || { }
76- if (
77- latestLocationEvent . recorded_at &&
78- dateUtils . isDateAfter (
79- latestLocationEvent . recorded_at ,
80- lastLocationEvent . recorded_at
81- )
82- ) {
83- currentSet . unshift ( latestLocationEvent )
84- lastLocationEvents . current = currentSet
85- }
86- } ,
87- [ latestDeviceStatus ]
88- )
71+ const [ showDeviceCardState , setShowDeviceCard ] = useState ( showDeviceCard )
72+ useEffect ( ( ) => {
73+ setShowDeviceCard ( showDeviceCard )
74+ } , [ showDeviceCard ] )
75+ React . useEffect ( ( ) => {
76+ const currentSet = lastLocationEvents . current
77+ const lastLocationEvent = currentSet [ 0 ] || { }
78+ const latestLocationEvent = latestDeviceStatus . location || { }
79+ if (
80+ latestLocationEvent . recorded_at &&
81+ dateUtils . isDateAfter (
82+ latestLocationEvent . recorded_at ,
83+ lastLocationEvent . recorded_at
84+ )
85+ ) {
86+ currentSet . unshift ( latestLocationEvent )
87+ lastLocationEvents . current = currentSet
88+ }
89+ } , [ latestDeviceStatus ] )
8990 const [ panToCenter , updatePanToCenter ] = React . useState ( false )
9091 const [ lastInteractionTime , setLastInteractionTime ] = React . useState ( null )
9192 const [ follow , setFollowFlag ] = React . useState ( true )
@@ -121,20 +122,17 @@ const LocationViewer = props => {
121122 setFollowFlag ( false )
122123 }
123124
124- React . useEffect (
125- ( ) => {
126- // Automatically resume following if some time of inactivity passed
127- if ( follow === false && lastInteractionTime != null ) {
128- if (
129- Date . now ( ) - lastInteractionTime >
130- CONSTANTS . map . inactivityTimer * 1000
131- ) {
132- setFollowFlag ( true )
133- }
125+ React . useEffect ( ( ) => {
126+ // Automatically resume following if some time of inactivity passed
127+ if ( follow === false && lastInteractionTime != null ) {
128+ if (
129+ Date . now ( ) - lastInteractionTime >
130+ CONSTANTS . map . inactivityTimer * 1000
131+ ) {
132+ setFollowFlag ( true )
134133 }
135- } ,
136- [ follow , lastInteractionTime , locationProps ]
137- )
134+ }
135+ } , [ follow , lastInteractionTime , locationProps ] )
138136
139137 return (
140138 < Query
@@ -156,7 +154,7 @@ const LocationViewer = props => {
156154 < div
157155 className = { classNames ( styles . cardWrapper , {
158156 [ styles . isWidget ] : isWidget ,
159- [ styles . showDeviceCard ] : ! showDeviceCard
157+ [ styles . showDeviceCard ] : ! showDeviceCardState
160158 } ) }
161159 >
162160 < Card
0 commit comments