chore: don't show ad on no search result (#668)

* chore: don't show ad on no search result

* feat: add disabled prop to Advertisement component and update usage for search page

---------

Co-authored-by: soyoka <55011525+soy0ka@users.noreply.github.com>
This commit is contained in:
Eunwoo Choi 2025-02-10 00:25:30 +09:00 committed by GitHub
parent 138ef55734
commit e99e661b8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View File

@ -1,6 +1,8 @@
import AdSense from 'react-adsense' import AdSense from 'react-adsense'
const Advertisement: React.FC<AdvertisementProps> = ({ size = 'short' }) => { const Advertisement: React.FC<AdvertisementProps> = ({ size = 'short', disabled = false }) => {
if (disabled) return null
return ( return (
<div className='py-5'> <div className='py-5'>
<div <div
@ -39,6 +41,7 @@ declare global {
interface AdvertisementProps { interface AdvertisementProps {
size?: 'short' | 'tall' size?: 'short' | 'tall'
disabled?: boolean
} }
export default Advertisement export default Advertisement

View File

@ -1,12 +1,12 @@
import { NextPage, NextPageContext } from 'next' import { NextPage, NextPageContext } from 'next'
import type { FC } from 'react'
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
import { ParsedUrlQuery } from 'querystring' import { ParsedUrlQuery } from 'querystring'
import type { FC } from 'react'
import { List, Bot, Server } from '@types' import { Bot, List, Server } from '@types'
import { KoreanbotsEndPoints } from '@utils/Constants'
import { get } from '@utils/Query' import { get } from '@utils/Query'
import { SearchQuerySchema } from '@utils/Yup' import { SearchQuerySchema } from '@utils/Yup'
import { KoreanbotsEndPoints } from '@utils/Constants'
const Hero = dynamic(() => import('@components/Hero')) const Hero = dynamic(() => import('@components/Hero'))
const Advertisement = dynamic(() => import('@components/Advertisement')) const Advertisement = dynamic(() => import('@components/Advertisement'))
@ -58,6 +58,8 @@ const SearchComponent: FC<{
const Search: NextPage<SearchProps> = ({ botData, serverData, priority, query }) => { const Search: NextPage<SearchProps> = ({ botData, serverData, priority, query }) => {
if (!query?.q) return <Redirect text={false} to='/' /> if (!query?.q) return <Redirect text={false} to='/' />
const list: ('bot' | 'server')[] = ['bot', 'server'] const list: ('bot' | 'server')[] = ['bot', 'server']
const resultNotExists =
(!botData || botData.data.length === 0) && (!serverData || serverData.data.length === 0)
return ( return (
<> <>
<Hero <Hero
@ -67,7 +69,7 @@ const Search: NextPage<SearchProps> = ({ botData, serverData, priority, query })
/> />
<Container> <Container>
<section id='list'> <section id='list'>
<Advertisement /> <Advertisement disabled={resultNotExists} />
{(priority === 'server' ? list.reverse() : list).map((el) => ( {(priority === 'server' ? list.reverse() : list).map((el) => (
<SearchComponent <SearchComponent
key={el} key={el}
@ -76,7 +78,7 @@ const Search: NextPage<SearchProps> = ({ botData, serverData, priority, query })
type={el} type={el}
/> />
))} ))}
<Advertisement /> <Advertisement disabled={resultNotExists} />
</section> </section>
</Container> </Container>
</> </>