Commit 5fcde0f5 authored by tom's avatar tom

New homepage layout loading bug on mobile

Fixes #2137
parent 02556490
...@@ -11,7 +11,7 @@ NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL=ws ...@@ -11,7 +11,7 @@ NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL=ws
# Instance ENVs # Instance ENVs
NEXT_PUBLIC_AD_ADBUTLER_CONFIG_DESKTOP={ "id": "728301", "width": "728", "height": "90" } NEXT_PUBLIC_AD_ADBUTLER_CONFIG_DESKTOP={ "id": "728301", "width": "728", "height": "90" }
NEXT_PUBLIC_AD_ADBUTLER_CONFIG_MOBILE={ "id": "728301", "width": "320", "height": "100" } NEXT_PUBLIC_AD_ADBUTLER_CONFIG_MOBILE={ "id": "728302", "width": "320", "height": "100" }
NEXT_PUBLIC_AD_BANNER_ADDITIONAL_PROVIDER=adbutler NEXT_PUBLIC_AD_BANNER_ADDITIONAL_PROVIDER=adbutler
NEXT_PUBLIC_ADMIN_SERVICE_API_HOST=https://admin-rs.services.blockscout.com NEXT_PUBLIC_ADMIN_SERVICE_API_HOST=https://admin-rs.services.blockscout.com
NEXT_PUBLIC_API_BASE_PATH=/ NEXT_PUBLIC_API_BASE_PATH=/
......
...@@ -2,7 +2,6 @@ import { Box, Flex, Heading } from '@chakra-ui/react'; ...@@ -2,7 +2,6 @@ import { Box, Flex, Heading } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import config from 'configs/app'; import config from 'configs/app';
import useIsMobile from 'lib/hooks/useIsMobile';
import ChainIndicators from 'ui/home/indicators/ChainIndicators'; import ChainIndicators from 'ui/home/indicators/ChainIndicators';
import LatestBlocks from 'ui/home/LatestBlocks'; import LatestBlocks from 'ui/home/LatestBlocks';
import LatestZkEvmL2Batches from 'ui/home/LatestZkEvmL2Batches'; import LatestZkEvmL2Batches from 'ui/home/LatestZkEvmL2Batches';
...@@ -16,8 +15,6 @@ import WalletMenuDesktop from 'ui/snippets/walletMenu/WalletMenuDesktop'; ...@@ -16,8 +15,6 @@ import WalletMenuDesktop from 'ui/snippets/walletMenu/WalletMenuDesktop';
const rollupFeature = config.features.rollup; const rollupFeature = config.features.rollup;
const Home = () => { const Home = () => {
const isMobile = useIsMobile();
return ( return (
<Box as="main"> <Box as="main">
<Flex <Flex
...@@ -53,13 +50,13 @@ const Home = () => { ...@@ -53,13 +50,13 @@ const Home = () => {
</Flex> </Flex>
<SearchBar isHomepage/> <SearchBar isHomepage/>
</Box> </Box>
{ !isMobile && <AdBanner platform="mobile" w="fit-content" flexShrink={ 0 } borderRadius="md" overflow="hidden"/> } <AdBanner platform="mobile" w="fit-content" flexShrink={ 0 } borderRadius="md" overflow="hidden" display={{ base: 'none', lg: 'block ' }}/>
</Flex> </Flex>
<Flex flexDir={{ base: 'column', lg: 'row' }} columnGap={ 2 } rowGap={ 1 } mt={ 3 } _empty={{ mt: 0 }}> <Flex flexDir={{ base: 'column', lg: 'row' }} columnGap={ 2 } rowGap={ 1 } mt={ 3 } _empty={{ mt: 0 }}>
<Stats/> <Stats/>
<ChainIndicators/> <ChainIndicators/>
</Flex> </Flex>
{ isMobile && <AdBanner mt={ 6 } mx="auto" display="flex" justifyContent="center"/> } <AdBanner mt={ 6 } mx="auto" display={{ base: 'flex', lg: 'none' }} justifyContent="center"/>
<Flex mt={ 8 } direction={{ base: 'column', lg: 'row' }} columnGap={ 12 } rowGap={ 6 }> <Flex mt={ 8 } direction={{ base: 'column', lg: 'row' }} columnGap={ 12 } rowGap={ 6 }>
{ rollupFeature.isEnabled && rollupFeature.type === 'zkEvm' ? <LatestZkEvmL2Batches/> : <LatestBlocks/> } { rollupFeature.isEnabled && rollupFeature.type === 'zkEvm' ? <LatestZkEvmL2Batches/> : <LatestBlocks/> }
<Box flexGrow={ 1 }> <Box flexGrow={ 1 }>
......
...@@ -14,14 +14,27 @@ const feature = config.features.adsBanner; ...@@ -14,14 +14,27 @@ const feature = config.features.adsBanner;
const AdbutlerBanner = ({ className, platform }: BannerProps) => { const AdbutlerBanner = ({ className, platform }: BannerProps) => {
const router = useRouter(); const router = useRouter();
const isMobileViewport = useIsMobile(); const isMobileViewport = useIsMobile();
const isMobile = platform === 'mobile' || isMobileViewport; const isMobile = platform === 'mobile' || isMobileViewport;
// On the home page there are two ad banners
// - one in the stats section with prop "platform === mobile", should be hidden on mobile devices
// - another - a regular ad banner, should be hidden on desktop devices
// The Adbutler provider doesn't work properly with 2 banners with the same id on the page
// So we use this flag to skip ad initialization for the first home page banner on mobile devices
// For all other pages this is not the case
const isHidden = (isMobileViewport && platform === 'mobile');
React.useEffect(() => { React.useEffect(() => {
if (!('adButler' in feature)) { if (!('adButler' in feature)) {
return; return;
} }
if (isHidden) {
return;
}
if (isBrowser() && window.AdButler) { if (isBrowser() && window.AdButler) {
const abkw = window.abkw || ''; const abkw = window.abkw || '';
if (!window.AdButler.ads) { if (!window.AdButler.ads) {
...@@ -47,7 +60,7 @@ const AdbutlerBanner = ({ className, platform }: BannerProps) => { ...@@ -47,7 +60,7 @@ const AdbutlerBanner = ({ className, platform }: BannerProps) => {
); );
}, opt: { place: plc++, keywords: abkw, domain: 'servedbyadbutler.com', click: 'CLICK_MACRO_PLACEHOLDER' } }); }, opt: { place: plc++, keywords: abkw, domain: 'servedbyadbutler.com', click: 'CLICK_MACRO_PLACEHOLDER' } });
} }
}, [ router, isMobile ]); }, [ router, isMobile, isHidden ]);
if (!('adButler' in feature)) { if (!('adButler' in feature)) {
return null; return null;
...@@ -73,11 +86,17 @@ const AdbutlerBanner = ({ className, platform }: BannerProps) => { ...@@ -73,11 +86,17 @@ const AdbutlerBanner = ({ className, platform }: BannerProps) => {
} }
})() ?? { width: '0', height: '0' }; })() ?? { width: '0', height: '0' };
const getElementId = (id: string) => id + (platform ? `_${ platform }` : '');
return ( return (
<Flex className={ className } id="adBanner" h={ height } w={ width }> <Flex className={ className } id={ getElementId('adBanner') } h={ height } w={ width }>
<Script strategy="lazyOnload" id="ad-butler-1">{ connectAdbutler }</Script> { !isHidden && (
<Script strategy="lazyOnload" id="ad-butler-2">{ placeAd(platform) }</Script> <>
<div id="ad-banner"></div> <Script strategy="lazyOnload" id="ad-butler-1">{ connectAdbutler }</Script>
<Script strategy="lazyOnload" id="ad-butler-2">{ placeAd(platform) }</Script>
<div id="ad-banner"></div>
</>
) }
</Flex> </Flex>
); );
}; };
......
...@@ -4,10 +4,20 @@ import React from 'react'; ...@@ -4,10 +4,20 @@ import React from 'react';
import type { BannerProps } from './types'; import type { BannerProps } from './types';
import useIsMobile from 'lib/hooks/useIsMobile';
import isBrowser from 'lib/isBrowser'; import isBrowser from 'lib/isBrowser';
const CoinzillaBanner = ({ className, platform }: BannerProps) => { const CoinzillaBanner = ({ className, platform }: BannerProps) => {
const isInBrowser = isBrowser(); const isInBrowser = isBrowser();
const isMobileViewport = useIsMobile();
// On the home page there are two ad banners
// - one in the stats section with prop "platform === mobile", should be hidden on mobile devices
// - another - a regular ad banner, should be hidden on desktop devices
// The Coinzilla provider doesn't work properly with 2 banners with the same id on the page
// So we use this flag to skip ad initialization for the first home page banner on mobile devices
// For all other pages this is not the case
const isHidden = (isMobileViewport && platform === 'mobile');
const { width, height } = (() => { const { width, height } = (() => {
switch (platform) { switch (platform) {
...@@ -22,7 +32,7 @@ const CoinzillaBanner = ({ className, platform }: BannerProps) => { ...@@ -22,7 +32,7 @@ const CoinzillaBanner = ({ className, platform }: BannerProps) => {
})(); })();
React.useEffect(() => { React.useEffect(() => {
if (isInBrowser) { if (isInBrowser && !isHidden) {
window.coinzilla_display = window.coinzilla_display || []; window.coinzilla_display = window.coinzilla_display || [];
const cDisplayPreferences = { const cDisplayPreferences = {
zone: '26660bf627543e46851', zone: '26660bf627543e46851',
...@@ -31,7 +41,7 @@ const CoinzillaBanner = ({ className, platform }: BannerProps) => { ...@@ -31,7 +41,7 @@ const CoinzillaBanner = ({ className, platform }: BannerProps) => {
}; };
window.coinzilla_display.push(cDisplayPreferences); window.coinzilla_display.push(cDisplayPreferences);
} }
}, [ height, isInBrowser, width ]); }, [ height, isInBrowser, isHidden, width ]);
return ( return (
<Flex <Flex
...@@ -40,8 +50,12 @@ const CoinzillaBanner = ({ className, platform }: BannerProps) => { ...@@ -40,8 +50,12 @@ const CoinzillaBanner = ({ className, platform }: BannerProps) => {
h={ height ? `${ height }px` : { base: '100px', lg: '90px' } } h={ height ? `${ height }px` : { base: '100px', lg: '90px' } }
w={ width ? `${ width }px` : undefined } w={ width ? `${ width }px` : undefined }
> >
<Script strategy="lazyOnload" src="https://coinzillatag.com/lib/display.js"/> { !isHidden && (
<div className="coinzilla" data-zone="C-26660bf627543e46851"></div> <>
<Script strategy="lazyOnload" src="https://coinzillatag.com/lib/display.js"/>
<div className="coinzilla" data-zone="C-26660bf627543e46851"></div>
</>
) }
</Flex> </Flex>
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment