Skip to content

Commit e49cb59

Browse files
committed
feat: add AdvFeedItem component to display advertisements with user-selected tags
1 parent 40fc24c commit e49cb59

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

src/features/adv/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from './api/getAd'
12
export * from './components/AdvBanner'
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { GoDotFill } from 'react-icons/go'
2+
import { useGetAd } from 'src/features/adv'
3+
import { useUserPreferences } from 'src/stores/preferences'
4+
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+
}
35+
36+
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+
/>
49+
</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="" />)}
65+
</div>
66+
)
67+
}

0 commit comments

Comments
 (0)