|
| 1 | +import React, { useEffect, useState } from 'react'; |
| 2 | +import BrowserOnly from '@docusaurus/BrowserOnly'; |
| 3 | +import clsx from 'clsx'; |
| 4 | +import styles from './styles.module.css'; |
| 5 | + |
| 6 | +const AD_REFRESH_RATE = 20 * 1000; |
| 7 | + |
| 8 | +// ====== ✅ Ad Variants ====== |
| 9 | +function CodeHarborHubIntro({ position }) { |
| 10 | + return ( |
| 11 | + <a |
| 12 | + className={clsx(styles.container, styles.backgroundIntro)} |
| 13 | + href="https://codeharborhub.github.io/tutorial/" |
| 14 | + target="_blank" |
| 15 | + rel="noopener" |
| 16 | + onClick={() => window.gtag?.('event', `codeharborhub.intro.${position}.click`)}> |
| 17 | + <p className={styles.tagline}> |
| 18 | + <strong className={styles.title}>🚀 Learn. Build. Grow.</strong> |
| 19 | + Join <u>CodeHarborHub</u> to explore free tech roadmaps, advanced tutorials, |
| 20 | + and career-ready projects. <u>Start your journey today!</u> |
| 21 | + </p> |
| 22 | + </a> |
| 23 | + ); |
| 24 | +} |
| 25 | + |
| 26 | +function CodeHarborHubCourses({ position }) { |
| 27 | + return ( |
| 28 | + <a |
| 29 | + className={clsx(styles.container, styles.backgroundCourses)} |
| 30 | + href="https://codeharborhub.github.io/courses/" |
| 31 | + target="_blank" |
| 32 | + rel="noopener" |
| 33 | + onClick={() => window.gtag?.('event', `codeharborhub.courses.${position}.click`)}> |
| 34 | + <p className={styles.tagline}> |
| 35 | + <strong className={styles.title}>🎯 Master Web Development</strong> |
| 36 | + Beginner to advanced courses in <u>HTML, CSS, JS, React & AI</u> with hands-on |
| 37 | + projects. <u>Learn at your own pace!</u> |
| 38 | + </p> |
| 39 | + </a> |
| 40 | + ); |
| 41 | +} |
| 42 | + |
| 43 | +function CodeHarborHubCommunity({ position }) { |
| 44 | + return ( |
| 45 | + <a |
| 46 | + className={clsx(styles.container, styles.backgroundCommunity)} |
| 47 | + href="https://discord.gg/rGCZYcaHk7" |
| 48 | + target="_blank" |
| 49 | + rel="noopener" |
| 50 | + onClick={() => window.gtag?.('event', `codeharborhub.community.${position}.click`)}> |
| 51 | + <p className={styles.tagline}> |
| 52 | + <strong className={styles.title}>🤝 Join Our Community</strong> |
| 53 | + Connect with developers, get help on projects, and collaborate on open-source. |
| 54 | + <u>Join our Discord now!</u> |
| 55 | + </p> |
| 56 | + </a> |
| 57 | + ); |
| 58 | +} |
| 59 | + |
| 60 | +// ====== ✅ Main Rotating Ad Component ====== |
| 61 | +export default React.memo(function SidebarAd({ position }) { |
| 62 | + const [counter, setCounter] = useState(0); |
| 63 | + |
| 64 | + useEffect(() => { |
| 65 | + const timer = setTimeout(() => setCounter((c) => c + 1), AD_REFRESH_RATE); |
| 66 | + return () => clearTimeout(timer); |
| 67 | + }, [counter]); |
| 68 | + |
| 69 | + return ( |
| 70 | + <BrowserOnly key={counter}> |
| 71 | + {() => { |
| 72 | + const rand = Math.random(); |
| 73 | + const path = window.location.pathname; |
| 74 | + |
| 75 | + // Dynamic placement based on page |
| 76 | + if (path.includes('roadmap')) { |
| 77 | + return rand < 0.5 |
| 78 | + ? <CodeHarborHubCourses key={Math.random()} position={position} /> |
| 79 | + : <CodeHarborHubIntro key={Math.random()} position={position} />; |
| 80 | + } |
| 81 | + |
| 82 | + if (path.includes('community')) { |
| 83 | + return <CodeHarborHubCommunity key={Math.random()} position={position} />; |
| 84 | + } |
| 85 | + |
| 86 | + // Default Rotation |
| 87 | + if (rand < 0.33) return <CodeHarborHubIntro key={Math.random()} position={position} />; |
| 88 | + if (rand < 0.66) return <CodeHarborHubCourses key={Math.random()} position={position} />; |
| 89 | + return <CodeHarborHubCommunity key={Math.random()} position={position} />; |
| 90 | + }} |
| 91 | + </BrowserOnly> |
| 92 | + ); |
| 93 | +}); |
0 commit comments