Skip to content

Commit cb741c5

Browse files
committed
Feat : first ad component added
1 parent 26e6cb3 commit cb741c5

File tree

2 files changed

+128
-21
lines changed

2 files changed

+128
-21
lines changed

app/components/ads/bottom.jsx

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"use client";
2+
import React, { useEffect, useState } from "react";
3+
import { FaChevronUp, FaChevronDown } from "react-icons/fa";
4+
5+
const BottomAd = () => {
6+
const [isClient, setIsClient] = useState(false);
7+
const [minimized, setMinimized] = useState(false);
8+
9+
useEffect(() => {
10+
setIsClient(true);
11+
12+
if (typeof window !== "undefined") {
13+
// Load AdSense script once
14+
const scriptId = "adsbygoogle-js";
15+
if (!document.getElementById(scriptId)) {
16+
const script = document.createElement("script");
17+
script.id = scriptId;
18+
script.async = true;
19+
script.src =
20+
"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4311738896428559";
21+
script.crossOrigin = "anonymous";
22+
document.head.appendChild(script);
23+
}
24+
}
25+
}, []);
26+
27+
useEffect(() => {
28+
if (isClient) {
29+
try {
30+
(window.adsbygoogle = window.adsbygoogle || []).push({});
31+
} catch (e) {
32+
console.warn("AdSense error:", e);
33+
}
34+
}
35+
}, [isClient]);
36+
37+
if (!isClient) return null;
38+
39+
// Detect environment for test ads
40+
const isDev =
41+
window.location.hostname === "localhost" ||
42+
window.location.hostname === "127.0.0.1";
43+
44+
return (
45+
<div
46+
style={{
47+
position: "fixed",
48+
bottom: 0,
49+
left: 0,
50+
width: "100%",
51+
background: "#fff",
52+
boxShadow: "0 -2px 8px rgba(0,0,0,0.1)",
53+
zIndex: 9999,
54+
transition: "height 0.3s ease",
55+
height: minimized ? "36px" : "120px",
56+
overflow: "hidden",
57+
textAlign: "center",
58+
padding: minimized ? "0" : "4px 0",
59+
}}
60+
>
61+
<button
62+
onClick={() => setMinimized(!minimized)}
63+
style={{
64+
position: "absolute",
65+
right: "8px",
66+
top: "4px",
67+
background: "transparent",
68+
border: "none",
69+
fontSize: "16px",
70+
cursor: "pointer",
71+
color: "#444",
72+
display: "flex",
73+
alignItems: "center",
74+
justifyContent: "center",
75+
}}
76+
aria-label={minimized ? "Expand Ad" : "Minimize Ad"}
77+
>
78+
{minimized ? <FaChevronUp /> : <FaChevronDown />}
79+
</button>
80+
81+
{minimized ? (
82+
<div style={{ fontSize: "13px", padding: "6px", color: "#555" }}>
83+
Ad minimized — click ▲ to reopen
84+
</div>
85+
) : (
86+
<ins
87+
className="adsbygoogle"
88+
style={{ display: "block", height: "100px" }}
89+
data-ad-client={
90+
isDev ? "ca-pub-3940256099942544" : "ca-pub-4311738896428559"
91+
}
92+
data-ad-slot={isDev ? "6300978111" : "2048540881"}
93+
data-ad-format="auto"
94+
data-full-width-responsive="true"
95+
></ins>
96+
)}
97+
</div>
98+
);
99+
};
100+
101+
export default BottomAd;

app/page.jsx

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Review from "@/app/components/review";
66
import Testimonial from "@/app/components/testimonial";
77
import Faq from "@/app/components/faq";
88
import Footer from "@/app/components/footer";
9+
import BottomAd from "./components/ads/bottom";
910

1011
export const metadata = {
1112
title: 'DSA Visualizer | Visualize & Learn DSA the Smart Way',
@@ -42,27 +43,32 @@ export const metadata = {
4243

4344
export default function Home() {
4445
return (
45-
<div className="min-h-screen bg-gray-100">
46-
<Navbar />
47-
<div id="hero">
48-
<Hero />
46+
<>
47+
<div className="min-h-screen bg-gray-100">
48+
<Navbar />
49+
<div id="hero">
50+
<Hero />
51+
</div>
52+
<div id="testimonial">
53+
<Testimonial/>
54+
</div>
55+
<div id="features">
56+
<Feature />
57+
</div>
58+
<div id="about">
59+
<About />
60+
</div>
61+
<div id="faq">
62+
<Faq />
63+
</div>
64+
<div id="review">
65+
<Review/>
66+
</div>
67+
<Footer />
4968
</div>
50-
<div id="testimonial">
51-
<Testimonial/>
52-
</div>
53-
<div id="features">
54-
<Feature />
55-
</div>
56-
<div id="about">
57-
<About />
58-
</div>
59-
<div id="faq">
60-
<Faq />
61-
</div>
62-
<div id="review">
63-
<Review/>
64-
</div>
65-
<Footer />
66-
</div>
69+
70+
{/* Floating Ad — always visible at bottom */}
71+
<BottomAd />
72+
</>
6773
);
6874
}

0 commit comments

Comments
 (0)