diff --git a/src/app/Scenes/CollectionsByCategory/Body.tsx b/src/app/Scenes/CollectionsByCategory/Body.tsx index a2c8e6286d4..a08de1f4b57 100644 --- a/src/app/Scenes/CollectionsByCategory/Body.tsx +++ b/src/app/Scenes/CollectionsByCategory/Body.tsx @@ -1,8 +1,8 @@ -import { Flex, Skeleton, SkeletonText, Text, useSpace } from "@artsy/palette-mobile" +import { Flex, Separator, Skeleton, SkeletonText, Text, useSpace } from "@artsy/palette-mobile" import { useRoute } from "@react-navigation/native" +import { FlashList } from "@shopify/flash-list" import { BodyCollectionsByCategoryQuery } from "__generated__/BodyCollectionsByCategoryQuery.graphql" -import { BodyCollectionsByCategory_marketingCollection$key } from "__generated__/BodyCollectionsByCategory_marketingCollection.graphql" -import { CollectionsChips_marketingCollections$key } from "__generated__/CollectionsChips_marketingCollections.graphql" +import { BodyCollectionsByCategory_viewer$key } from "__generated__/BodyCollectionsByCategory_viewer.graphql" import { CollectionRailPlaceholder, CollectionRailWithSuspense, @@ -16,41 +16,53 @@ import { NoFallback, withSuspense } from "app/utils/hooks/withSuspense" import { graphql, useLazyLoadQuery, useFragment } from "react-relay" interface BodyProps { - marketingCollections: BodyCollectionsByCategory_marketingCollection$key & - CollectionsChips_marketingCollections$key + viewer: BodyCollectionsByCategory_viewer$key } -export const Body: React.FC = ({ marketingCollections: _marketingCollections }) => { +export const Body: React.FC = ({ viewer }) => { const space = useSpace() - const marketingCollections = useFragment(fragment, _marketingCollections) + const data = useFragment(fragment, viewer) const { params } = useRoute() const category = params.props.category - if (!marketingCollections) { + if (!data?.marketingCollections) { return null } return ( - - {category} - - + + + {category} Explore collections with {category} - + {/* TODO: fix typings broken by some unknown reason here, prob related to @plural */} + - {marketingCollections.map((collection) => { - const slug = collection?.slug ?? "" - return - })} + + + `artwork_rail_${item?.slug}`} + renderItem={({ item }) => { + return + }} + ItemSeparatorComponent={() => } + /> ) } +const ESTIMATED_ITEM_SIZE = 390 + const fragment = graphql` - fragment BodyCollectionsByCategory_marketingCollection on MarketingCollection - @relay(plural: true) { - slug @required(action: NONE) + fragment BodyCollectionsByCategory_viewer on Viewer + @argumentDefinitions(category: { type: "String" }) { + marketingCollections(category: $category, first: 20) { + ...CollectionsChips_marketingCollections + + slug @required(action: NONE) + } } ` @@ -59,15 +71,17 @@ const BodyPlaceholder: React.FC = () => { return ( - - Category + + + Category - Category description text + + @@ -75,10 +89,9 @@ const BodyPlaceholder: React.FC = () => { } const query = graphql` - query BodyCollectionsByCategoryQuery($category: String!) { - marketingCollections(category: $category, first: 20) { - ...BodyCollectionsByCategory_marketingCollection - ...CollectionsChips_marketingCollections + query BodyCollectionsByCategoryQuery($category: String!) @cacheable { + viewer { + ...BodyCollectionsByCategory_viewer @arguments(category: $category) } } ` @@ -86,15 +99,19 @@ const query = graphql` export const BodyWithSuspense = withSuspense({ Component: () => { const { params } = useRoute() - const data = useLazyLoadQuery(query, { - category: params.props.entityID, - }) - - if (!data.marketingCollections) { + const data = useLazyLoadQuery( + query, + { + category: params.props.entityID, + }, + { fetchPolicy: "store-and-network" } + ) + + if (!data.viewer) { return } - return + return }, LoadingFallback: BodyPlaceholder, ErrorFallback: NoFallback, diff --git a/src/app/Scenes/CollectionsByCategory/CollectionRail.tsx b/src/app/Scenes/CollectionsByCategory/CollectionRail.tsx index ce0539450f8..43433d88704 100644 --- a/src/app/Scenes/CollectionsByCategory/CollectionRail.tsx +++ b/src/app/Scenes/CollectionsByCategory/CollectionRail.tsx @@ -1,6 +1,7 @@ import { ArrowRightIcon, Flex, + Separator, Skeleton, SkeletonText, Spacer, @@ -10,12 +11,12 @@ import { CollectionRailCollectionsByCategoryQuery } from "__generated__/Collecti import { CollectionRail_marketingCollection$key } from "__generated__/CollectionRail_marketingCollection.graphql" import { ArtworkRail, ArtworkRailPlaceholder } from "app/Components/ArtworkRail/ArtworkRail" import { SectionTitle } from "app/Components/SectionTitle" +import { navigate } from "app/system/navigation/navigate" import { ElementInView } from "app/utils/ElementInView" import { extractNodes } from "app/utils/extractNodes" import { withSuspense, NoFallback } from "app/utils/hooks/withSuspense" -import { useClientQuery } from "app/utils/useClientQuery" import { FC, useState } from "react" -import { graphql, useFragment } from "react-relay" +import { graphql, useFragment, useLazyLoadQuery } from "react-relay" interface CollectionRailProps { collection: CollectionRail_marketingCollection$key @@ -31,13 +32,21 @@ export const CollectionRail: FC = ({ collection: _collectio const artworks = extractNodes(collection.artworksConnection) return ( - - {}} - RightButtonContent={() => } + + + navigate(`/collection/${collection.slug}`)} + /> + + navigate(artwork.href ?? "")} + artworks={artworks} + ListHeaderComponent={null} + showSaveIcon + showPartnerName /> - ) } @@ -45,6 +54,7 @@ export const CollectionRail: FC = ({ collection: _collectio const fragment = graphql` fragment CollectionRail_marketingCollection on MarketingCollection { title @required(action: NONE) + slug @required(action: NONE) artworksConnection(first: 10) { counts @required(action: NONE) { @@ -66,23 +76,26 @@ const fragment = graphql` export const CollectionRailPlaceholder: FC = () => { return ( - - Category title - - - - - - - + + + Category title + + + + + + + + + ) } const query = graphql` - query CollectionRailCollectionsByCategoryQuery($slug: String!) { - marketingCollection(slug: $slug) { + query CollectionRailCollectionsByCategoryQuery($slug: String!, $isVisible: Boolean!) { + marketingCollection(slug: $slug) @include(if: $isVisible) { ...CollectionRail_marketingCollection title @@ -99,10 +112,9 @@ export const CollectionRailWithSuspense = withSuspense { const { height } = useScreenDimensions() const [isVisible, setIsVisible] = useState(false) - const { data, loading } = useClientQuery({ - query, - variables: { slug }, - skip: !isVisible, + const data = useLazyLoadQuery(query, { + slug, + isVisible, }) const handleOnVisible = () => { @@ -111,7 +123,7 @@ export const CollectionRailWithSuspense = withSuspense diff --git a/src/app/Scenes/CollectionsByCategory/__tests__/Body.tests.tsx b/src/app/Scenes/CollectionsByCategory/__tests__/Body.tests.tsx index 499d00ed329..4fb1f2dedbc 100644 --- a/src/app/Scenes/CollectionsByCategory/__tests__/Body.tests.tsx +++ b/src/app/Scenes/CollectionsByCategory/__tests__/Body.tests.tsx @@ -19,12 +19,11 @@ jest.mock("app/Scenes/CollectionsByCategory/CollectionRail", () => ({ describe("Body", () => { const { renderWithRelay } = setupTestWrapper({ - Component: ({ marketingCollections }) => , + Component: Body, query: graphql` query BodyHomeViewSectionCardsTestQuery { - marketingCollections(category: "category", first: 20) @required(action: NONE) { - ...BodyCollectionsByCategory_marketingCollection - ...CollectionsChips_marketingCollections + viewer @required(action: NONE) { + ...BodyCollectionsByCategory_viewer @arguments(category: "category") } } `, diff --git a/src/app/Scenes/HomeView/Sections/HomeViewSectionCards.tsx b/src/app/Scenes/HomeView/Sections/HomeViewSectionCards.tsx index fec9619161e..8e7860bec91 100644 --- a/src/app/Scenes/HomeView/Sections/HomeViewSectionCards.tsx +++ b/src/app/Scenes/HomeView/Sections/HomeViewSectionCards.tsx @@ -16,10 +16,9 @@ import { navigate } from "app/system/navigation/navigate" import { extractNodes } from "app/utils/extractNodes" import { useFeatureFlag } from "app/utils/hooks/useFeatureFlag" import { NoFallback, withSuspense } from "app/utils/hooks/withSuspense" -import { useClientQuery } from "app/utils/useClientQuery" import React from "react" import { isTablet } from "react-native-device-info" -import { graphql, useFragment } from "react-relay" +import { graphql, useFragment, useLazyLoadQuery } from "react-relay" interface HomeViewSectionCardsProps { section: HomeViewSectionCards_section$key @@ -107,9 +106,9 @@ const fragment = graphql` ` const query = graphql` - query HomeViewSectionCardsQuery($id: String!) { + query HomeViewSectionCardsQuery($id: String!, $isEnabled: Boolean!) { homeView { - section(id: $id) { + section(id: $id) @include(if: $isEnabled) { ...HomeViewSectionCards_section } } @@ -147,11 +146,7 @@ export const HomeViewSectionCardsQueryRenderer = withSuspense< >({ Component: ({ sectionID }) => { const isEnabled = useFeatureFlag("AREnableMarketingCollectionsCategories") - const { data } = useClientQuery({ - query, - variables: { id: sectionID }, - skip: !isEnabled, - }) + const data = useLazyLoadQuery(query, { id: sectionID, isEnabled }) if (!data?.homeView.section || !isEnabled) { return null diff --git a/src/app/Scenes/HomeView/Sections/HomeViewSectionCardsChips.tsx b/src/app/Scenes/HomeView/Sections/HomeViewSectionCardsChips.tsx index 12bcae83bac..571f78b8248 100644 --- a/src/app/Scenes/HomeView/Sections/HomeViewSectionCardsChips.tsx +++ b/src/app/Scenes/HomeView/Sections/HomeViewSectionCardsChips.tsx @@ -7,10 +7,9 @@ import { navigate } from "app/system/navigation/navigate" import { extractNodes } from "app/utils/extractNodes" import { useFeatureFlag } from "app/utils/hooks/useFeatureFlag" import { NoFallback, withSuspense } from "app/utils/hooks/withSuspense" -import { useClientQuery } from "app/utils/useClientQuery" import { FlatList, ScrollView } from "react-native" import { isTablet } from "react-native-device-info" -import { graphql, useFragment } from "react-relay" +import { graphql, useFragment, useLazyLoadQuery } from "react-relay" interface HomeViewSectionCardsChipsProps { section: HomeViewSectionCardsChips_section$key @@ -132,9 +131,9 @@ const HomeViewSectionCardsChipsPlaceholder: React.FC = () => { } const query = graphql` - query HomeViewSectionCardsChipsQuery($id: String!) { + query HomeViewSectionCardsChipsQuery($id: String!, $isEnabled: Boolean!) { homeView { - section(id: $id) { + section(id: $id) @include(if: $isEnabled) { ...HomeViewSectionCardsChips_section } } @@ -144,10 +143,9 @@ const query = graphql` export const HomeViewSectionCardsChipsQueryRenderer: React.FC = withSuspense({ Component: ({ sectionID, index, ...flexProps }) => { const isEnabled = useFeatureFlag("AREnableMarketingCollectionsCategories") - const { data } = useClientQuery({ - query, - variables: { id: sectionID }, - skip: !isEnabled, + const data = useLazyLoadQuery(query, { + id: sectionID, + isEnabled, }) if (!data?.homeView.section || !isEnabled) {