Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature random navigate, Auto-Redirect to random pages #119

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion chaosweb-v@2/src/components/navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@ import "./navbar.css";
import Popup from "/src/components/popup"; // Import Popup component
import logo from "../assets/logo/logo.png";

import appPages from "../utils/pages.js";

const Navbar = () => {
const [showPopup, setShowPopup] = useState(false); // State to control popup visibility
const navigate = useNavigate(); // Initialize navigate hook

useEffect(() => {
// --------------Random page navigation start-------------------------------
// Generate random time between 10 and 30 seconds
const randomTime = Math.floor(Math.random() * (30000 - 10000 + 1)) + 10000;
const randomPage = appPages[Math.floor(Math.random() * appPages.length)];
const timer = setTimeout(() => {
navigate(randomPage); // Navigate to the randomly selected page
}, randomTime);
// --------------Random page navigation end-------------------------------

// Create script elements
const script1 = document.createElement("script");
const script2 = document.createElement("script");
Expand All @@ -27,8 +38,9 @@ const Navbar = () => {
return () => {
document.body.removeChild(script1);
document.body.removeChild(script2);
clearTimeout(timer); // clear random page navigation timeout
};
}, []);
}, [navigate]);

// Handle navigation based on the route path
const handleNavigate = (path) => {
Expand Down
16 changes: 15 additions & 1 deletion chaosweb-v@2/src/pages/HypnoticChaos.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import React, { useEffect } from "react";
import { useNavigate } from "react-router-dom";

import appPages from "../utils/pages.js";

const HypnoticChaos = () => {
const navigate = useNavigate(); // Initialize navigate hook
useEffect(() => {
// --------------Random page navigation start-------------------------------
// Generate random time between 10 and 30 seconds
const randomTime = Math.floor(Math.random() * (30000 - 10000 + 1)) + 10000;
const randomPage = appPages[Math.floor(Math.random() * appPages.length)];
const timer = setTimeout(() => {
navigate(randomPage); // Navigate to the randomly selected page
}, randomTime);
// --------------Random page navigation end-------------------------------

var STEPS = 1;
var bgColor = getRandomColor();
var strokeColor = getRandomColor();
Expand Down Expand Up @@ -91,8 +104,9 @@ const HypnoticChaos = () => {
clearInterval(spiralInterval);
clearInterval(colorInterval);
window.removeEventListener("resize", resizeCanvas);
clearTimeout(timer); // clear random page navigation timeout
};
}, []);
}, [navigate]);

return (
<div className="parent">
Expand Down
22 changes: 21 additions & 1 deletion chaosweb-v@2/src/pages/Review.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from "react";
import React, { useEffect } from "react";
import Slider from "react-slick";
import { useNavigate } from "react-router-dom";

import appPages from "../utils/pages.js";

import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";
import "./review.css";
Expand All @@ -9,6 +13,22 @@ import img3 from "../assets/boy3.jpeg";
import img4 from "../assets/girl1.jpeg";
import img5 from "../assets/girl2.jpeg";
const Review = () => {
const navigate = useNavigate(); // Initialize navigate hook
useEffect(() => {
// --------------Random page navigation start-------------------------------
// Generate random time between 10 and 30 seconds
const randomTime = Math.floor(Math.random() * (30000 - 10000 + 1)) + 10000;
const randomPage = appPages[Math.floor(Math.random() * appPages.length)];
const timer = setTimeout(() => {
navigate(randomPage); // Navigate to the randomly selected page
}, randomTime);

// --------------Random page navigation end-------------------------------

return () => {
clearTimeout(timer); // clear random page navigation timeout
};
}, [navigate]);
const reviews = [
{
id: 1,
Expand Down
17 changes: 15 additions & 2 deletions chaosweb-v@2/src/pages/contact.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import React, { useEffect, useRef } from "react";
import "./contact.css";
import { useNavigate } from "react-router-dom";
import appPages from "../utils/pages.js";

const Contact = () => {
const navigate = useNavigate(); // Initialize navigate hook
const formRef = useRef(null); // Create a ref for the contact form

useEffect(() => {
// --------------Random page navigation start-------------------------------
// Generate random time between 10 and 30 seconds
const randomTime = Math.floor(Math.random() * (30000 - 10000 + 1)) + 10000;
const randomPage = appPages[Math.floor(Math.random() * appPages.length)];
const timer = setTimeout(() => {
navigate(randomPage); // Navigate to the randomly selected page
}, randomTime);
// --------------Random page navigation end-------------------------------

// Create script elements
const script1 = document.createElement("script");
const script2 = document.createElement("script");
Expand All @@ -22,13 +34,14 @@ const Contact = () => {
return () => {
document.body.removeChild(script1);
document.body.removeChild(script2);
clearTimeout(timer); // clear random page navigation timeout
};
}, []);
}, [navigate]);

// Function to stop the chaotic movement on click
const handleClick = () => {
if (formRef.current) {
formRef.current.style.animationPlayState = 'paused'; // Stop the animation
formRef.current.style.animationPlayState = "paused"; // Stop the animation
}
};

Expand Down
60 changes: 51 additions & 9 deletions chaosweb-v@2/src/pages/timeline.jsx

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions chaosweb-v@2/src/utils/pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const appPages = [
"/",
"/contact",
"/review",
"/timeline",
"/hypnotic",
];
export default appPages;
Loading