import React, { useEffect } from "react"; import { OptionsType } from "../types/options"; import { Options } from "../Options"; import { adsShowingState } from "../states/adsShowingState"; import { useRecoilState } from "recoil"; import { Check } from "../Check"; import { adsCurrentPlaceState } from "../states/adsCurrentPlaceState"; export default function AdsScreen() { const options: OptionsType = Options.getInstance().get(); const [adsShowing, setAdsShowing] = useRecoilState(adsShowingState); const [adsCurrentPlace] = useRecoilState(adsCurrentPlaceState); const check = Check.getInstance(); const startCloseInterval = () => { const interval = setInterval(async () => { if (await check.isViewedAds()) { setAdsShowing(false); clearInterval(interval); } }, 1000); return interval; }; useEffect(() => { const interval = startCloseInterval(); return () => clearInterval(interval); }, []); return ( <> {adsShowing && options.autoOpenAds && (