diff --git a/.vscode/settings.json b/.vscode/settings.json index 08b0782..4387795 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -27,6 +27,7 @@ "typescript.preferences.importModuleSpecifier": "relative", "prettier.configPath": ".prettierrc.js", "cSpell.words": [ + "adfit", "clsx", "formatjs", "hyochan", diff --git a/app/[lang]/(common)/AdFit.tsx b/app/[lang]/(common)/AdFit.tsx index 857c457..cb6c52b 100644 --- a/app/[lang]/(common)/AdFit.tsx +++ b/app/[lang]/(common)/AdFit.tsx @@ -1,45 +1,49 @@ -import React, { CSSProperties } from "react"; -import { useEffect } from "react"; +import React, {CSSProperties} from 'react'; +import {useEffect} from 'react'; +import {useMediaQuery} from 'usehooks-ts'; export default function AdFit({ - className = "adfit", + className, style, unit, height, width, }: { - className?: string; + className: string; style?: CSSProperties; unit: string; width: number; height: number; }): JSX.Element { + const isMobile = useMediaQuery('(max-width: 768px)'); + const convertedClassName = isMobile ? `${className}-mobile` : className; + useEffect(() => { const timeout = setTimeout(() => { - let ins = document.createElement("ins"); - let scr = document.createElement("script"); - ins.className = "kakao_ad_area"; + let ins = document.createElement('ins'); + let scr = document.createElement('script'); + ins.className = 'kakao_ad_area'; // @ts-ignore - ins.style = "display:none; width:100%;"; + ins.style = 'display:none; width:100%;'; // @ts-ignore - scr.async = "true"; - scr.type = "text/javascript"; - scr.src = "//t1.daumcdn.net/kas/static/ba.min.js"; - ins.setAttribute("data-ad-width", width.toString()); - ins.setAttribute("data-ad-height", height.toString()); - ins.setAttribute("data-ad-unit", unit.toString()); - document.querySelector(`.${className}`)?.appendChild(ins); - document.querySelector(`.${className}`)?.appendChild(scr); + scr.async = 'true'; + scr.type = 'text/javascript'; + scr.src = '//t1.daumcdn.net/kas/static/ba.min.js'; + ins.setAttribute('data-ad-width', width.toString()); + ins.setAttribute('data-ad-height', height.toString()); + ins.setAttribute('data-ad-unit', unit.toString()); + document.querySelector(`.${convertedClassName}`)?.appendChild(ins); + document.querySelector(`.${convertedClassName}`)?.appendChild(scr); }, 100); return () => { clearTimeout(timeout); }; - }, [className, height, unit, width]); + }, [className, convertedClassName, height, unit, width]); return (