Skip to content

Commit

Permalink
reuse ins content
Browse files Browse the repository at this point in the history
  • Loading branch information
pveyes committed Nov 1, 2023
1 parent 5fbb585 commit 39d0685
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions components/StatsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import useSWR from "swr";
import {
LegacyRef,
MutableRefObject,
useCallback,
useEffect,
useRef,
useState,
} from "react";
import { LegacyRef, useEffect, useRef, useState } from "react";
import { useTheme } from "next-themes";

import Modal from "./Modal";
Expand Down Expand Up @@ -227,9 +220,11 @@ export default function StatsModal(props: Props) {
const maxDistribution = Math.max(...Object.values(distribution));

const [isAdUnitRendered, setIsAdUnitRendered] = useState(false);
const adsByGooglePushedRef = useRef(false);
const adUnitRef = useRef<HTMLDivElement>(null);

useEffect(() => {
if (!isOpen || !isAdUnitRendered) return;
if (!isOpen || !isAdUnitRendered || adsByGooglePushedRef.current) return;

const adUnit = adUnitRef.current;
adUnit.innerHTML = `<!-- stats-ads -->
Expand All @@ -239,9 +234,11 @@ export default function StatsModal(props: Props) {
data-ad-slot="2576511153"
data-ad-format="auto"
data-full-width-responsive="true"></ins>`;

try {
// @ts-ignore
window.adsbygoogle = (window.adsbygoogle || []).push({});
adsByGooglePushedRef.current = true;
} catch (err) {
// ignore
}
Expand Down

1 comment on commit 39d0685

@vercel
Copy link

@vercel vercel bot commented on 39d0685 Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

katla – ./

katla-git-main-katla.vercel.app
katla.vercel.app
katla-katla.vercel.app
katla.id

Please sign in to comment.