Skip to content

Commit bbd734a

Browse files
authored
Merge pull request #117 from medyo/fix/ads
Fix/ads
2 parents 7d3248e + 228106d commit bbd734a

9 files changed

Lines changed: 62 additions & 75 deletions

File tree

src/components/List/ListComponent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { ReactNode } from 'react'
22
import { Placeholder } from 'src/components/placeholders'
33
import { MAX_ITEMS_PER_CARD } from 'src/config'
4-
import { CarbonAd } from 'src/features/carbonAds'
4+
import { BannerAd } from 'src/features/ads'
55
import { BaseEntry } from 'src/types'
66

77
type PlaceholdersProps = {
@@ -52,7 +52,7 @@ export function ListComponent<T extends BaseEntry>(props: ListComponentPropsType
5252
return items.slice(0, limit).map((item, index) => {
5353
let content: ReactNode[] = [renderItem(item, index)]
5454
if (withAds && index === 0) {
55-
content.unshift(<CarbonAd key={'carbonAd0'} />)
55+
content.unshift(<BannerAd key={'BannerAd0'} />)
5656
}
5757
return content
5858
})

src/features/ads/api/getAd.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
const getAd = async (): Promise<Ad | null> => {
7+
return axios.get('/engine/ads/')
8+
}
9+
10+
type QueryFnType = typeof getAd
11+
12+
type UseGetAdOptions = {
13+
config?: QueryConfig<QueryFnType>
14+
}
15+
export const useGetAd = ({ config }: UseGetAdOptions = {}) => {
16+
return useQuery<ExtractFnReturnType<QueryFnType>>({
17+
...config,
18+
queryKey: ['ad'],
19+
queryFn: () => getAd(),
20+
})
21+
}

src/features/carbonAds/components/CarbonAd.css renamed to src/features/ads/components/BannerAd.css

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
#carbonads * {
1+
#bannerads * {
22
margin: initial;
33
padding: initial;
44
}
5-
#carbonads {
5+
#bannerads {
66
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
77
Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', Helvetica, Arial,
88
sans-serif;
99
}
10-
#carbonads {
10+
#bannerads {
1111
display: flex;
1212
max-width: 330px;
1313
z-index: 100;
1414
margin: 0 auto
1515
}
16-
#carbonads a {
16+
#bannerads a {
1717
color: inherit;
1818
text-decoration: none;
1919
}
20-
#carbonads a:hover {
20+
#bannerads a:hover {
2121
color: inherit;
2222
}
23-
#carbonads span {
23+
#bannerads span {
2424
position: relative;
2525
display: block;
2626
overflow: hidden;
2727
}
28-
#carbonads .carbon-wrap {
28+
#bannerads .carbon-wrap {
2929
display: flex;
3030
}
31-
#carbonads .carbon-img {
31+
#bannerads .carbon-img {
3232
display: block;
3333
margin: 0;
3434
line-height: 1;
3535
}
36-
#carbonads .carbon-img img {
36+
#bannerads .carbon-img img {
3737
display: block;
3838
}
39-
#carbonads .carbon-text {
39+
#bannerads .carbon-text {
4040
font-size: 13px;
4141
padding: 10px;
4242
margin-bottom: 16px;
4343
line-height: 1.5;
4444
text-align: left;
4545
}
46-
#carbonads .carbon-poweredby {
46+
#bannerads .carbon-poweredby {
4747
display: block;
4848
padding: 6px 8px;
4949
background: inherit;

src/features/carbonAds/components/CarbonAd.tsx renamed to src/features/ads/components/BannerAd.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
1-
import './CarbonAd.css'
2-
import { addHttpsProtocol } from 'src/utils/UrlUtils'
1+
import './BannerAd.css'
32
import { useGetAd } from '../api/getAd'
43

4+
export const BannerAd = () => {
5+
const { data: ad, isError } = useGetAd()
56

6-
export const CarbonAd = () => {
7-
const { data: ad } = useGetAd()
8-
9-
if (!ad || !ad.statlink) {
7+
if (isError || !ad) {
108
return null
119
}
1210

1311
return (
1412
<div className="carbon-ad-wrapper blockRow">
1513
{ad && (
16-
<div id="carbonads">
14+
<div id="bannerads">
1715
<span>
1816
<span className="carbon-wrap">
1917
<a
20-
href={addHttpsProtocol(ad.statlink)}
18+
href={ad.link}
2119
className="carbon-img"
2220
target="_blank"
2321
rel="noopener sponsored noreferrer"
24-
title={ad.company + ' ' + ad.companyTagline}>
22+
title={ad.title}>
2523
<img
26-
src={ad.smallImage}
27-
alt={ad.company}
24+
src={ad.imageUrl}
25+
alt={ad.title}
2826
height="100"
2927
width="130"
30-
style={{ background: ad.backgroundColor, border: 0 }}
28+
style={{ border: 0 }}
3129
/>
3230
</a>
3331

3432
<a
35-
href={addHttpsProtocol(ad.statlink)}
33+
href={ad.link}
3634
className="carbon-text"
3735
target="_blank"
3836
rel="noopener sponsored noreferrer">
@@ -41,11 +39,11 @@ export const CarbonAd = () => {
4139
</span>
4240

4341
<a
44-
href={ad.ad_via_link}
42+
href={ad.provider.link}
4543
className="carbon-poweredby"
4644
target="_blank"
4745
rel="noopener sponsored noreferrer">
48-
ads via Carbon
46+
{ad.provider.title}
4947
</a>
5048
</span>
5149
</div>

src/features/ads/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./components/BannerAd";

src/features/ads/types/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
type AdProvider = {
2+
name: string,
3+
title: string,
4+
link?: string,
5+
}
6+
7+
export type Ad = {
8+
title?: string,
9+
description: string,
10+
imageUrl: string,
11+
link: string,
12+
backgroundColor?: string,
13+
provider: AdProvider,
14+
}

src/features/carbonAds/api/getAd.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/features/carbonAds/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/features/carbonAds/types/index.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)