From edfe82b65d378fea5d2da47abc36a7d724b7fd5f Mon Sep 17 00:00:00 2001 From: 0xkkonrad Date: Thu, 25 Jan 2024 14:43:27 +0100 Subject: [PATCH] replaced random time intervals with hover on desktop and click on mobile --- src/pages/index.jsx | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/pages/index.jsx b/src/pages/index.jsx index f2f23976..97ec3f46 100644 --- a/src/pages/index.jsx +++ b/src/pages/index.jsx @@ -1,23 +1,39 @@ -import React, { useEffect, useRef, useState } from "react"; +import React, { useState, useEffect } from "react"; import passface from "../assets/passface/passface.gif"; import dod from "../assets/passface/dod.png"; import Layout from "../components/Layout"; import ETHBerlin from "../components/ETHBerlin"; const Home = () => { - // mouseover image passport const [imageSrcPass, setImageSrcPass] = useState(dod); - useEffect(() => { - const MAX_TIME = 2000; // Maximum interval between image changes - const changeImage = () => { - setImageSrcPass((current) => (current === dod ? passface : dod)); - setTimeout(changeImage, Math.random() * MAX_TIME); // Reschedule with a new random interval - }; + // Function to toggle the image + const toggleImage = () => { + setImageSrcPass(current => current === dod ? passface : dod); + }; - const timeoutId = setTimeout(changeImage, Math.random() * MAX_TIME); // Initial scheduling + // Detect if the device is mobile based on the window's width + const isMobile = () => { + return window.innerWidth <= 768; + }; - return () => clearTimeout(timeoutId); // Clear timeout on component unmount + // Effect to add event listeners based on the device type + useEffect(() => { + const imageElement = document.querySelector('.passport-image'); + + if (isMobile()) { + // Mobile: Change image on click + imageElement.addEventListener('click', toggleImage); + } else { + // Desktop: Change image on hover + imageElement.addEventListener('mouseenter', toggleImage); + } + + // Cleanup function to remove event listeners + return () => { + imageElement.removeEventListener('click', toggleImage); + imageElement.removeEventListener('mouseenter', toggleImage); + }; }, []); return ( @@ -29,11 +45,11 @@ const Home = () => {
Fake passport image
-

Event: ETHBerlin4

+

Event: ETHBerlin04

Theme: Identity Crisis

Dates: May 24-26, 2024

@@ -45,11 +61,9 @@ const Home = () => { a platform for hacktivism, and a community initiative to push the decentralized ecosystem forward.

-

Loading : May 24-26, 2024, Berlin, Germany.

-

The situation is dire. We have been operating in crisis mode for years now. Established systems are failing, new and old imperialist @@ -58,20 +72,17 @@ const Home = () => { systems are falling apart, education is on a consistent downward spiral — the list goes on.

-

But there is hope: The soils to grow new ideas have never been more nutritious. It has never been more urgent to double down on new revolutionary concepts and ideas. It is high time to change the world.

-

For this year's ETHBerlin hackathon, we invite you to join the discourse and hack on anti-identity features instead of identity anti-features that boost the individual's privacy.

-

To learn more about our vision & mission, press{" "} <<M<