File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { useQuery } from '@tanstack/react-query' ;
2- import { ExtractFnReturnType , QueryConfig } from 'src/lib/react-query' ;
3- import { Ad } from "../types" ;
4- import { axios } from 'src/lib/axios' ;
5-
6- type Response = {
7- ads : Ad [ ]
8- }
1+ import { useQuery } from '@tanstack/react-query'
2+ import { ExtractFnReturnType , QueryConfig } from 'src/lib/react-query'
3+ import { Ad } from '../types'
4+ import { axios } from 'src/lib/axios'
95
106const getAd = async ( ) : Promise < Ad | null > => {
11- const userAgent = new URLSearchParams ( navigator . userAgent ) . toString ( )
127
13- return axios . get < Ad | null > ( '/monetization/' , {
14- params : {
15- useragent : userAgent
16- }
17- } ) . then ( response => {
18- const data = response as unknown as Response ;
19- if ( ! ! data . ads . length ) {
20- return data . ads [ 0 ] ;
21- }
22- return null ;
23- } ) ;
8+ return axios . get < Ad | null > ( '/engine/ads/' ) . then ( ( response ) => {
9+ const data = response as unknown as Ad
10+ return data
11+ } )
2412}
2513
26- type QueryFnType = typeof getAd ;
14+ type QueryFnType = typeof getAd
2715
2816type UseGetAdOptions = {
29- config ?: QueryConfig < QueryFnType > ;
30- } ;
17+ config ?: QueryConfig < QueryFnType >
18+ }
3119export const useGetAd = ( { config } : UseGetAdOptions = { } ) => {
3220 return useQuery < ExtractFnReturnType < QueryFnType > > ( {
3321 ...config ,
3422 queryKey : [ 'ad' ] ,
3523 queryFn : ( ) => getAd ( ) ,
36- } ) ;
37- }
24+ } )
25+ }
Original file line number Diff line number Diff line change 11import './CarbonAd.css'
2- import { addHttpsProtocol } from 'src/utils/UrlUtils'
32import { useGetAd } from '../api/getAd'
43import { useRemoteConfigStore } from 'src/features/remoteConfig'
4+
55export const CarbonAd = ( ) => {
66 const { refresh_rate } = useRemoteConfigStore ( )
77 const { data : ad } = useGetAd ( {
@@ -10,7 +10,7 @@ export const CarbonAd = () => {
1010 } ,
1111 } )
1212
13- if ( ! ad || ! ad . statlink ) {
13+ if ( ! ad || ! ad . link ) {
1414 return null
1515 }
1616
@@ -21,22 +21,22 @@ export const CarbonAd = () => {
2121 < span >
2222 < span className = "carbon-wrap" >
2323 < a
24- href = { addHttpsProtocol ( ad . statlink ) }
24+ href = { ad . link }
2525 className = "carbon-img"
2626 target = "_blank"
2727 rel = "noopener sponsored noreferrer"
28- title = { ad . company + ' ' + ad . companyTagline } >
28+ title = { ad . title } >
2929 < img
30- src = { ad . smallImage }
31- alt = { ad . company }
30+ src = { ad . imageUrl }
31+ alt = { ad . title }
3232 height = "100"
3333 width = "130"
34- style = { { background : ad . backgroundColor , border : 0 } }
34+ style = { { border : 0 } }
3535 />
3636 </ a >
3737
3838 < a
39- href = { addHttpsProtocol ( ad . statlink ) }
39+ href = { ad . link }
4040 className = "carbon-text"
4141 target = "_blank"
4242 rel = "noopener sponsored noreferrer" >
@@ -45,11 +45,11 @@ export const CarbonAd = () => {
4545 </ span >
4646
4747 < a
48- href = { ad . ad_via_link }
48+ href = { ad . provider . link }
4949 className = "carbon-poweredby"
5050 target = "_blank"
5151 rel = "noopener sponsored noreferrer" >
52- ads via Carbon
52+ { ad . provider . title }
5353 </ a >
5454 </ span >
5555 </ div >
Original file line number Diff line number Diff line change 1+ type AdProvider = {
2+ name : string ,
3+ title : string ,
4+ link ?: string ,
5+ }
6+
17export type Ad = {
2- statlink ?: string ,
3- company : string ,
4- companyTagline : string ,
5- smallImage : string ,
6- backgroundColor : string ,
8+ title ?: string ,
79 description : string ,
8- ad_via_link : string
10+ imageUrl : string ,
11+ link : string ,
12+ backgroundColor ?: string ,
13+ provider : AdProvider ,
914}
You can’t perform that action at this time.
0 commit comments