-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Replace ~ banner with news carousel in topmenu.
- Loading branch information
1 parent
16b2f01
commit e84363b
Showing
2 changed files
with
79 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,75 @@ | ||
import React from "react"; | ||
import { Image } from "react-native"; | ||
import React, { useEffect, useRef } from "react"; | ||
import { Image, TouchableOpacity, View } from "react-native"; | ||
|
||
import { TopMenuSection } from "./TopMenuSection"; | ||
import { useBanners } from "../../hooks/marketing/useBanners"; | ||
import { useSelectedNetworkId } from "../../hooks/useSelectedNetwork"; | ||
import { web3ToWeb2URI } from "../../utils/ipfs"; | ||
import FlexCol from "../FlexCol"; | ||
import { Link } from "../Link"; | ||
import { PrimaryBox } from "../boxes/PrimaryBox"; | ||
import { useNews } from "@/hooks/marketing/useNews"; | ||
import { News } from "@/api/marketplace/v1/marketplace"; | ||
Check failure on line 7 in packages/components/TopMenu/TopMenuHighlightedNews.tsx GitHub Actions / check-js
|
||
import Carousel, { ICarouselInstance } from "react-native-reanimated-carousel"; | ||
Check failure on line 8 in packages/components/TopMenu/TopMenuHighlightedNews.tsx GitHub Actions / check-js
|
||
import { FullWidthSeparator } from "../FullWidthSeparator"; | ||
import { Section } from "../Section"; | ||
import { NewsBox } from "../hub/NewsBox"; | ||
import { SVG } from "../SVG"; | ||
|
||
export const TopMenuHighlightedNews: React.FC = () => { | ||
import chevronLeftSVG from "../../../assets/icons/chevron-left.svg"; | ||
import chevronRightSVG from "../../../assets/icons/chevron-right.svg"; | ||
import { fontSemibold10, fontSemibold14 } from "@/utils/style/fonts"; | ||
|
||
export const SmallNewsCarouselSection: React.FC = () => { | ||
const width = 298 | ||
const carouselRef = useRef<ICarouselInstance | null>(null); | ||
const renderItem = (props: { item: News }) => | ||
<NewsBox news={props.item} imageHeight={210} imageWidth={210} | ||
titleTextStyle={fontSemibold14} subtitleTextStyle={fontSemibold10} boxWidth={298} />; | ||
const networkId = useSelectedNetworkId(); | ||
const banners = useBanners(networkId); | ||
const banner = banners?.length ? banners[0] : undefined; | ||
const news = useNews(networkId); | ||
|
||
const topRightChild = ( | ||
<View style={{ flexDirection: "row", alignItems: "center" }}> | ||
<TouchableOpacity | ||
onPress={() => carouselRef.current?.prev()} | ||
style={{ marginRight: 24 }} | ||
> | ||
<SVG width={16} height={16} source={chevronLeftSVG} /> | ||
</TouchableOpacity> | ||
|
||
<TouchableOpacity onPress={() => carouselRef.current?.next()}> | ||
<SVG width={16} height={16} source={chevronRightSVG} /> | ||
</TouchableOpacity> | ||
</View> | ||
); | ||
|
||
useEffect(() => { | ||
carouselRef.current?.next(); | ||
}, [width]); | ||
|
||
return ( | ||
<Section topRightChild={topRightChild}> | ||
{/*TODO: Async fetchMore for these data ?*/} | ||
|
||
<Carousel | ||
width={width} | ||
data={news || []} | ||
ref={carouselRef} | ||
onConfigurePanGesture={(g) => g.enableTrackpadTwoFingerGesture(true)} | ||
height={650} | ||
pagingEnabled | ||
loop | ||
autoPlay | ||
autoPlayInterval={3000} | ||
renderItem={renderItem} | ||
/> | ||
<FullWidthSeparator /> | ||
</Section> | ||
); | ||
}; | ||
|
||
|
||
export const TopMenuHighlightedNews: React.FC = () => { | ||
const networkId = useSelectedNetworkId(); | ||
return ( | ||
<TopMenuSection title="Highlighted News"> | ||
<FlexCol> | ||
<Link to={banner?.url || ""}> | ||
<PrimaryBox> | ||
<Image | ||
source={{ | ||
uri: web3ToWeb2URI(banner?.image), | ||
}} | ||
style={{ | ||
height: 94, | ||
width: 298, | ||
borderRadius: 7, | ||
}} | ||
/> | ||
</PrimaryBox> | ||
</Link> | ||
</FlexCol> | ||
<SmallNewsCarouselSection/> | ||
</TopMenuSection> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters