|
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"; |
3 | 4 |
|
4 | 5 | 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"; |
6 | 8 | 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"; |
11 | 13 |
|
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 | + ); |
13 | 31 | 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]); |
16 | 52 |
|
| 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 = () => { |
17 | 75 | return ( |
18 | 76 | <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 /> |
35 | 78 | </TopMenuSection> |
36 | 79 | ); |
37 | 80 | }; |
0 commit comments