@@ -23,38 +23,53 @@ export const DevicePackageManagerSettings: React.FC<IDevicePackageManagerSetting
2323 function DevicePackageManagerSettings ( { deviceId } : IDevicePackageManagerSettingsProps ) {
2424 const { t } = useTranslation ( )
2525 const device = useTracker ( ( ) => PeripheralDevices . findOne ( deviceId ) , [ deviceId ] , undefined )
26- const reloadingNow = useRef ( false )
26+ const reloadingNow = useRef < PeripheralDeviceId | null > ( null )
2727 const [ status , setStatus ] = useState < Status | undefined > ( undefined )
2828
29- const reloadStatus = useCallback ( ( silent = false ) => {
30- if ( reloadingNow . current ) return // if there is a method currently being executed, skip
29+ const reloadStatus = useCallback (
30+ ( silent = false ) => {
31+ if ( reloadingNow . current === deviceId ) return // if there is a method currently being executed, skip
3132
32- reloadingNow . current = true
33+ reloadingNow . current = deviceId
3334
34- MeteorCall . client
35- . callBackgroundPeripheralDeviceFunction ( deviceId , 1000 , 'getExpetationManagerStatus' )
36- . then ( ( result : Status ) => setStatus ( result ) )
37- . catch ( ( error ) => {
38- if ( silent ) {
39- logger . error ( 'callBackgroundPeripheralDeviceFunction getExpetationManagerStatus' , error )
40- return
41- }
35+ MeteorCall . client
36+ . callBackgroundPeripheralDeviceFunction ( deviceId , 1000 , 'getExpetationManagerStatus' )
37+ . then ( ( result : Status ) => {
38+ if ( reloadingNow . current !== deviceId ) return // if the deviceId has changed, abort
4239
43- doModalDialog ( {
44- message : t ( 'There was an error: {{error}}' , { error : error . toString ( ) } ) ,
45- title : t ( 'Error' ) ,
46- warning : true ,
47- onAccept : ( ) => {
48- // Do nothing
49- } ,
40+ setStatus ( result )
5041 } )
51- } )
52- . finally ( ( ) => {
53- reloadingNow . current = false
54- } )
55- } , [ ] )
42+ . catch ( ( error ) => {
43+ if ( reloadingNow . current !== deviceId ) return // if the deviceId has changed, abort
44+
45+ if ( silent ) {
46+ logger . error ( 'callBackgroundPeripheralDeviceFunction getExpetationManagerStatus' , error )
47+ return
48+ }
49+
50+ doModalDialog ( {
51+ message : t ( 'There was an error: {{error}}' , { error : error . toString ( ) } ) ,
52+ title : t ( 'Error' ) ,
53+ warning : true ,
54+ onAccept : ( ) => {
55+ // Do nothing
56+ } ,
57+ } )
58+ } )
59+ . finally ( ( ) => {
60+ reloadingNow . current = null
61+ } )
62+ } ,
63+ [ deviceId ]
64+ )
5665
5766 useEffect ( ( ) => {
67+ // Clear cached status when deviceId changes
68+ setStatus ( undefined )
69+
70+ // Trigger a load now
71+ reloadStatus ( true )
72+
5873 const reloadInterval = Meteor . setInterval ( ( ) => {
5974 if ( deviceId ) {
6075 reloadStatus ( true )
@@ -64,7 +79,7 @@ export const DevicePackageManagerSettings: React.FC<IDevicePackageManagerSetting
6479 return ( ) => {
6580 Meteor . clearInterval ( reloadInterval )
6681 }
67- } , [ ] )
82+ } , [ deviceId , reloadStatus ] )
6883
6984 function killApp ( e : string , appId : string ) {
7085 MeteorCall . client
0 commit comments