Skip to content

Commit eb7eddb

Browse files
committed
refactor: remove duplication
1 parent 178e8ac commit eb7eddb

File tree

11 files changed

+383
-407
lines changed

11 files changed

+383
-407
lines changed

src/2023/Home/components/SpeakersCarousel/SpeakerSwiper.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import "swiper/swiper-bundle.min.css";
77
import "./SpeakersCarousel.scss";
88
import { Link } from "react-router";
99
import { ROUTE_SPEAKER_DETAIL } from "../../../../constants/routes";
10-
import { useFetchSpeakers } from "../../../Speakers/UseFetchSpeakers";
1110
import * as Sentry from "@sentry/react";
1211

12+
import conferenceData from "../../../../data/2023.json";
13+
import { useFetchSpeakers } from "../../../../views/Speakers/UseFetchSpeakers";
14+
1315
const StyledSlideImage = styled.img`
1416
display: block;
1517
width: 100%;
@@ -35,7 +37,9 @@ const StyledSlideText = styled.p`
3537
color: white;
3638
`;
3739
const SpeakerSwiper: FC<React.PropsWithChildren<unknown>> = () => {
38-
const { isLoading, data, error } = useFetchSpeakers();
40+
const { isLoading, data, error } = useFetchSpeakers(
41+
conferenceData.sessionizeUrl,
42+
);
3943

4044
const swiperSpeakers = data?.sort(() => 0.5 - Math.random()).slice(0, 20);
4145

src/2023/SpeakerDetail/SpeakerDetailContainer2023.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import SpeakerDetail2023 from "./SpeakerDetail2023";
66
import { useParams } from "react-router";
77
import { StyledContainer, StyledWaveContainer } from "./Speaker.style";
88
import conferenceData from "../../data/2023.json";
9-
import { useFetchSpeakers } from "../Speakers/UseFetchSpeakers";
109
import * as Sentry from "@sentry/react";
10+
import { useFetchSpeakers } from "../../views/Speakers/UseFetchSpeakers";
1111

1212
const SpeakerDetailContainer2023: FC<React.PropsWithChildren<unknown>> = () => {
1313
const { id } = useParams<{ id: string }>();
1414

15-
const { isLoading, error, data } = useFetchSpeakers(id);
15+
const { isLoading, error, data } = useFetchSpeakers(
16+
conferenceData.sessionizeUrl,
17+
id,
18+
);
1619

1720
if (error) {
1821
Sentry.captureException(error);

src/2023/Speakers/Speakers2023.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import {MOBILE_BREAKPOINT} from "../../constants/BreakPoints";
2-
import {Color} from "../../styles/colors";
3-
import {FC, useCallback, useEffect} from "react";
1+
import { MOBILE_BREAKPOINT } from "../../constants/BreakPoints";
2+
import { Color } from "../../styles/colors";
3+
import { FC, useCallback, useEffect } from "react";
44
import LessThanBlueIcon from "../../assets/images/LessThanBlueIcon.svg";
55
import MoreThanBlueIcon from "../../assets/images/MoreThanBlueIcon.svg";
66
import SectionWrapper from "../../components/SectionWrapper/SectionWrapper";
7-
import {SpeakerCard} from "./components/SpeakersCard";
7+
import { SpeakerCard } from "./components/SpeakersCard";
88
import TitleSection from "../../components/SectionTitle/TitleSection";
9-
import {useWindowSize} from "react-use";
9+
import { useWindowSize } from "react-use";
1010
import {
1111
SpeakersCardsContainer,
1212
StyledContainerLeftSlash,
@@ -19,10 +19,10 @@ import {
1919
} from "./Speakers.style";
2020
import webData from "../../data/2023.json";
2121
import Button from "../../components/UI/Button";
22-
import {gaEventTracker} from "../../components/analytics/Analytics";
23-
import {useFetchSpeakers} from "./UseFetchSpeakers";
22+
import { gaEventTracker } from "../../components/analytics/Analytics";
2423
import * as Sentry from "@sentry/react";
25-
import {ISpeaker} from "../../types/speakers";
24+
import { ISpeaker } from "../../types/speakers";
25+
import { useFetchSpeakers } from "../../views/Speakers/UseFetchSpeakers";
2626

2727
const LessThanGreaterThan = (props: { width: number }) => (
2828
<>
@@ -41,7 +41,9 @@ const Speakers2023: FC<React.PropsWithChildren<unknown>> = () => {
4141
const isBetween = (startDay: Date, endDay: Date): boolean =>
4242
startDay < new Date() && endDay > today;
4343

44-
const { error, data, isLoading } = useFetchSpeakers();
44+
const { error, data, isLoading } = useFetchSpeakers(
45+
`${webData.sessionizeUrl}/view/Speakers`,
46+
);
4547

4648
if (error) {
4749
Sentry.captureException(error);
@@ -105,7 +107,8 @@ const Speakers2023: FC<React.PropsWithChildren<unknown>> = () => {
105107
>
106108
<StyledSlash color={Color.YELLOW}>
107109
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
108-
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /{" "}
110+
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
111+
/{" "}
109112
</StyledSlash>
110113
</StyledContainerRightSlash>
111114

@@ -117,7 +120,8 @@ const Speakers2023: FC<React.PropsWithChildren<unknown>> = () => {
117120
>
118121
<StyledSlash color={Color.DARK_BLUE}>
119122
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
120-
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /{" "}
123+
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
124+
/{" "}
121125
</StyledSlash>
122126
</StyledContainerLeftSlash>
123127

@@ -129,7 +133,8 @@ const Speakers2023: FC<React.PropsWithChildren<unknown>> = () => {
129133
>
130134
<StyledSlash color={Color.BLUE}>
131135
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
132-
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /{" "}
136+
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
137+
/{" "}
133138
</StyledSlash>
134139
</StyledContainerRightSlash>
135140

@@ -141,7 +146,8 @@ const Speakers2023: FC<React.PropsWithChildren<unknown>> = () => {
141146
>
142147
<StyledSlash color={Color.YELLOW}>
143148
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
144-
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /{" "}
149+
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
150+
/{" "}
145151
</StyledSlash>
146152
</StyledContainerLeftSlash>
147153
</StyledSpeakersSection>

src/2023/Speakers/UseFetchSpeakers.ts

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

src/2023/TalkDetail/TalkDetailContainer2023.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import {Color} from "../../styles/colors";
2-
import React, {FC, useEffect} from "react";
1+
import { Color } from "../../styles/colors";
2+
import React, { FC, useEffect } from "react";
33
import NotFoundError from "../../components/NotFoundError/NotFoundError";
44
import SectionWrapper from "../../components/SectionWrapper/SectionWrapper";
55
import styled from "styled-components";
6-
import {useParams} from "react-router";
6+
import { useParams } from "react-router";
77
import conferenceData from "../../data/2023.json";
8-
import {useFetchTalksById} from "../Talks/UseFetchTalks";
8+
import { useFetchTalksById } from "../Talks/UseFetchTalks";
99
import * as Sentry from "@sentry/react";
10-
import {useFetchSpeakers} from "../Speakers/UseFetchSpeakers";
11-
import {Session} from "../../types/sessions";
10+
import { Session } from "../../types/sessions";
1211
import TalkDetail from "./TalkDetail";
13-
import {ISpeaker} from "../../types/speakers";
14-
import {sessionAdapter} from "../../services/sessionsAdapter";
12+
import { ISpeaker } from "../../types/speakers";
13+
import { sessionAdapter } from "../../services/sessionsAdapter";
14+
import { useFetchSpeakers } from "../../views/Speakers/UseFetchSpeakers";
1515

1616
const StyledContainer = styled.div`
1717
background-color: ${Color.WHITE};
1818
`;
1919
const TalkDetailContainer2023: FC<React.PropsWithChildren<unknown>> = () => {
2020
const { id } = useParams<{ id: string }>();
2121
const { isLoading, error, data } = useFetchTalksById(id!);
22-
const { data: speakerData } = useFetchSpeakers();
22+
const { data: speakerData } = useFetchSpeakers(conferenceData.sessionizeUrl);
2323

2424
const getTalkSpeakers = (
2525
data: Session[] | undefined,
Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,55 @@
1-
import {Color} from "../../styles/colors";
1+
import { Color } from "../../styles/colors";
22

3-
import React, {FC} from "react";
3+
import React, { FC } from "react";
44
import SectionWrapper from "../../components/SectionWrapper/SectionWrapper";
55
import SpeakerDetail from "./SpeakerDetail";
6-
import {useParams} from "react-router";
6+
import { useParams } from "react-router";
77
import conferenceData from "../../data/2024.json";
8-
import {useFetchSpeakers} from "../Speakers/UseFetchSpeakers";
98
import * as Sentry from "@sentry/react";
10-
import {StyledContainer} from "../../views/SpeakerDetail/Speaker.style";
11-
import {StyledWaveContainer} from "../../views/Talks/Talks.style";
9+
import { StyledContainer } from "../../views/SpeakerDetail/Speaker.style";
10+
import { StyledWaveContainer } from "../../views/Talks/Talks.style";
11+
import { useFetchSpeakers } from "../../views/Speakers/UseFetchSpeakers";
1212

1313
const SpeakerDetailContainer2024: FC<React.PropsWithChildren<unknown>> = () => {
14-
const {id} = useParams<{ id: string }>();
14+
const { id } = useParams<{ id: string }>();
1515

16-
const {isLoading, error, data} = useFetchSpeakers(id);
16+
const { isLoading, error, data } = useFetchSpeakers(
17+
conferenceData.sessionizeUrl,
18+
id,
19+
);
1720

18-
if (error) {
19-
Sentry.captureException(error);
21+
if (error) {
22+
Sentry.captureException(error);
23+
}
24+
React.useEffect(() => {
25+
if (data) {
26+
document.title = `${data[0]?.fullName} - DevBcn - ${conferenceData.edition}`;
2027
}
21-
React.useEffect(() => {
22-
if (data) {
23-
document.title = `${data[0]?.fullName} - DevBcn - ${conferenceData.edition}`;
24-
}
25-
}, [id, data]);
26-
return (
27-
<StyledContainer>
28-
<SectionWrapper color={Color.BLUE} marginTop={4}>
29-
{isLoading && <h2>Loading</h2>}
30-
{!isLoading && data && data.length > 0 ? (
31-
<SpeakerDetail speaker={data[0]}/>
32-
) : (
33-
"not found"
34-
)}
35-
</SectionWrapper>
36-
<StyledWaveContainer>
37-
<svg
38-
viewBox="0 0 500 150"
39-
preserveAspectRatio="none"
40-
style={{height: "100%", width: "100%"}}
41-
>
42-
<path
43-
d="M-8.17,75.50 C207.95,-129.75 329.85,202.80 500.27,5.45 L501.41,-5.41 L0.00,0.00 Z"
44-
style={{stroke: "none", fill: "#0496ff"}}
45-
></path>
46-
</svg>
47-
</StyledWaveContainer>
48-
</StyledContainer>
49-
);
28+
}, [id, data]);
29+
return (
30+
<StyledContainer>
31+
<SectionWrapper color={Color.BLUE} marginTop={4}>
32+
{isLoading && <h2>Loading</h2>}
33+
{!isLoading && data && data.length > 0 ? (
34+
<SpeakerDetail speaker={data[0]} />
35+
) : (
36+
"not found"
37+
)}
38+
</SectionWrapper>
39+
<StyledWaveContainer>
40+
<svg
41+
viewBox="0 0 500 150"
42+
preserveAspectRatio="none"
43+
style={{ height: "100%", width: "100%" }}
44+
>
45+
<path
46+
d="M-8.17,75.50 C207.95,-129.75 329.85,202.80 500.27,5.45 L501.41,-5.41 L0.00,0.00 Z"
47+
style={{ stroke: "none", fill: "#0496ff" }}
48+
></path>
49+
</svg>
50+
</StyledWaveContainer>
51+
</StyledContainer>
52+
);
5053
};
5154

5255
export default SpeakerDetailContainer2024;

0 commit comments

Comments
 (0)