Skip to content

Commit ce66b76

Browse files
committed
feat(VideoSection): include support for mobile
1 parent 12c8514 commit ce66b76

1 file changed

Lines changed: 52 additions & 33 deletions

File tree

src/Components/sections/VideoSection.tsx

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
import toast, { Toaster } from "react-hot-toast";
1313

1414
import { ViewportSizes } from "../../../styles/theme";
15+
import useMediaQuery from "../../helpers/useMediaQuery";
16+
1517
import { H2 } from "../core/Typography";
1618

1719
const GetAccount = dynamic(async () => await import("../GetAccount"), {
@@ -50,9 +52,13 @@ const PlayerContainer = styled.div`
5052

5153
const IframeContainer = styled.div`
5254
position: relative;
53-
padding-bottom: 56.25%;
55+
padding-bottom: 100%;
5456
margin: 1rem 0;
5557
58+
@media (min-width: ${ViewportSizes.TabletLandscape}) {
59+
padding-bottom: 56.25%;
60+
}
61+
5662
iframe {
5763
position: absolute;
5864
width: 100%;
@@ -97,15 +103,21 @@ const Button = styled.button`
97103
}
98104
`;
99105

106+
const desktopChatConfigurations = ["0 0 50%", "0 0 33%", "0 0 25%", "0 0 0%"];
107+
const mobileChatConfigurations = ["0 0 100%", "0 0 0%"];
108+
100109
const VideoSection = ({
101110
videoId,
102111
includesChat = true,
103112
}: {
104113
videoId: string;
105114
includesChat?: boolean;
106115
}) => {
107-
const chatConfigurations = ["0 0 50%", "0 0 33%", "0 0 25%", "0 0 0%"];
108-
const [chatSize, setChatSize] = useState(3);
116+
const isMobile = useMediaQuery(`(max-width: ${ViewportSizes.Phone - 1}px)`);
117+
const chatConfigurations = isMobile
118+
? mobileChatConfigurations
119+
: desktopChatConfigurations;
120+
const [chatSize, setChatSize] = useState(chatConfigurations.length - 1);
109121
const [origin, setOrigin] = useState("");
110122
const [port, setPort] = useState("");
111123

@@ -116,30 +128,33 @@ const VideoSection = ({
116128
}
117129
}, [setOrigin]);
118130

119-
const chatConfiguration = chatConfigurations[chatSize];
120-
121-
if (!videoId) {
122-
return <></>;
123-
}
124-
131+
const flex =
132+
chatSize > chatConfigurations.length - 1
133+
? chatConfigurations[chatConfigurations.length - 1]
134+
: chatConfigurations[chatSize];
135+
const paddingBottom = isMobile ? "100%" : "56.25%";
125136
const httpScheme = origin.startsWith("https") ? "https" : "http";
126137
const embedDomain = origin.includes("localhost")
127138
? origin.replace("http://", "").replace(`:${port}`, "")
128139
: origin.replace("https://", "");
129140

141+
if (!videoId) {
142+
return <></>;
143+
}
144+
130145
return (
131146
<Container>
132147
<H2 whileHover={{ scale: 1.01 }}>Ver la Previa</H2>
133148
<HR />
134149
<PlayerContainer>
135-
<VideoContainer>
150+
<VideoContainer style={{ paddingBottom }}>
136151
<iframe
137152
src={`${httpScheme}://www.youtube-nocookie.com/embed/${videoId}?theme=dark&autoplay=1&keyboard=1&autohide=2&cc_load_policy=1&modestbranding=1&fs=1&rel=0&iv_load_policy=3&mute=0&loop=0&share=0`}
138153
allowFullScreen
139154
/>
140155
</VideoContainer>
141156
{includesChat ? (
142-
<ChatContainer style={{ flex: chatConfiguration }}>
157+
<ChatContainer style={{ paddingBottom, flex }}>
143158
<iframe
144159
src={`${httpScheme}://www.youtube.com/live_chat?v=${videoId}&embed_domain=${embedDomain}`}
145160
allowFullScreen
@@ -151,17 +166,19 @@ const VideoSection = ({
151166
<div style={{ textAlign: "right", paddingRight: "24px" }}>
152167
{includesChat ? (
153168
<>
154-
<Button
155-
disabled={chatSize === 0}
156-
onClick={() => {
157-
setChatSize(0);
158-
}}
159-
>
160-
<ChevronsLeft
161-
size={24}
162-
style={{ position: "relative", top: "4px" }}
163-
/>
164-
</Button>
169+
{!isMobile ? (
170+
<Button
171+
disabled={chatSize === 0}
172+
onClick={() => {
173+
setChatSize(0);
174+
}}
175+
>
176+
<ChevronsLeft
177+
size={24}
178+
style={{ position: "relative", top: "4px" }}
179+
/>
180+
</Button>
181+
) : null}
165182
<Button
166183
disabled={chatSize === 0}
167184
onClick={() => {
@@ -190,17 +207,19 @@ const VideoSection = ({
190207
style={{ position: "relative", top: "4px" }}
191208
/>
192209
</Button>
193-
<Button
194-
disabled={chatSize === chatConfigurations.length - 1}
195-
onClick={() => {
196-
setChatSize(chatConfigurations.length - 1);
197-
}}
198-
>
199-
<ChevronsRight
200-
size={24}
201-
style={{ position: "relative", top: "4px" }}
202-
/>
203-
</Button>
210+
{!isMobile ? (
211+
<Button
212+
disabled={chatSize >= chatConfigurations.length - 1}
213+
onClick={() => {
214+
setChatSize(chatConfigurations.length - 1);
215+
}}
216+
>
217+
<ChevronsRight
218+
size={24}
219+
style={{ position: "relative", top: "4px" }}
220+
/>
221+
</Button>
222+
) : null}
204223
</>
205224
) : null}
206225
<Button>

0 commit comments

Comments
 (0)