From c246948986fa3657a089237ce8006e0903a63d49 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 11 Jul 2024 21:53:56 -0700 Subject: [PATCH] toooooooo messy --- package.json | 2 +- pnpm-lock.yaml | 10 +++++----- src/actions/index.js | 38 ++++++++++++++++++++++++++++++++----- src/reducers/globalState.js | 17 +++++++++++++++++ src/url.js | 3 ++- 5 files changed, 58 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 93ebc83a..20f5ded1 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "node": ">=16" }, "dependencies": { - "@commaai/api": "github:commaai/comma-api#3.1.2", + "@commaai/api": "github:commaai/comma-api#3.1.3", "@commaai/my-comma-auth": "^1.4.1", "@mapbox/mapbox-sdk": "^0.15.3", "@material-ui/core": "^1.5.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aec028f7..7617c8b2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,8 +6,8 @@ settings: dependencies: '@commaai/api': - specifier: github:commaai/comma-api#3.1.2 - version: github.com/commaai/comma-api/d23b152ea64bfcd0de0937d2d525d556870820b6 + specifier: github:commaai/comma-api#3.1.3 + version: github.com/commaai/comma-api/eaae69b722eb0666c1d0f126f1cd1514a7993fb6 '@commaai/my-comma-auth': specifier: ^1.4.1 version: 1.4.1 @@ -9779,10 +9779,10 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} - github.com/commaai/comma-api/d23b152ea64bfcd0de0937d2d525d556870820b6: - resolution: {tarball: https://codeload.github.com/commaai/comma-api/tar.gz/d23b152ea64bfcd0de0937d2d525d556870820b6} + github.com/commaai/comma-api/eaae69b722eb0666c1d0f126f1cd1514a7993fb6: + resolution: {tarball: https://codeload.github.com/commaai/comma-api/tar.gz/eaae69b722eb0666c1d0f126f1cd1514a7993fb6} name: '@commaai/api' - version: 3.1.2 + version: 3.1.3 dependencies: '@babel/runtime': 7.23.5 query-string: 7.1.3 diff --git a/src/actions/index.js b/src/actions/index.js index 9c6cc3e4..03d966ec 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -17,6 +17,7 @@ const FIVE_YEARS = 1000 * 60 * 60 * 24 * 365 * 5; export function checkRoutesData() { return (dispatch, getState) => { let state = getState(); + console.log('current routes', state.lastRoutes) if (!state.dongleId) { return; } @@ -32,18 +33,31 @@ export function checkRoutesData() { const { dongleId } = state; const fetchRange = state.filter; - routesRequest = { - req: Drives.getRoutesSegments(dongleId, fetchRange.start, fetchRange.end, state.limit), - dongleId, - }; + // console.log('currentRoute', state.currentRoute, 'segmentRange', state.segmentRange) + // if (state.segmentRange && !state.lastRoutes.some(route => route.log_id === state.segmentRange?.log_id)) { + if (state.segmentRange) { // && state.lastRoutes?.length !== 0) { + console.log("has segmentRange, doing log_id query for", `${dongleId}|${state.segmentRange.log_id}`) + routesRequest = { + req: Drives.getRoutesSegments(dongleId, undefined, undefined, undefined, `${dongleId}|${state.segmentRange.log_id}`), + dongleId, + }; + } else { + console.log("no segmentRange, doing multiquery", dongleId, fetchRange.start, fetchRange.end, state.limit) + routesRequest = { + req: Drives.getRoutesSegments(dongleId, fetchRange.start, fetchRange.end, state.limit), + dongleId, + }; + } routesRequestPromise = routesRequest.req.then((routesData) => { + console.log("routesData from routesRequest", routesData) state = getState(); const currentRange = state.filter; if (currentRange.start !== fetchRange.start || currentRange.end !== fetchRange.end || state.dongleId !== dongleId) { routesRequest = null; + console.log('dispatch checkRoutesData: inside checkRoutesData?!') dispatch(checkRoutesData()); return; } @@ -80,6 +94,7 @@ export function checkRoutesData() { return b.create_time - a.create_time; }); + console.log('dispatch ACTION_ROUTES_METADATA', routes.length) dispatch({ type: Types.ACTION_ROUTES_METADATA, dongleId, @@ -102,6 +117,7 @@ export function checkRoutesData() { } export function checkLastRoutesData() { + console.log('checkLastRoutesData') return (dispatch, getState) => { const limit = getState().limit const routes = getState().routes @@ -116,6 +132,7 @@ export function checkLastRoutesData() { type: Types.ACTION_UPDATE_ROUTE_LIMIT, limit: limit + LIMIT_INCREMENT, }) + console.log('fetched those routes') const d = new Date(); const end = d.getTime(); @@ -127,6 +144,7 @@ export function checkLastRoutesData() { end, }); + console.log('dispatch checkRoutesData: from checkLastRoutesData') dispatch(checkRoutesData()); }; } @@ -148,7 +166,12 @@ export function urlForState(dongleId, log_id, start, end, prime) { } function updateTimeline(state, dispatch, log_id, start, end, allowPathChange) { - dispatch(checkRoutesData()); + // if (!state.currentRoute) { + // return; + // } + console.log('dispatch checkRoutesData: from updateTimeline') + // dispatch(checkRoutesData()); + console.log('updateTimeline state', state) if (!state.loop || !state.loop.startTime || !state.loop.duration || state.loop.startTime < start || state.loop.startTime + state.loop.duration > end || state.loop.duration < end - start) { @@ -173,12 +196,14 @@ export function popTimelineRange(log_id, allowPathChange = true) { }); const { start, end } = state.zoom.previous; + console.log('calling updateTimeline from popTimelineRange') updateTimeline(state, dispatch, log_id, start, end, allowPathChange); } }; } export function pushTimelineRange(log_id, start, end, allowPathChange = true) { + return (dispatch, getState) => { const state = getState(); @@ -191,6 +216,7 @@ export function pushTimelineRange(log_id, start, end, allowPathChange = true) { }); } + console.log('calling updateTimeline from pushTimelineRange') updateTimeline(state, dispatch, log_id, start, end, allowPathChange); }; @@ -285,6 +311,7 @@ export function selectDevice(dongleId, allowPathChange = true) { dispatch(fetchDeviceOnline(dongleId)); } + console.log('dispatch checkRoutesData: from selectDevice') dispatch(checkRoutesData()); if (allowPathChange) { @@ -432,6 +459,7 @@ export function selectTimeFilter(start, end) { limit: undefined, }) + console.log('dispatch checkRoutesData: from selectTimeFilter') dispatch(checkRoutesData()); }; } diff --git a/src/reducers/globalState.js b/src/reducers/globalState.js index c2d3a308..b01c9c33 100644 --- a/src/reducers/globalState.js +++ b/src/reducers/globalState.js @@ -281,14 +281,18 @@ export default function reducer(_state, action) { }; break; case Types.TIMELINE_POP_SELECTION: + console.log('pop', state.zoom, state.loop) if (state.zoom.previous) { + console.log('pop first') state.zoom = state.zoom.previous; } else { + console.log('pop second') state.zoom = null; state.loop = null; } break; case Types.TIMELINE_PUSH_SELECTION: { + console.log('timeline push', state.zoom, state.loop) if (!state.zoom || !action.start || !action.end || action.start < state.zoom.start || action.end > state.zoom.end) { state.files = null; } @@ -296,10 +300,12 @@ export default function reducer(_state, action) { if (!action.log_id) { state.segmentRange = null; } + console.log('push', state.segmentRange) const r = state.routes?.find((route) => route.log_id === action.log_id); if (action.log_id && r) { state.currentRoute = r; + console.log('found currentRoute from click!', state.currentRoute) if (!action.start) { state.zoom = { start: 0, @@ -318,6 +324,8 @@ export default function reducer(_state, action) { start: state.currentRoute.start_time_utc_millis, end: state.currentRoute.end_time_utc_millis, }; + console.log('updating segmentRange1') + if (!state.loop) { state.loop = { @@ -326,6 +334,7 @@ export default function reducer(_state, action) { }; } } else { + console.log('push all reset') state.zoom = null; state.loop = null; state.currentRoute = null; @@ -387,10 +396,15 @@ export default function reducer(_state, action) { }; if (!state.currentRoute && state.segmentRange) { const curr = state.routes?.find((route) => route.log_id === state.segmentRange.log_id); + console.log('ACTION_ROUTES_METADATA state.routes ', state.routes) if (curr) { + console.log('prev currentRoute', state.currentRoute) state.currentRoute = { ...curr, }; + // state.segmentRange.start = NaN + // state.segmentRange.end = NaN + console.log('found currentRoute from url loading', state.currentRoute, state.segmentRange) if (state.segmentRange.start && state.segmentRange.end) { state.zoom = { start: state.segmentRange.start, @@ -408,6 +422,8 @@ export default function reducer(_state, action) { start: state.currentRoute.start_time_utc_millis, end: state.currentRoute.end_time_utc_millis, }; + console.log('updating segmentRange2') + if (!state.loop || !state.loop.startTime || !state.loop.duration) { state.loop = { @@ -422,6 +438,7 @@ export default function reducer(_state, action) { if (!action.log_id) { state.segmentRange = null; } else { + console.log('updating segmentRange3') state.segmentRange = { log_id: action.log_id, start: action.start, diff --git a/src/url.js b/src/url.js index 75b8d592..636eaf80 100644 --- a/src/url.js +++ b/src/url.js @@ -29,6 +29,7 @@ export function getSegmentRange(pathname) { parts = parts.filter((m) => m.length); if (parts.length >= 2 && logIdRegex.test(parts[1])) { + console.log('getSegmentRange', parts[1], Number(parts[2]) * 1000, Number(parts[3]) * 1000); return { log_id: parts[1], start: Number(parts[2]) * 1000, @@ -46,4 +47,4 @@ export function getPrimeNav(pathname) { return true; } return false; -} \ No newline at end of file +}