Skip to content

Commit d4e19dd

Browse files
committed
add new endpoint
1 parent e5c9d6a commit d4e19dd

3 files changed

Lines changed: 34 additions & 41 deletions

File tree

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,25 @@
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

106
const 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

2816
type UseGetAdOptions = {
29-
config?: QueryConfig<QueryFnType>;
30-
};
17+
config?: QueryConfig<QueryFnType>
18+
}
3119
export const useGetAd = ({ config }: UseGetAdOptions = {}) => {
3220
return useQuery<ExtractFnReturnType<QueryFnType>>({
3321
...config,
3422
queryKey: ['ad'],
3523
queryFn: () => getAd(),
36-
});
37-
}
24+
})
25+
}

src/features/carbonAds/components/CarbonAd.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import './CarbonAd.css'
2-
import { addHttpsProtocol } from 'src/utils/UrlUtils'
32
import { useGetAd } from '../api/getAd'
43
import { useRemoteConfigStore } from 'src/features/remoteConfig'
4+
55
export 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>
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
type AdProvider = {
2+
name: string,
3+
title: string,
4+
link?: string,
5+
}
6+
17
export 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
}

0 commit comments

Comments
 (0)