From 0da555865cabb7b2c33162e35ba221288c551437 Mon Sep 17 00:00:00 2001 From: Apoorva Pendse Date: Mon, 25 Nov 2024 13:36:50 +0530 Subject: [PATCH] fix: Replace ~ banner with news carousel in topmenu. --- .../TopMenu/TopMenuHighlightedNews.tsx | 95 ++++++++++++++----- packages/components/hub/NewsBox.tsx | 30 ++++-- 2 files changed, 93 insertions(+), 32 deletions(-) diff --git a/packages/components/TopMenu/TopMenuHighlightedNews.tsx b/packages/components/TopMenu/TopMenuHighlightedNews.tsx index 67ee8f9e8c..d2a6f6d3d6 100644 --- a/packages/components/TopMenu/TopMenuHighlightedNews.tsx +++ b/packages/components/TopMenu/TopMenuHighlightedNews.tsx @@ -1,37 +1,80 @@ -import React from "react"; -import { Image } from "react-native"; +import React, { useEffect, useRef } from "react"; +import { TouchableOpacity, View } from "react-native"; +import Carousel, { ICarouselInstance } from "react-native-reanimated-carousel"; import { TopMenuSection } from "./TopMenuSection"; -import { useBanners } from "../../hooks/marketing/useBanners"; +import chevronLeftSVG from "../../../assets/icons/chevron-left.svg"; +import chevronRightSVG from "../../../assets/icons/chevron-right.svg"; import { useSelectedNetworkId } from "../../hooks/useSelectedNetwork"; -import { web3ToWeb2URI } from "../../utils/ipfs"; -import FlexCol from "../FlexCol"; -import { Link } from "../Link"; -import { PrimaryBox } from "../boxes/PrimaryBox"; +import { FullWidthSeparator } from "../FullWidthSeparator"; +import { SVG } from "../SVG"; +import { Section } from "../Section"; +import { NewsBox } from "../hub/NewsBox"; -export const TopMenuHighlightedNews: React.FC = () => { +import { News } from "@/api/marketplace/v1/marketplace"; +import { useNews } from "@/hooks/marketing/useNews"; +import { fontSemibold10, fontSemibold14 } from "@/utils/style/fonts"; + +export const SmallNewsCarouselSection: React.FC = () => { + const width = 298; + const carouselRef = useRef(null); + const renderItem = (props: { item: News }) => ( + + ); const networkId = useSelectedNetworkId(); - const banners = useBanners(networkId); - const banner = banners?.length ? banners[0] : undefined; + const news = useNews(networkId); + + const topRightChild = ( + + carouselRef.current?.prev()} + style={{ marginRight: 24 }} + > + + + + carouselRef.current?.next()}> + + + + ); + + useEffect(() => { + carouselRef.current?.next(); + }, [width]); + return ( +
+ {/*TODO: Async fetchMore for these data ?*/} + + g.enableTrackpadTwoFingerGesture(true)} + height={650} + pagingEnabled + loop + autoPlay + autoPlayInterval={3000} + renderItem={renderItem} + /> + +
+ ); +}; + +export const TopMenuHighlightedNews: React.FC = () => { return ( - - - - - - - + ); }; diff --git a/packages/components/hub/NewsBox.tsx b/packages/components/hub/NewsBox.tsx index ae6ceef4b6..afa82464b2 100644 --- a/packages/components/hub/NewsBox.tsx +++ b/packages/components/hub/NewsBox.tsx @@ -1,6 +1,12 @@ import { useLinkTo } from "@react-navigation/native"; import React, { useCallback } from "react"; -import { Image, Linking, useWindowDimensions, View } from "react-native"; +import { + Image, + Linking, + TextStyle, + useWindowDimensions, + View, +} from "react-native"; import { News } from "../../api/marketplace/v1/marketplace"; import { web3ToWeb2URI } from "../../utils/ipfs"; @@ -19,8 +25,16 @@ const breakPoint = 768; export const NewsBox: React.FC<{ news: News; -}> = ({ news }) => { - const { width } = useWindowDimensions(); + imageHeight?: number; + imageWidth?: number; + titleTextStyle?: TextStyle; + subtitleTextStyle?: TextStyle; + boxWidth?: number; +}> = ({ news, imageHeight, imageWidth, titleTextStyle, boxWidth }) => { + let { width } = useWindowDimensions(); + if (boxWidth) { + width = boxWidth; + } const linkTo = useLinkTo(); const navigateTo = useCallback( (to: string | undefined) => { @@ -44,6 +58,7 @@ export const NewsBox: React.FC<{ borderBottomColor: neutral33, paddingHorizontal: 10, paddingVertical: 20, + display: "flex", }} > - + {news.title} {news.subtitle} @@ -114,8 +132,8 @@ export const NewsBox: React.FC<{