Skip to content

Commit

Permalink
toooooooo messy
Browse files Browse the repository at this point in the history
  • Loading branch information
sshane committed Jul 12, 2024
1 parent 396f0d6 commit c246948
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 33 additions & 5 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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,
Expand All @@ -102,6 +117,7 @@ export function checkRoutesData() {
}

export function checkLastRoutesData() {
console.log('checkLastRoutesData')
return (dispatch, getState) => {
const limit = getState().limit
const routes = getState().routes
Expand All @@ -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();
Expand All @@ -127,6 +144,7 @@ export function checkLastRoutesData() {
end,
});

console.log('dispatch checkRoutesData: from checkLastRoutesData')
dispatch(checkRoutesData());
};
}
Expand All @@ -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) {
Expand All @@ -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();

Expand All @@ -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);
};

Expand Down Expand Up @@ -285,6 +311,7 @@ export function selectDevice(dongleId, allowPathChange = true) {
dispatch(fetchDeviceOnline(dongleId));
}

console.log('dispatch checkRoutesData: from selectDevice')
dispatch(checkRoutesData());

if (allowPathChange) {
Expand Down Expand Up @@ -432,6 +459,7 @@ export function selectTimeFilter(start, end) {
limit: undefined,
})

console.log('dispatch checkRoutesData: from selectTimeFilter')
dispatch(checkRoutesData());
};
}
Expand Down
17 changes: 17 additions & 0 deletions src/reducers/globalState.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,25 +281,31 @@ 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;
}

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,
Expand All @@ -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 = {
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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 = {
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -46,4 +47,4 @@ export function getPrimeNav(pathname) {
return true;
}
return false;
}
}

0 comments on commit c246948

Please sign in to comment.