Skip to content

Commit f26631f

Browse files
committed
refactor: remove duplicated code. Home wrapper
1 parent fa77170 commit f26631f

File tree

11 files changed

+66
-304
lines changed

11 files changed

+66
-304
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"react-cookie-consent": "^9.0.0",
2525
"react-countdown": "^2.3.6",
2626
"react-dom": "^18.3.1",
27+
"react-error-boundary": "^5.0.0",
2728
"react-query": "^3.39.2",
2829
"react-router-dom": "^7.3.0",
2930
"react-scripts": "5.0.1",

src/2023/Home/Home2023Wrapper.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { BIG_BREAKPOINT } from "../../constants/BreakPoints";
22
import React, { FC } from "react";
33
import Faqs from "./components/Faqs/Faqs";
44
import Home from "./components/Home/Home";
5-
import SpeakersCarousel from "./components/SpeakersCarousel/SpeakersCarousel";
65
import Sponsors from "./components/Sponsors/Sponsors";
76
import styled from "styled-components";
87
import data from "../../data/2023.json";
98
import { useLocation } from "react-router";
109
import { useDocumentTitleUpdater } from "../../services/useDocumentTitleUpdate";
10+
import SpeakersCarousel from "../../components/Swiper/SpeakersCarousel";
11+
import {ROUTE_2023_SPEAKERS} from "../../constants/routes";
1112

1213
const StyledContainer = styled.div`
1314
padding-bottom: 10rem;
@@ -32,7 +33,7 @@ export const Home2023Wrapper: FC<React.PropsWithChildren<unknown>> = () => {
3233
<StyledContainer id="home-wrapper">
3334
<Home />
3435
<Faqs />
35-
<SpeakersCarousel />
36+
<SpeakersCarousel speakersLink={ROUTE_2023_SPEAKERS} sessionizeUrl={data.sessionizeUrl} />
3637
<Sponsors />
3738
</StyledContainer>
3839
);

src/2024/HomeWrapper2024.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import React, { FC, useState } from "react";
1+
import React, { FC } from "react";
22
import styled from "styled-components";
33

44
import { useLocation } from "react-router";
55
import { BIG_BREAKPOINT } from "../constants/BreakPoints";
6-
7-
import { useEventEdition } from "../views/Home/UseEventEdition";
6+
import conferenceData from "../data/2024.json";
87
import Faqs from "../views/Home/components/Faqs/Faqs";
98

109
import Home from "./Home/Home";
11-
import SpeakersCarousel from "./SpeakersCarousel/SpeakersCarousel";
1210
import Sponsors from "./Sponsors/Sponsors";
13-
14-
import { Edition } from "../types/types";
1511
import { useDocumentTitleUpdater } from "../services/useDocumentTitleUpdate";
12+
import SpeakersCarousel from "../components/Swiper/SpeakersCarousel";
13+
import { ROUTE_2024_SPEAKERS } from "../constants/routes";
1614

1715
const StyledContainer = styled.div`
1816
padding-bottom: 10rem;
@@ -24,23 +22,24 @@ const StyledContainer = styled.div`
2422

2523
export const HomeWrapper2024: FC<React.PropsWithChildren<unknown>> = () => {
2624
const { hash } = useLocation();
27-
const [edition, setEdition] = useState<Edition>();
2825

29-
useEventEdition(setEdition);
3026
React.useEffect(() => {
3127
if (hash != null && hash !== "") {
3228
const scroll = document.getElementById(hash.substring(1));
3329
scroll?.scrollIntoView();
3430
}
35-
}, [hash, edition]);
31+
}, [hash]);
3632

37-
useDocumentTitleUpdater("Home", edition?.edition ?? "2024");
33+
useDocumentTitleUpdater("Home", conferenceData.edition);
3834

3935
return (
4036
<StyledContainer id="home-wrapper">
4137
<Home />
4238
<Faqs />
43-
<SpeakersCarousel />
39+
<SpeakersCarousel
40+
speakersLink={ROUTE_2024_SPEAKERS}
41+
sessionizeUrl={conferenceData.sessionizeUrl}
42+
/>
4443
<Sponsors />
4544
</StyledContainer>
4645
);

src/2024/SpeakersCarousel/SpeakersCarousel.scss

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/2024/SpeakersCarousel/SpeakersCarousel.tsx

Lines changed: 0 additions & 106 deletions
This file was deleted.
File renamed without changes.

src/2023/Home/components/SpeakersCarousel/SpeakersCarousel.tsx renamed to src/components/Swiper/SpeakersCarousel.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import { Color } from "../../../../styles/colors";
2-
31
import { FC } from "react";
42
import { Link } from "react-router";
5-
import LessThanBlueWhiteIcon from ".././../../../assets/images/MoreThanBlueIcon.svg";
6-
import SectionWrapper from "../../../../components/SectionWrapper/SectionWrapper";
7-
import { TABLET_BREAKPOINT } from "../../../../constants/BreakPoints";
8-
import TitleSection from "../../../../components/SectionTitle/TitleSection";
3+
import LessThanBlueWhiteIcon from "../../assets/images/LessThanBlueIcon.svg";
94
import { motion } from "framer-motion";
105
import styled from "styled-components";
11-
import { ROUTE_2023_SPEAKERS } from "../../../../constants/routes";
126
import SpeakerSwiper from "./SpeakerSwiper";
7+
import { Color } from "../../styles/colors";
8+
import { TABLET_BREAKPOINT } from "../../constants/BreakPoints";
9+
import SectionWrapper from "../SectionWrapper/SectionWrapper";
10+
import TitleSection from "../SectionTitle/TitleSection";
1311

1412
const StyledSpeakersContainer = styled.section`
1513
background-color: ${Color.LIGHT_BLUE};
@@ -58,7 +56,15 @@ const StyledBlueSlash = styled(motion.p)`
5856
height: 100%;
5957
`;
6058

61-
const SpeakersCarousel: FC<React.PropsWithChildren<unknown>> = () => {
59+
interface Props {
60+
speakersLink: string;
61+
sessionizeUrl: string;
62+
}
63+
64+
const SpeakersCarousel: FC<React.PropsWithChildren<Props>> = ({
65+
speakersLink,
66+
sessionizeUrl,
67+
}) => {
6268
return (
6369
<SectionWrapper color={Color.LIGHT_BLUE}>
6470
<StyledSpeakersContainer>
@@ -72,9 +78,9 @@ const SpeakersCarousel: FC<React.PropsWithChildren<unknown>> = () => {
7278
color={Color.WHITE}
7379
/>
7480
</StyledTitleWrapper>
75-
<SpeakerSwiper />
81+
<SpeakerSwiper sessionizeUrl={sessionizeUrl} />
7682
<StyledLink>
77-
<Link to={ROUTE_2023_SPEAKERS} className="link--text">
83+
<Link to={speakersLink} className="link--text">
7884
<StyledSubtitle> View all speakers</StyledSubtitle>
7985
<StyledLessThanRed src={LessThanBlueWhiteIcon} />
8086
</Link>

src/services/shuffleArray.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** Fisher-Yates shuffle algorithm using window.crypto.getRandomValues() */
2+
export const shuffleArray = <T, >(array: T[]): T[] => {
3+
if (!array) {
4+
return [];
5+
}
6+
const shuffledArray = [...array]; // Create a copy to avoid modifying the original array
7+
for (let i = shuffledArray.length - 1; i > 0; i--) {
8+
let j;
9+
const max = (i + 1) * (2 ** 32 / (i + 1));
10+
do {
11+
j = window.crypto.getRandomValues(new Uint32Array(1))[0];
12+
} while (j >= max);
13+
j = j % (i + 1);
14+
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
15+
}
16+
return shuffledArray;
17+
};

src/views/Home/HomeWrapper.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import {BIG_BREAKPOINT} from "../../constants/BreakPoints";
2-
import React, {FC, useState} from "react";
1+
import { BIG_BREAKPOINT } from "../../constants/BreakPoints";
2+
import React, { FC } from "react";
33
import Faqs from "./components/Faqs/Faqs";
44
import Home from "./components/Home/Home";
5-
import SpeakersCarousel from "./components/SpeakersCarousel/SpeakersCarousel";
65
import Sponsors from "./components/Sponsors/Sponsors";
76
import styled from "styled-components";
7+
import conferenceData from "../../data/2025.json";
8+
import { useLocation } from "react-router";
89

9-
import {useLocation} from "react-router";
10-
import {useEventEdition} from "./UseEventEdition";
11-
import {Edition} from "../../types/types";
1210
import { useDocumentTitleUpdater } from "../../services/useDocumentTitleUpdate";
11+
import SpeakersCarousel from "../../components/Swiper/SpeakersCarousel";
12+
import { ROUTE_SPEAKERS } from "../../constants/routes";
13+
import { ErrorBoundary } from "react-error-boundary";
1314

1415
const StyledContainer = styled.div`
1516
padding-bottom: 10rem;
@@ -21,26 +22,31 @@ const StyledContainer = styled.div`
2122

2223
const HomeWrapper: FC<React.PropsWithChildren<unknown>> = () => {
2324
const { hash } = useLocation();
24-
const [edition, setEdition] = useState<Edition>();
2525

26-
useEventEdition(setEdition);
2726
React.useEffect(() => {
2827
if (hash != null && hash !== "") {
2928
const scroll = document.getElementById(hash.substring(1));
3029
scroll?.scrollIntoView();
3130
}
32-
}, [hash, edition]);
31+
}, [hash]);
3332

34-
useDocumentTitleUpdater("Home", edition?.edition ?? "2025");
33+
useDocumentTitleUpdater("Home", conferenceData?.edition ?? "2025");
3534

3635
return (
3736
<StyledContainer id="home-wrapper">
38-
<Home />
37+
<ErrorBoundary fallback={<div>Something went wrong</div>}>
38+
<Home />
39+
</ErrorBoundary>
3940
<Faqs />
40-
{edition?.carrousel.enabled && <SpeakersCarousel/>}
41+
{conferenceData?.carrousel.enabled && (
42+
<SpeakersCarousel
43+
sessionizeUrl={conferenceData.sessionizeUrl}
44+
speakersLink={ROUTE_SPEAKERS}
45+
/>
46+
)}
4147
<Sponsors />
4248
</StyledContainer>
4349
);
4450
};
4551

46-
export default HomeWrapper;
52+
export default HomeWrapper;

src/views/Home/components/SpeakersCarousel/SpeakersCarousel.scss

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)