Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
switch (state) {
case 'running':
runState = { ...this.state.runState, state: 'running', runAt: new Date() };
BackgroundGeolocation.start();
this._interval = setInterval(() => {
this.setState({ runningDuration: this.state.runningDuration + 1 })
}, 1000);
break;
case 'paused':
runState = { ...this.state.runState, state: 'paused', pauseAt: new Date() };
clearInterval(this._interval);
BackgroundGeolocation.stopWatchPosition();
break;
case 'resume':
runState = { ...this.state.runState, state: 'running' };
BackgroundGeolocation.watchPosition();
this._interval = setInterval(() => {
this.setState({ runningDuration: this.state.runningDuration + 1 })
}, 1000);
break;
case 'finished':
runState = { ...this.state.runState, state: 'finished', finishAt: new Date() };
clearInterval(this._interval);
BackgroundGeolocation.stop();
break;
}
await AsyncStorage.setItem(`${Configs.StorageKey}:runstate`, JSON.stringify(runState, null));
this.setState({ runState })
}
}