From 8c0dcd34ed8cabf50a9328bfd63db052b9de0248 Mon Sep 17 00:00:00 2001 From: Adam Iskounen Date: Thu, 19 Dec 2024 13:33:52 -0500 Subject: [PATCH] loaded artworks from the curator's pick collection --- .../InfiniteDiscovery/InfiniteDiscovery.tsx | 78 ++++++++++++++++--- .../InfiniteDiscoveryContext.ts | 27 +++---- 2 files changed, 80 insertions(+), 25 deletions(-) diff --git a/src/app/Scenes/InfiniteDiscovery/InfiniteDiscovery.tsx b/src/app/Scenes/InfiniteDiscovery/InfiniteDiscovery.tsx index 9749b8658c4..bfb04f8a381 100644 --- a/src/app/Scenes/InfiniteDiscovery/InfiniteDiscovery.tsx +++ b/src/app/Scenes/InfiniteDiscovery/InfiniteDiscovery.tsx @@ -1,4 +1,5 @@ import { + Avatar, Button, Flex, Image, @@ -8,10 +9,13 @@ import { useScreenDimensions, useTheme, } from "@artsy/palette-mobile" +import { InfiniteDiscoveryQuery } from "__generated__/InfiniteDiscoveryQuery.graphql" import { FancySwiper } from "app/Components/FancySwiper/FancySwiper" import { Card } from "app/Components/FancySwiper/FancySwiperCard" import { InfiniteDiscoveryContext } from "app/Scenes/InfiniteDiscovery/InfiniteDiscoveryContext" import { navigate } from "app/system/navigation/navigate" +import { useEffect } from "react" +import { graphql, useLazyLoadQuery } from "react-relay" export const InfiniteDiscoveryView: React.FC = () => { return ( @@ -25,16 +29,26 @@ export const InfiniteDiscovery: React.FC = () => { const { color } = useTheme() const { width: screenWidth } = useScreenDimensions() + const data = useLazyLoadQuery(infiniteDiscoveryQuery, {}) + const artworks = InfiniteDiscoveryContext.useStoreState((state) => state.artworks) - const currentArtwork = InfiniteDiscoveryContext.useStoreState((state) => state.currentArtwork) + const currentArtworkIndex = InfiniteDiscoveryContext.useStoreState( + (state) => state.currentArtworkIndex + ) const goToPreviousArtwork = InfiniteDiscoveryContext.useStoreActions( (action) => action.goToPreviousArtwork ) const goToNextArtwork = InfiniteDiscoveryContext.useStoreActions( (actions) => actions.goToNextArtwork ) + const setArtworks = InfiniteDiscoveryContext.useStoreActions((actions) => actions.setArtworks) + + useEffect(() => { + setArtworks( + (data.marketingCollection?.artworksConnection?.edges?.map((edge) => edge?.node) as any) || [] + ) + }, [data]) - const currentArtworkIndex = artworks.indexOf(currentArtwork) const canGoBack = currentArtworkIndex > 0 const handleBackPressed = () => { @@ -58,33 +72,41 @@ export const InfiniteDiscovery: React.FC = () => { jsx: ( - Artist Name + + + + {artwork.artistNames} + + {artwork.artists[0].formattedNationalityAndBirthday} + + + - + - Artwork Title, + {artwork.title} - 2024 + , {artwork.date} - $1,234 + {artwork.saleMessage} ), - id: artwork, + id: artwork.internalID, } }) @@ -117,3 +139,35 @@ export const InfiniteDiscovery: React.FC = () => { ) } + +const infiniteDiscoveryQuery = graphql` + query InfiniteDiscoveryQuery { + marketingCollection(slug: "curators-picks") { + artworksConnection(first: 10) { + edges { + node { + artistNames + artists(shallow: true) { + initials + formattedNationalityAndBirthday + coverArtwork { + image { + cropped(height: 45, width: 45) { + url + } + } + } + } + date + internalID + images { + url(version: "large") + } + saleMessage + title + } + } + } + } + } +` diff --git a/src/app/Scenes/InfiniteDiscovery/InfiniteDiscoveryContext.ts b/src/app/Scenes/InfiniteDiscovery/InfiniteDiscoveryContext.ts index a9e02591847..2963781decf 100644 --- a/src/app/Scenes/InfiniteDiscovery/InfiniteDiscoveryContext.ts +++ b/src/app/Scenes/InfiniteDiscovery/InfiniteDiscoveryContext.ts @@ -1,27 +1,28 @@ -import { Color } from "@artsy/palette-mobile" import { action, Action, createContextStore } from "easy-peasy" export interface InfiniteDiscoveryContextModel { - artworks: Color[] - currentArtwork: Color + artworks: any[] + currentArtworkIndex: number goToPreviousArtwork: Action goToNextArtwork: Action + setArtworks: Action } export const initialModel: InfiniteDiscoveryContextModel = { - artworks: ["red100", "green100", "blue100"], - currentArtwork: "red100", + artworks: [], + currentArtworkIndex: 0, goToPreviousArtwork: action((state) => { - const currentIndex = state.artworks.indexOf(state.currentArtwork) - if (currentIndex - 1 < 0) return - const previousIndex = currentIndex - 1 - state.currentArtwork = state.artworks[previousIndex] + if (state.currentArtworkIndex > 0) { + state.currentArtworkIndex-- + } }), goToNextArtwork: action((state) => { - const currentIndex = state.artworks.indexOf(state.currentArtwork) - if (currentIndex + 1 === state.artworks.length) return - const nextIndex = currentIndex + 1 - state.currentArtwork = state.artworks[nextIndex] + if (state.currentArtworkIndex < state.artworks.length - 1) { + state.currentArtworkIndex++ + } + }), + setArtworks: action((state, artworks) => { + state.artworks = artworks }), }