Skip to content

Commit 7cf1214

Browse files
committed
refactor: simplify AdvFeedItem component by removing unused hooks and restructuring ad loading logic
1 parent 5ec3634 commit 7cf1214

2 files changed

Lines changed: 38 additions & 60 deletions

File tree

src/features/adv/types/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ export type Ad = {
1818
backgroundColor?: string
1919
provider: AdProvider
2020
nextAd?: NextAdType
21+
22+
largeImage?: string
23+
logo?: string
24+
companyTagline?: string
25+
callToAction?: string
26+
company?: string
2127
}
Lines changed: 32 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,39 @@
1-
import { GoDotFill } from 'react-icons/go'
2-
import { useGetAd } from 'src/features/adv'
3-
import { useUserPreferences } from 'src/stores/preferences'
1+
import clsx from 'clsx'
2+
import { useState } from 'react'
3+
import { RiAdvertisementFill } from 'react-icons/ri'
4+
import { Ad, AdvBanner } from 'src/features/adv'
5+
import { AdFeedItemData, BaseItemPropsType } from 'src/types'
46

5-
export const AdvFeedItem = () => {
6-
const { userSelectedTags } = useUserPreferences()
7-
8-
const {
9-
data: ad,
10-
isLoading,
11-
isError,
12-
} = useGetAd({
13-
keywords: userSelectedTags.map((tag) => tag.label.toLocaleLowerCase()),
14-
aditionalAdQueries: undefined,
15-
config: {
16-
cacheTime: 0,
17-
staleTime: 0,
18-
useErrorBoundary: false,
19-
},
20-
})
21-
22-
if (isLoading) {
23-
return (
24-
<div className="placeholder">
25-
<div className="image"></div>
26-
<div className="line"></div>
27-
<div className="smallLine"></div>
28-
</div>
29-
)
30-
}
31-
32-
if (isError || !ad) {
33-
return null
34-
}
7+
export const AdvFeedItem = ({ className }: BaseItemPropsType<AdFeedItemData>) => {
8+
const [adMeta, setAdMeta] = useState<Ad | null>()
359

3610
return (
37-
<div className="blockRow">
38-
<div className="rowTitle">
39-
<a className="rowLink titleWithCover" href={ad.link}>
40-
<div className="rowCover">
41-
<img
42-
src={ad.imageUrl}
43-
alt={ad.title}
44-
className=""
45-
style={{ border: 0 }}
46-
width={260}
47-
height={200}
48-
/>
11+
<div className={clsx('blockRow advFeed', className)}>
12+
<AdvBanner
13+
hideAttribution={true}
14+
onAdLoaded={setAdMeta}
15+
loadingState={
16+
<div className="placeholder">
17+
<div className="image"></div>
18+
<div className="line"></div>
19+
<div className="smallLine"></div>
4920
</div>
50-
51-
<span className="subTitle">{ad.description}</span>
52-
</a>
53-
</div>
54-
<div className="rowDetails">
55-
<span className="rowItem">
56-
<a href={ad.provider.link} target="_blank" rel="noopener sponsored noreferrer">
57-
<GoDotFill className="rowItemIcon" /> {ad.provider.title}
58-
</a>
59-
</span>
60-
</div>
61-
{ad.viewUrl &&
62-
ad.viewUrl
63-
.split('||')
64-
.map((viewUrl, i) => <img key={i} src={viewUrl} className="hidden" alt="" />)}
21+
}
22+
/>
23+
{adMeta && (
24+
<>
25+
<div className="rowTitle">
26+
<span className="subTitle">
27+
{[adMeta.company, adMeta.companyTagline].filter(Boolean).join(' - ')}
28+
</span>
29+
</div>
30+
<div className="rowDetails">
31+
<span className="rowItem verticalAligned">
32+
<RiAdvertisementFill color="orange" size={16} /> Powered by {adMeta.provider.title}
33+
</span>
34+
</div>
35+
</>
36+
)}
6537
</div>
6638
)
6739
}

0 commit comments

Comments
 (0)