@@ -14,6 +14,8 @@ import Advisories from '../advisories/Advisories';
14
14
// Styling
15
15
import './CameraList.scss' ;
16
16
17
+ const collator = new Intl . Collator ( undefined , { numeric : true , sensitivity : 'base' } ) ;
18
+
17
19
export default function CameraList ( ) {
18
20
// UseRef hooks
19
21
const isInitialMount = useRef ( true ) ;
@@ -27,15 +29,17 @@ export default function CameraList() {
27
29
const webcamResults = await getWebcams ( ) ;
28
30
const cameras = groupCameras ( webcamResults ) ;
29
31
32
+ // Sort cameras by highway number
33
+ cameras . sort ( function ( a , b ) {
34
+ return collator . compare ( a . highway , b . highway )
35
+ } ) ;
36
+
30
37
setWebcams ( cameras ) ;
31
38
32
39
isInitialMount . current = false ;
33
40
} ;
34
41
35
42
const getDisplayedWebcams = ( ) => {
36
- webcams . sort ( ( a , b ) => {
37
- return parseInt ( a . highway , 10 ) - parseInt ( b . highway , 10 ) ;
38
- } ) ;
39
43
const res = webcams . slice ( 0 , displayedWebcams . length + 7 ) ;
40
44
setDisplayedWebcams ( res ) ;
41
45
} ;
@@ -52,7 +56,7 @@ export default function CameraList() {
52
56
useEffect ( ( ) => {
53
57
if ( ! isInitialMount . current ) { // Only run on updates
54
58
getDisplayedWebcams ( ) ;
55
- }
59
+ }
56
60
} , [ webcams ] ) ;
57
61
58
62
useEffect ( ( ) => {
@@ -79,35 +83,48 @@ export default function CameraList() {
79
83
} ;
80
84
81
85
const renderWebcams = ( ) => {
82
- return Object . entries ( mapDisplayedWebcams ( ) ) . map ( ( [ highway , cameras ] ) => (
83
- < div className = "highway-group" key = { highway } >
84
- < Container >
85
- < div className = "highway-title" >
86
- < div className = "highway-shield-box" >
87
- { highwayShield ( highway ) }
86
+ const groupedCams = mapDisplayedWebcams ( ) ;
87
+ const highwayKeys = Object . keys ( groupedCams ) ;
88
+
89
+ // Render camera groups by highway number
90
+ highwayKeys . sort ( collator . compare ) ;
91
+
92
+ return highwayKeys . map ( ( highway ) => {
93
+ const cameras = groupedCams [ highway ] ;
94
+
95
+ // Render cameras by highway_cam_order
96
+ cameras . sort ( ( a , b ) => a . highway_cam_order - b . highway_cam_order ) ;
97
+
98
+ return (
99
+ < div className = "highway-group" key = { highway } >
100
+ < Container >
101
+ < div className = "highway-title" >
102
+ < div className = "highway-shield-box" >
103
+ { highwayShield ( highway ) }
104
+ </ div >
105
+
106
+ < div className = "highway-name" >
107
+ < p className = "highway-name__number" > Highway { highway } </ p >
108
+ { highway === '1' &&
109
+ < h2 className = "highway-name__alias highway-name__alias--green" > Trans Canada</ h2 >
110
+ }
111
+ { highway !== '1' &&
112
+ < h2 className = "highway-name__alias" > Highway { highway } </ h2 >
113
+ }
114
+ </ div >
88
115
</ div >
89
116
90
- < div className = "highway-name" >
91
- < p className = "highway-name__number" > Highway { highway } </ p >
92
- { highway === '1' &&
93
- < h2 className = "highway-name__alias highway-name__alias--green" > Trans Canada</ h2 >
94
- }
95
- { highway !== '1' &&
96
- < h2 className = "highway-name__alias" > Highway { highway } </ h2 >
97
- }
117
+ < div className = "webcam-group" >
118
+ { cameras . map ( ( camera , id ) => (
119
+ < WebcamCard cameraData = { camera } className = "webcam" key = { id } >
120
+ </ WebcamCard >
121
+ ) ) }
98
122
</ div >
99
- </ div >
100
-
101
- < div className = "webcam-group" >
102
- { cameras . map ( ( camera , id ) => (
103
- < WebcamCard cameraData = { camera } className = "webcam" key = { id } >
104
- </ WebcamCard >
105
- ) ) }
106
- </ div >
107
- </ Container >
108
- </ div >
109
- ) ) ;
110
- } ;
123
+ </ Container >
124
+ </ div >
125
+ ) ;
126
+ } ) ;
127
+ }
111
128
112
129
return (
113
130
< div className = "camera-list" >
0 commit comments