Skip to content

Commit

Permalink
remove unnecessary hook and inline task registration
Browse files Browse the repository at this point in the history
  • Loading branch information
CDFN committed Apr 24, 2024
1 parent 6eb15e4 commit 135c56d
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/frontend/hooks/tracks/useTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,28 @@ export function useTracking() {
const setTracking = useCurrentTrackStore(state => state.setTracking);
const isTracking = useCurrentTrackStore(state => state.isTracking);

const addNewTrackLocations = useCallback(
({data, error}: LocationCallbackInfo) => {
if (error) {
console.error('Error while processing location update callback', error);
}
if (data?.locations) {
addNewLocations(
data.locations.map(loc => ({
latitude: loc.coords.latitude,
longitude: loc.coords.longitude,
timestamp: loc.timestamp,
})),
);
}
},
[addNewLocations],
);

React.useEffect(() => {
TaskManager.defineTask(LOCATION_TASK_NAME, addNewTrackLocations);
}, [addNewTrackLocations]);
TaskManager.defineTask(
LOCATION_TASK_NAME,
({data, error}: LocationCallbackInfo) => {
if (error) {
console.error(
'Error while processing location update callback',
error,
);
}
if (data?.locations) {
addNewLocations(
data.locations.map(loc => ({
latitude: loc.coords.latitude,
longitude: loc.coords.longitude,
timestamp: loc.timestamp,
})),
);
}
},
);
}, []);

const startTracking = useCallback(async () => {
if (isTracking) {
Expand Down

0 comments on commit 135c56d

Please sign in to comment.