11import React , { useEffect , useState } from 'react' ;
22import styled from 'styled-components' ;
33import media from '../../lib/styles/media' ;
4+ import { isTablet } from '../../lib/deviceDetection' ;
45
56const Wrapper = styled . div `
6- display: none;
7- ${ media . medium } {
8- display: flex;
9- justify-content: center;
10- align-items: center;
11- margin: 16px 0;
12- }
7+ display: flex;
8+ justify-content: center;
9+ align-items: center;
10+ margin: 16px 0;
1311` ;
1412
1513const AdBlock = styled . div < { width : number ; height : number } > `
@@ -48,7 +46,7 @@ function AdInsComponent({
4846}
4947
5048export default function NarrowAd ( ) {
51- const [ isMobile , setIsMobile ] = useState ( false ) ;
49+ const [ isMobileOrTablet , setIsMobileOrTablet ] = useState ( false ) ;
5250 const [ mode , setMode ] = useState < 'wide' | 'narrow' > ( 'wide' ) ;
5351
5452 useEffect ( ( ) => {
@@ -57,8 +55,9 @@ export default function NarrowAd() {
5755 / a n d r o i d | w e b o s | i p h o n e | i p a d | i p o d | b l a c k b e r r y | i e m o b i l e | o p e r a m i n i / i. test (
5856 userAgent ,
5957 ) ;
58+ const checkIsTablet = isTablet ( ) ;
6059
61- setIsMobile ( checkIsMobile ) ;
60+ setIsMobileOrTablet ( checkIsMobile || checkIsTablet ) ;
6261
6362 // Set mode based on window width
6463 const windowWidth = window . innerWidth ;
@@ -80,14 +79,12 @@ export default function NarrowAd() {
8079 } , [ ] ) ;
8180
8281 const size =
83- mode === 'narrow'
84- ? { width : 300 , height : 50 }
85- : { width : 728 , height : 90 } ;
82+ mode === 'narrow' ? { width : 300 , height : 50 } : { width : 728 , height : 90 } ;
8683 const adSlot = mode === 'narrow' ? '1778476944' : '5606751754' ;
8784
8885 return (
8986 < Wrapper >
90- { isMobile && mode === 'narrow' && (
87+ { isMobileOrTablet && mode === 'narrow' && (
9188 < AdBlock width = { size . width } height = { size . height } >
9289 < AdInsComponent
9390 width = { size . width }
@@ -96,7 +93,7 @@ export default function NarrowAd() {
9693 />
9794 </ AdBlock >
9895 ) }
99- { isMobile && mode === 'wide' && (
96+ { isMobileOrTablet && mode === 'wide' && (
10097 < AdBlock width = { size . width } height = { size . height } >
10198 < AdInsComponent
10299 width = { size . width }
0 commit comments