Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
sshane committed Jul 12, 2024
1 parent c246948 commit c97d1b6
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 41 deletions.
25 changes: 1 addition & 24 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ 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 @@ -33,31 +32,25 @@ export function checkRoutesData() {
const { dongleId } = state;
const fetchRange = state.filter;

// 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}`)
if (state.segmentRange) {
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 @@ -94,7 +87,6 @@ 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 @@ -117,7 +109,6 @@ export function checkRoutesData() {
}

export function checkLastRoutesData() {
console.log('checkLastRoutesData')
return (dispatch, getState) => {
const limit = getState().limit
const routes = getState().routes
Expand All @@ -127,12 +118,10 @@ export function checkLastRoutesData() {
return
}

console.log(`fetching ${limit +LIMIT_INCREMENT } routes`)
dispatch({
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 @@ -144,7 +133,6 @@ export function checkLastRoutesData() {
end,
});

console.log('dispatch checkRoutesData: from checkLastRoutesData')
dispatch(checkRoutesData());
};
}
Expand All @@ -166,13 +154,6 @@ export function urlForState(dongleId, log_id, start, end, prime) {
}

function updateTimeline(state, dispatch, log_id, start, end, allowPathChange) {
// 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) {
dispatch(resetPlayback());
Expand All @@ -196,7 +177,6 @@ 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);
}
};
Expand All @@ -216,7 +196,6 @@ 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 @@ -311,7 +290,6 @@ export function selectDevice(dongleId, allowPathChange = true) {
dispatch(fetchDeviceOnline(dongleId));
}

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

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

console.log('dispatch checkRoutesData: from selectTimeFilter')
dispatch(checkRoutesData());
};
}
Expand Down
16 changes: 0 additions & 16 deletions src/reducers/globalState.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,31 +281,25 @@ 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 @@ -324,7 +318,6 @@ 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) {
Expand All @@ -334,7 +327,6 @@ 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 @@ -396,15 +388,10 @@ 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 @@ -422,8 +409,6 @@ 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 @@ -438,7 +423,6 @@ 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
1 change: 0 additions & 1 deletion src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ 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 Down

0 comments on commit c97d1b6

Please sign in to comment.