Skip to content

Commit 0da5558

Browse files
committed
fix: Replace ~ banner with news carousel in topmenu.
1 parent 16b2f01 commit 0da5558

File tree

2 files changed

+93
-32
lines changed

2 files changed

+93
-32
lines changed
Lines changed: 69 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,80 @@
1-
import React from "react";
2-
import { Image } from "react-native";
1+
import React, { useEffect, useRef } from "react";
2+
import { TouchableOpacity, View } from "react-native";
3+
import Carousel, { ICarouselInstance } from "react-native-reanimated-carousel";
34

45
import { TopMenuSection } from "./TopMenuSection";
5-
import { useBanners } from "../../hooks/marketing/useBanners";
6+
import chevronLeftSVG from "../../../assets/icons/chevron-left.svg";
7+
import chevronRightSVG from "../../../assets/icons/chevron-right.svg";
68
import { useSelectedNetworkId } from "../../hooks/useSelectedNetwork";
7-
import { web3ToWeb2URI } from "../../utils/ipfs";
8-
import FlexCol from "../FlexCol";
9-
import { Link } from "../Link";
10-
import { PrimaryBox } from "../boxes/PrimaryBox";
9+
import { FullWidthSeparator } from "../FullWidthSeparator";
10+
import { SVG } from "../SVG";
11+
import { Section } from "../Section";
12+
import { NewsBox } from "../hub/NewsBox";
1113

12-
export const TopMenuHighlightedNews: React.FC = () => {
14+
import { News } from "@/api/marketplace/v1/marketplace";
15+
import { useNews } from "@/hooks/marketing/useNews";
16+
import { fontSemibold10, fontSemibold14 } from "@/utils/style/fonts";
17+
18+
export const SmallNewsCarouselSection: React.FC = () => {
19+
const width = 298;
20+
const carouselRef = useRef<ICarouselInstance | null>(null);
21+
const renderItem = (props: { item: News }) => (
22+
<NewsBox
23+
news={props.item}
24+
imageHeight={210}
25+
imageWidth={210}
26+
titleTextStyle={fontSemibold14}
27+
subtitleTextStyle={fontSemibold10}
28+
boxWidth={298}
29+
/>
30+
);
1331
const networkId = useSelectedNetworkId();
14-
const banners = useBanners(networkId);
15-
const banner = banners?.length ? banners[0] : undefined;
32+
const news = useNews(networkId);
33+
34+
const topRightChild = (
35+
<View style={{ flexDirection: "row", alignItems: "center" }}>
36+
<TouchableOpacity
37+
onPress={() => carouselRef.current?.prev()}
38+
style={{ marginRight: 24 }}
39+
>
40+
<SVG width={16} height={16} source={chevronLeftSVG} />
41+
</TouchableOpacity>
42+
43+
<TouchableOpacity onPress={() => carouselRef.current?.next()}>
44+
<SVG width={16} height={16} source={chevronRightSVG} />
45+
</TouchableOpacity>
46+
</View>
47+
);
48+
49+
useEffect(() => {
50+
carouselRef.current?.next();
51+
}, [width]);
1652

53+
return (
54+
<Section topRightChild={topRightChild}>
55+
{/*TODO: Async fetchMore for these data ?*/}
56+
57+
<Carousel
58+
width={width}
59+
data={news || []}
60+
ref={carouselRef}
61+
onConfigurePanGesture={(g) => g.enableTrackpadTwoFingerGesture(true)}
62+
height={650}
63+
pagingEnabled
64+
loop
65+
autoPlay
66+
autoPlayInterval={3000}
67+
renderItem={renderItem}
68+
/>
69+
<FullWidthSeparator />
70+
</Section>
71+
);
72+
};
73+
74+
export const TopMenuHighlightedNews: React.FC = () => {
1775
return (
1876
<TopMenuSection title="Highlighted News">
19-
<FlexCol>
20-
<Link to={banner?.url || ""}>
21-
<PrimaryBox>
22-
<Image
23-
source={{
24-
uri: web3ToWeb2URI(banner?.image),
25-
}}
26-
style={{
27-
height: 94,
28-
width: 298,
29-
borderRadius: 7,
30-
}}
31-
/>
32-
</PrimaryBox>
33-
</Link>
34-
</FlexCol>
77+
<SmallNewsCarouselSection />
3578
</TopMenuSection>
3679
);
3780
};

packages/components/hub/NewsBox.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { useLinkTo } from "@react-navigation/native";
22
import React, { useCallback } from "react";
3-
import { Image, Linking, useWindowDimensions, View } from "react-native";
3+
import {
4+
Image,
5+
Linking,
6+
TextStyle,
7+
useWindowDimensions,
8+
View,
9+
} from "react-native";
410

511
import { News } from "../../api/marketplace/v1/marketplace";
612
import { web3ToWeb2URI } from "../../utils/ipfs";
@@ -19,8 +25,16 @@ const breakPoint = 768;
1925

2026
export const NewsBox: React.FC<{
2127
news: News;
22-
}> = ({ news }) => {
23-
const { width } = useWindowDimensions();
28+
imageHeight?: number;
29+
imageWidth?: number;
30+
titleTextStyle?: TextStyle;
31+
subtitleTextStyle?: TextStyle;
32+
boxWidth?: number;
33+
}> = ({ news, imageHeight, imageWidth, titleTextStyle, boxWidth }) => {
34+
let { width } = useWindowDimensions();
35+
if (boxWidth) {
36+
width = boxWidth;
37+
}
2438
const linkTo = useLinkTo();
2539
const navigateTo = useCallback(
2640
(to: string | undefined) => {
@@ -44,6 +58,7 @@ export const NewsBox: React.FC<{
4458
borderBottomColor: neutral33,
4559
paddingHorizontal: 10,
4660
paddingVertical: 20,
61+
display: "flex",
4762
}}
4863
>
4964
<View
@@ -64,7 +79,10 @@ export const NewsBox: React.FC<{
6479
]}
6580
>
6681
<View>
67-
<GradientText gradientType="blueExtended" style={fontSemibold28}>
82+
<GradientText
83+
gradientType="blueExtended"
84+
style={titleTextStyle || fontSemibold28}
85+
>
6886
{news.title}
6987
</GradientText>
7088
<BrandText style={fontSemibold20}>{news.subtitle}</BrandText>
@@ -114,8 +132,8 @@ export const NewsBox: React.FC<{
114132
<Image
115133
source={{ uri: web3ToWeb2URI(news.image) }}
116134
style={{
117-
height: 342,
118-
width: 342,
135+
height: imageHeight || 342,
136+
width: imageWidth || 342,
119137
aspectRatio: 1,
120138
borderRadius: 10,
121139
}}

0 commit comments

Comments
 (0)