Skip to content

Commit

Permalink
Some more stuff working.
Browse files Browse the repository at this point in the history
  • Loading branch information
0x7B5 committed Jun 14, 2024
1 parent 877ea3d commit 07ca400
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 35 deletions.
38 changes: 8 additions & 30 deletions src/actions/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,25 @@ export const onHistoryMiddleware = ({ dispatch, getState }) => (next) => async (
}

const pathZoom = getZoom(action.payload.location.pathname);
const pathSegmentRange = getSegmentRange(action.payload.location.pathname);

if (!pathSegmentRange && pathZoom && pathDongleId) {

if (pathZoom !== state.zoom) {
const [start, end] = [pathZoom.start, pathZoom.end];

Drives.getRoutesSegments(pathDongleId, start, end).then((routesData) => {
if (routesData && routesData.length > 0) {
const log_id = routesData[0].fullname.split('|')[1];
const duration = routesData[0].end_time_utc_millis - routesData[0].start_time_utc_millis;




// if ( updatedState.routesMeta && updatedState.routesMeta.log_id === logId) {
// console.log("logId", logId);
// dispatch(pushTimelineRange(logId, 0, duration, true));
// }
dispatch(pushTimelineRange(log_id, 0, duration, true));
dispatch(updateSegmentRange(log_id, pathSegmentRange?.start, pathSegmentRange?.end));


// const updatedState = getState();
dispatch(checkRoutesData());


// dispatch(pushTimelineRange(logId, 0, duration, true));

console.log("history state", state);
dispatch(pushTimelineRange(log_id, null, null, true));
dispatch(updateSegmentRange(log_id, 0, duration));
}
}).catch((err) => {
console.error('Error fetching routes data for log ID conversion', err);
});
} else if (pathSegmentRange && pathSegmentRange.log_id) {
if (!state.routesMeta || state.routesMeta.log_id !== pathSegmentRange.log_id) {
dispatch(checkRoutesData());
}
}

dispatch(pushTimelineRange(pathSegmentRange.log_id, pathSegmentRange.start, pathSegmentRange.end, false));
} else if (pathZoom) {
dispatch(pushTimelineRange(null, pathZoom.start, pathZoom.end, false));
const pathSegmentRange = getSegmentRange(action.payload.location.pathname);
if (pathSegmentRange !== state.segmentRange) {
// dispatch(pushTimelineRange(pathSegmentRange?.log_id, pathSegmentRange?.start, pathSegmentRange?.end, false));
dispatch(pushTimelineRange(state.segmentRange.log_id, null, null, false));
}

const pathPrimeNav = getPrimeNav(action.payload.location.pathname);
Expand Down
8 changes: 7 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function urlForState(dongleId, log_id, start, end, prime) {
}

function updateTimeline(state, dispatch, log_id, start, end, allowPathChange) {
console.log("updateTimeline", state, dispatch, log_id, start, end, allowPathChange);

dispatch(checkRoutesData());

if (!state.loop || !state.loop.startTime || !state.loop.duration || state.loop.startTime < start
Expand All @@ -125,9 +125,11 @@ function updateTimeline(state, dispatch, log_id, start, end, allowPathChange) {
dispatch(push(desiredPath));
}
}
console.log("updateTimeline", log_id, start, end, allowPathChange);
}

export function popTimelineRange(allowPathChange = true) {
console.log("popTimelineRange");
return (dispatch, getState) => {
const state = getState();
if (state.zoom.previous) {
Expand All @@ -142,9 +144,12 @@ export function popTimelineRange(allowPathChange = true) {
}

export function pushTimelineRange(log_id, start, end, allowPathChange = true) {

return (dispatch, getState) => {
const state = getState();

console.log("pushTimelineRange", state);

if (state.zoom?.start !== start || state.zoom?.end !== end || state.segmentRange?.log_id !== log_id) {
dispatch({
type: Types.TIMELINE_PUSH_SELECTION,
Expand All @@ -156,6 +161,7 @@ export function pushTimelineRange(log_id, start, end, allowPathChange = true) {

updateTimeline(state, dispatch, log_id, start, end, allowPathChange);
};

}


Expand Down
2 changes: 2 additions & 0 deletions src/components/DriveMap/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class DriveMap extends Component {

async populateMap() {
const { currentRoute } = this.props;

console.log("currentRoute", currentRoute);
if (!this.map || !currentRoute || !currentRoute.driveCoords) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/DriveView/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class DriveView extends Component {
if (zoom.previous) {
this.props.dispatch(popTimelineRange());
} else if (currentRoute) {
console.log("on back");
this.props.dispatch(
pushTimelineRange(currentRoute.log_id, null, null),
);
Expand Down
25 changes: 22 additions & 3 deletions src/reducers/globalState.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export default function reducer(_state, action) {
}
break;
case Types.TIMELINE_PUSH_SELECTION: {
console.log("TIMELINE_PUSH_SELECTION", state);
if (!state.zoom || !action.start || !action.end || action.start < state.zoom.start || action.end > state.zoom.end) {
state.files = null;
}
Expand All @@ -285,6 +286,12 @@ export default function reducer(_state, action) {
previous: state.zoom,
};
}
state.segmentRange = {
log_id: state.currentRoute.log_id,
start: state.currentRoute.start_time_utc_millis,
end: state.currentRoute.end_time_utc_millis,
};

} else {
state.zoom = null;
state.loop = null;
Expand Down Expand Up @@ -331,8 +338,6 @@ export default function reducer(_state, action) {
.reduce((obj, id) => { obj[id] = state.filesUploading[id]; return obj; }, {});
break;
case Types.ACTION_ROUTES_METADATA:
console.log("routesData", action);
console.log("state", state);
state.routes = action.routes;
state.routesMeta = {
dongleId: action.dongleId,
Expand All @@ -356,16 +361,30 @@ export default function reducer(_state, action) {
end: state.currentRoute.duration,
};
}

console.log("FOUND CURRENT ROUTE", state.currentRoute, state.segmentRange, state.zoom);

state.segmentRange = {
log_id: curr.log_id,
start: state.currentRoute.start_time_utc_millis,
end: state.currentRoute.end_time_utc_millis,
};
}
}
break;
case Types.ACTION_UPDATE_SEGMENT_RANGE:
case Types.ACTION_UPDATE_SEGMENT_RANGE: {
console.log("ACTION_UPDATE_SEGMENT_RANGE");
const r = state.routes?.find((route) => route.log_id === action.log_id);

console.log("r", r);

state.segmentRange = {
log_id: action.log_id,
start: action.start,
end: action.end,
};
break;
}
default:
return state;
}
Expand Down
3 changes: 3 additions & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ const store = Redux.createStore(
)),
);

//TODO: REMOVE THIS (ONLY FOR DEBUG)
window.store = store;

export default store;
1 change: 0 additions & 1 deletion src/timeline/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ export function currentOffset(state = null) {
offset = ((offset - loopOffset) % state.loop.duration) + loopOffset;
}
}

return offset;
}
2 changes: 2 additions & 0 deletions src/timeline/playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export function reducer(_state, action) {
}
break;
case Types.ACTION_LOOP:

console.log('loop', action.start, action.end, state);
if (action.start && action.end) {
state.loop = {
startTime: action.start,
Expand Down

0 comments on commit 07ca400

Please sign in to comment.