refactor(ads): remove unnecessary hidden class and add desktop-only rendering for vertical banners to improve responsiveness and clarity

This commit is contained in:
Mathias
2026-04-06 01:44:27 +03:00
parent 118178168f
commit 7cc89d0183
3 changed files with 38 additions and 2 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ export function VerticalAdBanner({ adSlot, ezoicPlacementId, position = "left" }
return ( return (
<AdWrapper> <AdWrapper>
<div className="hidden lg:block w-[160px] h-[600px] sticky top-4"> <div className="w-[160px] h-[600px] sticky top-4">
{isDevelopment ? ( {isDevelopment ? (
<AdPlaceholder height="600px" type={`Vertical Ad (${position})`} width="160px" /> <AdPlaceholder height="600px" type={`Vertical Ad (${position})`} width="160px" />
) : useEzoic ? ( ) : useEzoic ? (
+18
View File
@@ -1,8 +1,22 @@
"use client";
import { useState, useEffect } from "react";
import { VerticalAdBanner } from "./VerticalAdBanner"; import { VerticalAdBanner } from "./VerticalAdBanner";
import { env } from "@/env"; import { env } from "@/env";
export function VerticalLeftBanner() { export function VerticalLeftBanner() {
const [isDesktop, setIsDesktop] = useState(false);
useEffect(() => {
const mq = window.matchMedia("(min-width: 1024px)");
setIsDesktop(mq.matches);
const handler = (e: MediaQueryListEvent) => setIsDesktop(e.matches);
mq.addEventListener("change", handler);
return () => mq.removeEventListener("change", handler);
}, []);
const isCustom = env.NEXT_PUBLIC_AD_PROVIDER === "custom"; const isCustom = env.NEXT_PUBLIC_AD_PROVIDER === "custom";
const hasAdSlot = env.NEXT_PUBLIC_VERTICAL_LEFT_BANNER_AD_SLOT; const hasAdSlot = env.NEXT_PUBLIC_VERTICAL_LEFT_BANNER_AD_SLOT;
const hasEzoicPlacement = env.NEXT_PUBLIC_EZOIC_VERTICAL_LEFT_PLACEMENT_ID; const hasEzoicPlacement = env.NEXT_PUBLIC_EZOIC_VERTICAL_LEFT_PLACEMENT_ID;
@@ -11,6 +25,10 @@ export function VerticalLeftBanner() {
return null; return null;
} }
if (!isDesktop) {
return null;
}
return ( return (
<VerticalAdBanner <VerticalAdBanner
adSlot={env.NEXT_PUBLIC_VERTICAL_LEFT_BANNER_AD_SLOT || ""} adSlot={env.NEXT_PUBLIC_VERTICAL_LEFT_BANNER_AD_SLOT || ""}
+19 -1
View File
@@ -1,8 +1,22 @@
import { env } from "@/env"; "use client";
import { useState, useEffect } from "react";
import { VerticalAdBanner } from "./VerticalAdBanner"; import { VerticalAdBanner } from "./VerticalAdBanner";
import { env } from "@/env";
export function VerticalRightBanner() { export function VerticalRightBanner() {
const [isDesktop, setIsDesktop] = useState(false);
useEffect(() => {
const mq = window.matchMedia("(min-width: 1024px)");
setIsDesktop(mq.matches);
const handler = (e: MediaQueryListEvent) => setIsDesktop(e.matches);
mq.addEventListener("change", handler);
return () => mq.removeEventListener("change", handler);
}, []);
const isCustom = env.NEXT_PUBLIC_AD_PROVIDER === "custom"; const isCustom = env.NEXT_PUBLIC_AD_PROVIDER === "custom";
const hasAdSlot = env.NEXT_PUBLIC_VERTICAL_RIGHT_BANNER_AD_SLOT; const hasAdSlot = env.NEXT_PUBLIC_VERTICAL_RIGHT_BANNER_AD_SLOT;
const hasEzoicPlacement = env.NEXT_PUBLIC_EZOIC_VERTICAL_RIGHT_PLACEMENT_ID; const hasEzoicPlacement = env.NEXT_PUBLIC_EZOIC_VERTICAL_RIGHT_PLACEMENT_ID;
@@ -11,6 +25,10 @@ export function VerticalRightBanner() {
return null; return null;
} }
if (!isDesktop) {
return null;
}
return ( return (
<VerticalAdBanner <VerticalAdBanner
adSlot={env.NEXT_PUBLIC_VERTICAL_RIGHT_BANNER_AD_SLOT || ""} adSlot={env.NEXT_PUBLIC_VERTICAL_RIGHT_BANNER_AD_SLOT || ""}