Skip to content

Commit e9d2703

Browse files
wmuldergovbcgov-brwang
authored andcommitted
DBC22-6536: Remove few old unmaintained packages
Replace React-Good-Carousel with Embla which is much more used and maintained Remove React-Outside-Click-Handler as we can do it natively.
1 parent 90753c4 commit e9d2703

7 files changed

Lines changed: 271 additions & 368 deletions

File tree

src/frontend/package-lock.json

Lines changed: 29 additions & 99 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/frontend/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@vaadin/time-picker": "^24.6.2",
3232
"@vladyoslav/drawer": "^0.1.0",
3333
"bootstrap": "^5.3.0",
34+
"embla-carousel-react": "^8.6.0",
3435
"env-cmd": "^10.1.0",
3536
"flatbush": "^4.4.0",
3637
"html-react-parser": "^4.2.1",
@@ -50,11 +51,9 @@
5051
"react-dnd-html5-backend": "^16.0.1",
5152
"react-dnd-multi-backend": "^8.0.0",
5253
"react-dom": "^18.2.0",
53-
"react-good-carousel": "^1.0.3",
5454
"react-image-gallery": "^1.2.12",
5555
"react-infinite-scroll-component": "^6.1.0",
5656
"react-loading-skeleton": "^3.4.0",
57-
"react-outside-click-handler": "^1.3.0",
5857
"react-redux": "^8.1.2",
5958
"react-router-bootstrap": "^0.26.2",
6059
"react-router-dom": "^6.11.2",

src/frontend/src/Components/cameras/directions/CameraOrientations.js

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ import React, { useEffect, useState } from 'react';
33

44
// External imports
55
import { 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';
107
import { useMediaQuery } from '@uidotdev/usehooks';
118
import Button from 'react-bootstrap/Button';
12-
import GoodCarousel from 'react-good-carousel';
9+
import useEmblaCarousel from 'embla-carousel-react';
1310

1411
// Internal imports
1512
import 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+
}

src/frontend/src/Components/cameras/directions/CameraOrientations.scss

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
@import "../../../styles/variables";
22

3+
4+
.embla {
5+
overflow: hidden;
6+
padding-right: 20px;
7+
}
8+
9+
.embla__container {
10+
display: flex;
11+
gap: 16px;
12+
}
13+
14+
.embla__slide {
15+
flex: 0 0 85%;
16+
min-width: 0;
17+
}
18+
319
.camera-orientations-container {
420
display: flex;
521
flex-direction: column;
@@ -157,9 +173,12 @@
157173
position: absolute;
158174
top: calc(50% - (35px / 2));
159175

160-
border: 1px solid $Input-border;
161-
border-radius: 2rem;
176+
width: 35px;
177+
height: 35px;
178+
padding: 0;
179+
border-radius: 50%; // ← circle
162180

181+
border: 1px solid $Input-border;
163182
background: #FFFFFF;
164183
color: $Type-Primary;
165184
box-shadow: 0px 3.2px 7.2px 0px #00000021, 0px 0.6px 1.8px 0px #0000001A;
@@ -182,4 +201,4 @@
182201
}
183202
}
184203
}
185-
}
204+
}

0 commit comments

Comments
 (0)