diff --git a/src/frontend/src/App.js b/src/frontend/src/App.js
index 680c5130c..dca905fb5 100644
--- a/src/frontend/src/App.js
+++ b/src/frontend/src/App.js
@@ -30,6 +30,8 @@ import '@fortawesome/fontawesome-svg-core/styles.css'
config.autoAddCss = false
export const MapContext = createContext(null);
+export const CamsContext = createContext(null);
+
function App() {
function getInitialMapContext() {
@@ -50,29 +52,32 @@ function App() {
}
const [mapContext, setMapContext] = useState(getInitialMapContext());
+ const [camsContext] = useState({ displayLength: 21, setDisplayLength: (length) => {} });
return (
-
-
-
-
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- {/* Catch-all route for 404 errors */}
- } />
- } />
- Website Problem or Suggestion Page
} />
- Highway or Bridge Problem Page} />
- Road Electrical Problem Page} />
-
-
+
+
+
+
+
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ {/* Catch-all route for 404 errors */}
+ } />
+ } />
+ Website Problem or Suggestion Page
} />
+ Highway or Bridge Problem Page} />
+ Road Electrical Problem Page} />
+
+
+
);
}
diff --git a/src/frontend/src/Components/cameras/CameraList.js b/src/frontend/src/Components/cameras/CameraList.js
index cc44b160d..933681fcf 100644
--- a/src/frontend/src/Components/cameras/CameraList.js
+++ b/src/frontend/src/Components/cameras/CameraList.js
@@ -1,10 +1,10 @@
// React
-import React, { useEffect, useState } from 'react';
-
+import React, { useContext, useEffect, useState } from 'react';
// Third party packages
import InfiniteScroll from 'react-infinite-scroll-component';
// Components and functions
+import { CamsContext } from '../../App.js';
import HighwayGroup from './HighwayGroup.js';
// Styling
@@ -14,50 +14,55 @@ export default function CameraList(props) {
// Props
const { cameras } = props;
+ // Contexts
+ const { camsContext } = useContext(CamsContext);
+
// UseState hooks
const [displayedCameras, setDisplayedCameras] = useState([]);
// UseEffect hooks and data functions
const getDisplayedCameras = (length) => {
- const res = cameras.slice(0, length ? length : displayedCameras.length + 7);
- setDisplayedCameras(res);
+
+ if (!length) { camsContext.displayLength += 4; }
+ const shown = cameras.slice(0, length ? length : camsContext.displayLength);
+ setDisplayedCameras(shown);
};
useEffect(() => {
if (cameras) { // Do nothing until cameras are processed
- getDisplayedCameras(21); // Load up to 21 cameras at the start
+ getDisplayedCameras(camsContext.displayLength);
}
}, [cameras]);
// Rendering
const groupDisplayedCameras = () => {
// Group adjacent cams on the same road into arrays
- const res = [];
+ const groups = [];
displayedCameras.forEach((cam) => {
const highway = cam.highway_display;
- if (res.length == 0 || res[res.length-1]['highway'] !== highway) {
- res.push({
+ if (groups.length == 0 || groups[groups.length - 1]['highway'] !== highway) {
+ groups.push({
'highway': highway,
'cams': []
- })
+ });
}
- res[res.length-1]['cams'].push(cam);
+ groups[groups.length - 1]['cams'].push(cam);
});
- return res;
+ return groups;
};
const renderHighways = () => {
const groupedCams = groupDisplayedCameras();
- const res = [];
+ const groups = [];
for (const {highway, cams} of groupedCams) {
- res.push();
+ groups.push();
}
- return res;
+ return groups;
}
const getHasMore = () => {
@@ -67,7 +72,7 @@ export default function CameraList(props) {
return (
diff --git a/src/frontend/src/Header.js b/src/frontend/src/Header.js
index 6e80dc22f..826da7aaf 100644
--- a/src/frontend/src/Header.js
+++ b/src/frontend/src/Header.js
@@ -24,8 +24,13 @@ export default function Header() {
const [expanded, setExpanded] = useState(false);
// Component functions
+ const onClickActions = () => {
+ setTimeout(() => setExpanded(false));
+ sessionStorage.setItem('scrollPosition', 0);
+ }
+
const getNavLink = (title) => {
- return setTimeout(() => setExpanded(false))}>{title}
+ return {title}
};
const xLargeScreen = useMediaQuery('only screen and (min-width : 992px)');