Skip to content

Commit

Permalink
DBC22-1517: fixes and optimizations for cam list page (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-oxd authored Jan 18, 2024
1 parent db47314 commit a16b021
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/frontend/src/Components/cameras/CameraList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// React
import React, {useEffect, useState} from 'react';
import React, { useEffect, useState } from 'react';

// Third party packages
import Container from 'react-bootstrap/Container';
Expand Down Expand Up @@ -27,7 +27,9 @@ export default function CameraList(props) {
};

useEffect(() => {
getDisplayedCameras(displayedCameras.length);
if (cameras) { // Do nothing until cameras are processed
getDisplayedCameras(21); // Load up to 21 cameras at the start
}
}, [cameras]);

// Rendering
Expand Down Expand Up @@ -56,12 +58,16 @@ export default function CameraList(props) {
return highwayKeys.map((highway) => <HighwayGroup key={highway} highway={highway} cams={mappedCams[highway]} />);
}

const getHasMore = () => {
return displayedCameras.length < (cameras ? cameras.length : 0);
}

return (
<div className="camera-list">
<InfiniteScroll
dataLength={displayedCameras.length}
next={getDisplayedCameras}
hasMore={displayedCameras.length < cameras.length}
hasMore={getHasMore}
loader={<h4>Loading...</h4>}>

<Container>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/pages/CamerasListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function CamerasListPage() {
const isInitialMount = useRef(true);

// UseState hooks
const [processedCameras, setProcessedCameras] = useState([]);
const [processedCameras, setProcessedCameras] = useState(null);

// UseEffect hooks and data functions
const getCamerasData = async () => {
Expand Down

0 comments on commit a16b021

Please sign in to comment.