@@ -3,13 +3,10 @@ import React, { useEffect, useState } from 'react';
33
44// External imports
55import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
6- import {
7- faChevronRight ,
8- faChevronLeft
9- } from '@fortawesome/pro-solid-svg-icons' ;
6+ import { faChevronRight , faChevronLeft } from '@fortawesome/pro-solid-svg-icons' ;
107import { useMediaQuery } from '@uidotdev/usehooks' ;
118import Button from 'react-bootstrap/Button' ;
12- import GoodCarousel from 'react-good- carousel' ;
9+ import useEmblaCarousel from 'embla- carousel-react' ;
1310
1411// Internal imports
1512import colocatedCamIcon from '../../../images/colocated-camera.svg' ;
@@ -42,7 +39,17 @@ export default function CameraOrientations(props) {
4239 const [ currentCamIndex , setCurrentCamIndex ] = useState ( 0 ) ;
4340 const [ currentPane , setCurrentPane ] = useState ( 0 ) ;
4441
45- // Effects
42+ const [ emblaRef , emblaApi ] = useEmblaCarousel ( {
43+ align : 'start' ,
44+ slidesToScroll : perPane ,
45+ duration : 25 ,
46+ containScroll : 'trimSnaps' ,
47+ } ) ;
48+
49+ useEffect ( ( ) => {
50+ if ( emblaApi ) emblaApi . scrollTo ( currentPane ) ;
51+ } , [ currentPane , emblaApi ] ) ;
52+
4653 useEffect ( ( ) => {
4754 const nextCam = camData . camGroup [ currentCamIndex ] ;
4855 loadCamDetails ( nextCam ) ;
@@ -62,52 +69,54 @@ export default function CameraOrientations(props) {
6269 const rotateCameraOrientation = ( ) => {
6370 const currentIndex = camData . camGroup . findIndex ( cam => cam . id === camData . id ) ;
6471 const nextIndex = ( currentIndex + 1 ) % camData . camGroup . length ;
65-
6672 const nextCamera = camData . camGroup [ nextIndex ] ;
6773 switchOrientation ( nextIndex ) ;
6874 loadCamDetails ( nextCamera ) ;
6975 trackEvent ( "click" , "camera-details" , "camera-rotate" , nextCamera . name ) ;
7076 } ;
7177
72- // Switch orientation for mobile carousel
7378 const switchOrientation = ( index ) => {
7479 setCurrentCamIndex ( index ) ;
7580 setCurrentPane ( Math . floor ( index / perPane ) ) ;
7681 }
7782
78- /* Rendering */
79- // Main component
83+ const slideWidth = `calc((100% - ${ ( perPane - 1 ) * 16 } px - 12px) / ${ perPane } )` ;
84+
8085 return (
8186 < div className = "camera-orientations-container" >
8287 < div className = "header" >
83- < button className = "rotate-direction-btn"
84- onClick = { rotateCameraOrientation } >
85-
88+ < button className = "rotate-direction-btn" onClick = { rotateCameraOrientation } >
8689 < img
8790 className = "colocated-camera-icon"
8891 src = { colocatedCamIcon }
8992 role = "presentation"
9093 alt = "colocated cameras icon"
9194 />
92-
9395 < span className = "title" > Direction</ span >
9496 </ button >
9597 </ div >
9698
9799 { ( showCompactLayout || showReducedLayout ) &&
98100 < div className = "main-content carousel-container--camera-orientations" >
99- < GoodCarousel
100- className = "camera-orientations-carousel"
101- currentPane = { currentPane }
102- itemsPerPane = { perPane }
103- gap = { 16 }
104- itemPeek = { 12 }
105- animationDuration = { 0.4 } >
106-
107- { camData . camGroup . map ( ( cam , index ) => (
108- < CameraThumbnail key = { cam . id } thumbnailCamera = { cam } mainCamera = { camData . camGroup [ currentCamIndex ] } index = { index } switchOrientation = { switchOrientation } />
109- ) ) }
110- </ GoodCarousel >
101+
102+ < div className = "camera-orientations-carousel embla" ref = { emblaRef } >
103+ < div className = "embla__container" >
104+ { camData . camGroup . map ( ( cam , index ) => (
105+ < div
106+ key = { cam . id }
107+ className = "embla__slide"
108+ style = { { flex : `0 0 ${ slideWidth } ` } }
109+ >
110+ < CameraThumbnail
111+ thumbnailCamera = { cam }
112+ mainCamera = { camData . camGroup [ currentCamIndex ] }
113+ index = { index }
114+ switchOrientation = { switchOrientation }
115+ />
116+ </ div >
117+ ) ) }
118+ </ div >
119+ </ div >
111120
112121 { currentCamIndex < ( camData . camGroup . length - 1 ) && (
113122 < Button
@@ -130,10 +139,16 @@ export default function CameraOrientations(props) {
130139 { showFullLayout &&
131140 < div className = { 'main-content' + ' camCount' + camData . camGroup . length } >
132141 { camData . camGroup . map ( ( cam , index ) => (
133- < CameraThumbnail key = { cam . id } thumbnailCamera = { cam } mainCamera = { camData . camGroup [ currentCamIndex ] } index = { index } switchOrientation = { switchOrientation } />
142+ < CameraThumbnail
143+ key = { cam . id }
144+ thumbnailCamera = { cam }
145+ mainCamera = { camData . camGroup [ currentCamIndex ] }
146+ index = { index }
147+ switchOrientation = { switchOrientation }
148+ />
134149 ) ) }
135150 </ div >
136151 }
137152 </ div >
138153 ) ;
139- }
154+ }
0 commit comments