File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,21 +3,22 @@ import { ExtractFnReturnType, QueryConfig } from 'src/lib/react-query'
33import { Ad } from '../types'
44import { axios } from 'src/lib/axios'
55
6- const getAd = async ( ) : Promise < Ad | null > => {
6+ const getAd = async ( keywords : string [ ] ) : Promise < Ad | null > => {
77 let url = new URL ( window . location . href ) ;
88 let ref = url . searchParams . get ( "ref" ) ;
9- return axios . get ( '/engine/ads/' , { params : { ref } } )
9+ return axios . get ( '/engine/ads/' , { params : { ref, keywords : keywords . join ( "," ) } } )
1010}
1111
1212type QueryFnType = typeof getAd
1313
1414type UseGetAdOptions = {
15+ keywords : string [ ] ;
1516 config ?: QueryConfig < QueryFnType >
1617}
17- export const useGetAd = ( { config } : UseGetAdOptions = { } ) => {
18+ export const useGetAd = ( { keywords , config } : UseGetAdOptions ) => {
1819 return useQuery < ExtractFnReturnType < QueryFnType > > ( {
1920 ...config ,
2021 queryKey : [ 'ad' ] ,
21- queryFn : ( ) => getAd ( ) ,
22+ queryFn : ( ) => getAd ( keywords ) ,
2223 } )
2324}
Original file line number Diff line number Diff line change 11import './BannerAd.css'
22import { useGetAd } from '../api/getAd'
3+ import { useUserPreferences } from 'src/stores/preferences'
34import { AdPlaceholder } from 'src/components/placeholders'
45
56export const BannerAd = ( ) => {
7+ const { userSelectedTags } = useUserPreferences ( )
68 const {
79 data : ad ,
810 isLoading,
911 isError,
1012 } = useGetAd ( {
13+ keywords : userSelectedTags . map ( tag => tag . label . toLocaleLowerCase ( ) ) ,
1114 config : {
1215 cacheTime : 0 ,
1316 staleTime : 0 ,
@@ -57,7 +60,7 @@ export const BannerAd = () => {
5760 </ span >
5861 </ div >
5962 { ad . viewUrl && (
60- < img src = { ad . viewUrl } key = { ad . viewUrl } className = "hidden" alt = "Pixel " />
63+ < img src = { ad . viewUrl } key = { ad . viewUrl } className = "hidden" alt = "" />
6164 ) }
6265 </ div >
6366 )
You can’t perform that action at this time.
0 commit comments