From f9377404aee9ed07620ca1336ae5d1ebd0e56bf9 Mon Sep 17 00:00:00 2001 From: Arkapravo-Ghosh Date: Sat, 6 Jan 2024 16:46:25 +0530 Subject: [PATCH] feat: added window width event listeners --- src/components/mentors/Mentors.jsx | 18 ++++++++++++++++-- src/components/prizes/Prizes.jsx | 18 ++++++++++++++++-- src/components/sponsors/Sponsors.jsx | 18 ++++++++++++++++-- src/components/themes/Theme.jsx | 18 ++++++++++++++++-- src/components/timeline/Timeline.jsx | 20 +++++++++++++++++--- 5 files changed, 81 insertions(+), 11 deletions(-) diff --git a/src/components/mentors/Mentors.jsx b/src/components/mentors/Mentors.jsx index ff77071..cfb0518 100644 --- a/src/components/mentors/Mentors.jsx +++ b/src/components/mentors/Mentors.jsx @@ -1,15 +1,29 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; import Marquee from "react-fast-marquee"; import { FaLinkedinIn, FaXTwitter } from "react-icons/fa6"; import { mentorContent } from "../../assets/data/MentorsContent"; import "./Mentors.scss"; function Mentors({ refs }) { + const [windowWidth, setWindowWidth] = useState(window.innerWidth); + + useEffect(() => { + const handleResize = () => { + setWindowWidth(window.innerWidth); + }; + + window.addEventListener("resize", handleResize); + + return () => { + window.removeEventListener("resize", handleResize); + }; + }, []); + return (

Experts

-

{window.innerWidth > 700 ? "Previous" : "Past"} Mentors

+

{windowWidth > 700 ? "Previous" : "Past"} Mentors

diff --git a/src/components/prizes/Prizes.jsx b/src/components/prizes/Prizes.jsx index 06c5a25..fae9be6 100644 --- a/src/components/prizes/Prizes.jsx +++ b/src/components/prizes/Prizes.jsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; // import white from "../../assets/images/LandingImages/blob_right.png"; // import FirstPrize from "../../assets/images/PrizesImages/FirstPrize.png"; @@ -11,12 +11,26 @@ import ComingSoon from "../comingsoon/ComingSoon"; import "./Prizes.scss"; const Prizes = ({ refs }) => { + const [windowWidth, setWindowWidth] = useState(window.innerWidth); + + useEffect(() => { + const handleResize = () => { + setWindowWidth(window.innerWidth); + }; + + window.addEventListener("resize", handleResize); + + return () => { + window.removeEventListener("resize", handleResize); + }; + }, []); + return ( <>

Awards

-

{window.innerWidth > 700 && "Hackathon"} Prizes

+

{windowWidth > 700 && "Hackathon"} Prizes

{/* */} {/* */} diff --git a/src/components/sponsors/Sponsors.jsx b/src/components/sponsors/Sponsors.jsx index 4e6fcc9..ba79f7e 100644 --- a/src/components/sponsors/Sponsors.jsx +++ b/src/components/sponsors/Sponsors.jsx @@ -1,14 +1,28 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; import sponsors from "../../assets/data/SponsorsContent"; import SingleSponsors from "../singlesponsors/SingleSponsors"; import "./Sponsors.scss"; const Sponsors = ({ refs }) => { + const [windowWidth, setWindowWidth] = useState(window.innerWidth); + + useEffect(() => { + const handleResize = () => { + setWindowWidth(window.innerWidth); + }; + + window.addEventListener("resize", handleResize); + + return () => { + window.removeEventListener("resize", handleResize); + }; + }, []); + return ( <>
-

{window.innerWidth > 700 ? "Supporters" : "Backers"}

+

{windowWidth > 700 ? "Supporters" : "Backers"}

Past Sponsors

diff --git a/src/components/themes/Theme.jsx b/src/components/themes/Theme.jsx index 82a3e83..eede4c6 100644 --- a/src/components/themes/Theme.jsx +++ b/src/components/themes/Theme.jsx @@ -1,14 +1,28 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; import ComingSoon from "../comingsoon/ComingSoon"; import "./Theme.scss"; const Theme = ({ refs }) => { + const [windowWidth, setWindowWidth] = useState(window.innerWidth); + + useEffect(() => { + const handleResize = () => { + setWindowWidth(window.innerWidth); + }; + + window.addEventListener("resize", handleResize); + + return () => { + window.removeEventListener("resize", handleResize); + }; + }, []); + return ( <>

Tracks

-

{window.innerWidth > 700 && "Hackathon"} Themes

+

{windowWidth > 700 && "Hackathon"} Themes

diff --git a/src/components/timeline/Timeline.jsx b/src/components/timeline/Timeline.jsx index 4e67a35..5bce118 100644 --- a/src/components/timeline/Timeline.jsx +++ b/src/components/timeline/Timeline.jsx @@ -1,14 +1,28 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; import ComingSoon from "../comingsoon/ComingSoon"; import "./Timeline.scss"; const Timeline = ({ refs }) => { + const [windowWidth, setWindowWidth] = useState(window.innerWidth); + + useEffect(() => { + const handleResize = () => { + setWindowWidth(window.innerWidth); + }; + + window.addEventListener("resize", handleResize); + + return () => { + window.removeEventListener("resize", handleResize); + }; + }, []); + return ( <>
-

{window.innerWidth > 700 ? "Roadmap" : "Plan"}

-

{window.innerWidth > 700 && "Hackathon"} Timeline

+

{windowWidth > 700 ? "Roadmap" : "Plan"}

+

{windowWidth > 700 && "Hackathon"} Timeline