Skip to content

Commit

Permalink
fix: troubleshooting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Jensen committed Nov 15, 2023
1 parent f029bc3 commit 4b15305
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
22 changes: 21 additions & 1 deletion src/tracking/TrackingManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,30 @@ export function TrackingManager({children, service}: PropsWithChildren<TrackingM
}
});
});
}, [dispatch, ids, service]);
}, [dispatch, service, ...ids]);

useEffect(() => {
console.log("dispatch changed");
}, [dispatch]);

useEffect(() => {
console.log("service changed");
}, [service]);

useEffect(() => {
console.log("ids changed");
}, [...ids]);

useEffect(() => {
console.log("updatePositions changed");
}, [updatePositions]);


/* Effect to defer a position update upon expiration of the tracking interval. */
const {nextUpdate} = state;
useEffect(() => {
console.log("nextUpdate changed");
}, [nextUpdate]);
useEffect(() => {
const delay = nextUpdate.diff(DateTime.utc()).toMillis();
if (delay <= 0) {
Expand Down
15 changes: 9 additions & 6 deletions src/tracking/adsbx/ADSBXTrackingProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import Axios, {AxiosHeaders, AxiosInstance, CreateAxiosDefaults} from "axios";
import {freeze} from "immer";
import _ from "lodash";
import {PropsWithChildren, useMemo} from "react";
import {PropsWithChildren, useEffect, useMemo} from "react";
import {TrackingManager} from "../TrackingManager";
import {ADSBXConfig} from "./ADSBX-types";
import {ADSBXClient} from "./ADSBXClient";
Expand All @@ -16,22 +16,25 @@ export interface ADSBXTrackingProviderProps extends ADSBXConfig {
}

export function ADSBXTrackingProvider({children, ...props}: PropsWithChildren<ADSBXTrackingProviderProps>) {
const {axiosFactory, auth, baseURL} = _.defaults({}, props, DEFAULT_PROPS);
const {axiosFactory, auth, baseURL: {href}} = _.defaults({}, props, DEFAULT_PROPS);
const positionService = useMemo(() => {
let headers = new AxiosHeaders().setAccept("application/json");
if (null != auth) {
headers = headers.set("api-auth", auth);
}
const axios = axiosFactory({
baseURL: baseURL.href,
const axios = axiosFactory(freeze({
baseURL: href,
responseType: "json",
headers: {
common: headers
}
});
}, true));
const client = ADSBXClient.create(axios.request);
return ADSBXPositionService.create(client);
}, [axiosFactory, auth, baseURL.href]);
}, [axiosFactory, auth, href]);
useEffect(() => {
console.log("positionService changed.");
}, [positionService]);
return (
<TrackingManager service={positionService}>
{children}
Expand Down

0 comments on commit 4b15305

Please sign in to comment.