-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DIA-931): add collection artwork rails (#10989)
feat: add collection artwork rails
- Loading branch information
1 parent
55b06d9
commit 76af019
Showing
6 changed files
with
235 additions
and
15 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
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
127 changes: 127 additions & 0 deletions
127
src/app/Scenes/CollectionsByCategory/CollectionRail.tsx
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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { | ||
ArrowRightIcon, | ||
Flex, | ||
Skeleton, | ||
SkeletonText, | ||
Spacer, | ||
useScreenDimensions, | ||
} from "@artsy/palette-mobile" | ||
import { CollectionRailCollectionsByCategoryQuery } from "__generated__/CollectionRailCollectionsByCategoryQuery.graphql" | ||
import { CollectionRail_marketingCollection$key } from "__generated__/CollectionRail_marketingCollection.graphql" | ||
import { ArtworkRail, ArtworkRailPlaceholder } from "app/Components/ArtworkRail/ArtworkRail" | ||
import { SectionTitle } from "app/Components/SectionTitle" | ||
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" | ||
|
||
interface CollectionRailProps { | ||
collection: CollectionRail_marketingCollection$key | ||
} | ||
|
||
export const CollectionRail: FC<CollectionRailProps> = ({ collection: _collection }) => { | ||
const collection = useFragment(fragment, _collection) | ||
|
||
if (!collection || collection.artworksConnection?.counts.total === 0) { | ||
return null | ||
} | ||
|
||
const artworks = extractNodes(collection.artworksConnection) | ||
|
||
return ( | ||
<Flex> | ||
<SectionTitle | ||
title={collection.title} | ||
onPress={() => {}} | ||
RightButtonContent={() => <ArrowRightIcon />} | ||
/> | ||
<ArtworkRail artworks={artworks} ListHeaderComponent={null} /> | ||
</Flex> | ||
) | ||
} | ||
|
||
const fragment = graphql` | ||
fragment CollectionRail_marketingCollection on MarketingCollection { | ||
title @required(action: NONE) | ||
artworksConnection(first: 10) { | ||
counts @required(action: NONE) { | ||
total | ||
} | ||
edges { | ||
node { | ||
...ArtworkRail_artworks | ||
internalID | ||
slug | ||
href | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
export const CollectionRailPlaceholder: FC = () => { | ||
return ( | ||
<Skeleton> | ||
<Flex justifyContent="space-between" flexDirection="row"> | ||
<SkeletonText>Category title</SkeletonText> | ||
<ArrowRightIcon /> | ||
</Flex> | ||
|
||
<Spacer y={1} /> | ||
|
||
<Flex flexDirection="row"> | ||
<ArtworkRailPlaceholder /> | ||
</Flex> | ||
</Skeleton> | ||
) | ||
} | ||
|
||
const query = graphql` | ||
query CollectionRailCollectionsByCategoryQuery($slug: String!) { | ||
marketingCollection(slug: $slug) { | ||
...CollectionRail_marketingCollection | ||
title | ||
markdownDescription | ||
} | ||
} | ||
` | ||
|
||
interface CollectionRailWithSuspenseProps { | ||
slug: string | ||
} | ||
|
||
export const CollectionRailWithSuspense = withSuspense<CollectionRailWithSuspenseProps>({ | ||
Component: ({ slug }) => { | ||
const { height } = useScreenDimensions() | ||
const [isVisible, setIsVisible] = useState(false) | ||
const { data, loading } = useClientQuery<CollectionRailCollectionsByCategoryQuery>({ | ||
query, | ||
variables: { slug }, | ||
skip: !isVisible, | ||
}) | ||
|
||
const handleOnVisible = () => { | ||
if (!isVisible) { | ||
setIsVisible(true) | ||
} | ||
} | ||
|
||
if (loading || !data?.marketingCollection || !isVisible) { | ||
// We don't need to overfetch all rails at once, fetch as they become closer to be visible | ||
return ( | ||
<ElementInView onVisible={handleOnVisible} visibilityMargin={-height}> | ||
<CollectionRailPlaceholder /> | ||
</ElementInView> | ||
) | ||
} | ||
|
||
return <CollectionRail collection={data.marketingCollection} /> | ||
}, | ||
ErrorFallback: NoFallback, | ||
LoadingFallback: CollectionRailPlaceholder, | ||
}) |
39 changes: 39 additions & 0 deletions
39
src/app/Scenes/CollectionsByCategory/__tests__/Body.tests.tsx
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { screen } from "@testing-library/react-native" | ||
import { BodyHomeViewSectionCardsTestQuery } from "__generated__/BodyHomeViewSectionCardsTestQuery.graphql" | ||
import { Body } from "app/Scenes/CollectionsByCategory/Body" | ||
import { setupTestWrapper } from "app/utils/tests/setupTestWrapper" | ||
import { graphql } from "react-relay" | ||
|
||
jest.mock("@react-navigation/native", () => ({ | ||
useRoute: () => ({ | ||
params: { | ||
props: { category: "mock-category" }, | ||
}, | ||
}), | ||
})) | ||
|
||
jest.mock("app/Scenes/CollectionsByCategory/CollectionRail", () => ({ | ||
CollectionRailWithSuspense: () => null, | ||
CollectionRailPlaceholder: () => null, | ||
})) | ||
|
||
describe("Body", () => { | ||
const { renderWithRelay } = setupTestWrapper<BodyHomeViewSectionCardsTestQuery>({ | ||
Component: ({ marketingCollections }) => <Body marketingCollections={marketingCollections} />, | ||
query: graphql` | ||
query BodyHomeViewSectionCardsTestQuery { | ||
marketingCollections(category: "category", first: 20) @required(action: NONE) { | ||
...BodyCollectionsByCategory_marketingCollection | ||
...CollectionsChips_marketingCollections | ||
} | ||
} | ||
`, | ||
}) | ||
|
||
it("renders", () => { | ||
renderWithRelay() | ||
|
||
expect(screen.getByText(/Explore collections with mock-category/)).toBeOnTheScreen() | ||
expect(screen.getByText(/<mock-value-for-field-"title">/)).toBeOnTheScreen() | ||
}) | ||
}) |
29 changes: 29 additions & 0 deletions
29
src/app/Scenes/CollectionsByCategory/__tests__/CollectionRail.tests.tsx
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { screen } from "@testing-library/react-native" | ||
import { CollectionRailHomeViewSectionCardsTestQuery } from "__generated__/CollectionRailHomeViewSectionCardsTestQuery.graphql" | ||
import { CollectionRail } from "app/Scenes/CollectionsByCategory/CollectionRail" | ||
import { setupTestWrapper } from "app/utils/tests/setupTestWrapper" | ||
import { graphql } from "react-relay" | ||
|
||
jest.mock("app/Components/ArtworkRail/ArtworkRail", () => ({ | ||
ArtworkRail: () => null, | ||
ArtworkRailPlaceholder: () => null, | ||
})) | ||
|
||
describe("CollectionRail", () => { | ||
const { renderWithRelay } = setupTestWrapper<CollectionRailHomeViewSectionCardsTestQuery>({ | ||
Component: ({ marketingCollection }) => <CollectionRail collection={marketingCollection} />, | ||
query: graphql` | ||
query CollectionRailHomeViewSectionCardsTestQuery { | ||
marketingCollection(slug: "marketing-slug") @required(action: NONE) { | ||
...CollectionRail_marketingCollection | ||
} | ||
} | ||
`, | ||
}) | ||
|
||
it("renders", () => { | ||
renderWithRelay() | ||
|
||
expect(screen.getByText(/mock-Value-for-Field-"Title"/)).toBeOnTheScreen() | ||
}) | ||
}) |
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