From 07ca400b742c05238a594c658a208c96677d43e6 Mon Sep 17 00:00:00 2001 From: 0x7B5 Date: Thu, 13 Jun 2024 20:50:42 -0400 Subject: [PATCH] Some more stuff working. --- src/actions/history.js | 38 +++++++----------------------- src/actions/index.js | 8 ++++++- src/components/DriveMap/index.jsx | 2 ++ src/components/DriveView/index.jsx | 1 + src/reducers/globalState.js | 25 +++++++++++++++++--- src/store.js | 3 +++ src/timeline/index.js | 1 - src/timeline/playback.js | 2 ++ 8 files changed, 45 insertions(+), 35 deletions(-) diff --git a/src/actions/history.js b/src/actions/history.js index eb8279c7f..ae0076014 100644 --- a/src/actions/history.js +++ b/src/actions/history.js @@ -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); diff --git a/src/actions/index.js b/src/actions/index.js index 0b88fdc9d..9ffddcca3 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -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 @@ -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) { @@ -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, @@ -156,6 +161,7 @@ export function pushTimelineRange(log_id, start, end, allowPathChange = true) { updateTimeline(state, dispatch, log_id, start, end, allowPathChange); }; + } diff --git a/src/components/DriveMap/index.jsx b/src/components/DriveMap/index.jsx index 9130ef306..e7715dab7 100644 --- a/src/components/DriveMap/index.jsx +++ b/src/components/DriveMap/index.jsx @@ -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; } diff --git a/src/components/DriveView/index.jsx b/src/components/DriveView/index.jsx index 1679a3fe3..5bdc77e8e 100644 --- a/src/components/DriveView/index.jsx +++ b/src/components/DriveView/index.jsx @@ -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), ); diff --git a/src/reducers/globalState.js b/src/reducers/globalState.js index 7049b51c7..18b5ffb0e 100644 --- a/src/reducers/globalState.js +++ b/src/reducers/globalState.js @@ -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; } @@ -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; @@ -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, @@ -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; } diff --git a/src/store.js b/src/store.js index d0f2a6e83..691cc7b25 100644 --- a/src/store.js +++ b/src/store.js @@ -22,4 +22,7 @@ const store = Redux.createStore( )), ); +//TODO: REMOVE THIS (ONLY FOR DEBUG) +window.store = store; + export default store; diff --git a/src/timeline/index.js b/src/timeline/index.js index 13e797a08..22724754f 100644 --- a/src/timeline/index.js +++ b/src/timeline/index.js @@ -29,6 +29,5 @@ export function currentOffset(state = null) { offset = ((offset - loopOffset) % state.loop.duration) + loopOffset; } } - return offset; } \ No newline at end of file diff --git a/src/timeline/playback.js b/src/timeline/playback.js index 3c1a4c039..d5d31548d 100644 --- a/src/timeline/playback.js +++ b/src/timeline/playback.js @@ -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,