-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DIA-135): add captions and navigation on artworks inside articles (
#9416) feat: add captions and navigation of artworks inside articles
- Loading branch information
1 parent
0e9b4cd
commit 9d22c14
Showing
8 changed files
with
272 additions
and
13 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...rticle/Components/Sections/ArticleSectionImageCollection/ArticleSectionArtworkCaption.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,81 @@ | ||
import { Flex, Text, Touchable } from "@artsy/palette-mobile" | ||
import { ArticleSectionArtworkCaption_artwork$key } from "__generated__/ArticleSectionArtworkCaption_artwork.graphql" | ||
import { navigate } from "app/system/navigation/navigate" | ||
import { useFragment, graphql } from "react-relay" | ||
|
||
interface ArticleSectionArtworkCaptionProps { | ||
artwork: ArticleSectionArtworkCaption_artwork$key | ||
} | ||
|
||
export const ArticleSectionArtworkCaption: React.FC<ArticleSectionArtworkCaptionProps> = ({ | ||
artwork, | ||
}) => { | ||
const data = useFragment(fragment, artwork) | ||
|
||
if (!data) { | ||
return null | ||
} | ||
|
||
const handleOnNavigate = (href: string | null = null) => { | ||
if (href) { | ||
navigate(href) | ||
} | ||
} | ||
|
||
return ( | ||
<Flex px={2} py={1}> | ||
{data.artists?.map((artist, i) => { | ||
if (!artist || !artist.href || !artist.name) return null | ||
|
||
return ( | ||
<Touchable key={i} onPress={() => handleOnNavigate(artist.href)}> | ||
<Text variant="sm-display"> | ||
{artist.name} | ||
{i !== data.artists!.length - 1 && ", "} | ||
</Text> | ||
</Touchable> | ||
) | ||
})} | ||
|
||
<Touchable onPress={() => handleOnNavigate(data.href)}> | ||
<Text variant="sm-display" color="black60"> | ||
<Text variant="sm-display" color="black60" italic> | ||
{data.title} | ||
</Text> | ||
{!!data.date && `, ${data.date}`} | ||
</Text> | ||
</Touchable> | ||
|
||
<Touchable onPress={() => handleOnNavigate(data.partner?.href)}> | ||
<Text variant="xs" color="black60"> | ||
{data.partner?.name} | ||
</Text> | ||
</Touchable> | ||
|
||
{!!data.saleMessage && ( | ||
<Text variant="xs" weight="medium"> | ||
{data.saleMessage} | ||
</Text> | ||
)} | ||
</Flex> | ||
) | ||
} | ||
|
||
const fragment = graphql` | ||
fragment ArticleSectionArtworkCaption_artwork on Artwork { | ||
internalID | ||
href | ||
title | ||
date | ||
saleMessage | ||
artists(shallow: true) { | ||
id | ||
href | ||
name | ||
} | ||
partner { | ||
name | ||
href | ||
} | ||
} | ||
` |
54 changes: 54 additions & 0 deletions
54
.../Article/Components/Sections/ArticleSectionImageCollection/ArticleSectionArtworkImage.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,54 @@ | ||
import { Image, Touchable, useScreenDimensions } from "@artsy/palette-mobile" | ||
import { ArticleSectionArtworkImage_artwork$key } from "__generated__/ArticleSectionArtworkImage_artwork.graphql" | ||
import { navigate } from "app/system/navigation/navigate" | ||
import { useFragment, graphql } from "react-relay" | ||
|
||
interface ArticleSectionArtworkImageProps { | ||
artwork: ArticleSectionArtworkImage_artwork$key | ||
} | ||
|
||
export const ArticleSectionArtworkImage: React.FC<ArticleSectionArtworkImageProps> = ({ | ||
artwork, | ||
}) => { | ||
const { width } = useScreenDimensions() | ||
const data = useFragment(fragment, artwork) | ||
|
||
if (!data.image?.url) { | ||
return null | ||
} | ||
|
||
const handleOnPress = () => { | ||
if (!!data.href) { | ||
navigate(data.href) | ||
} | ||
} | ||
|
||
const widthShrinkPercentage = width / (data.image?.width ?? width) | ||
const height = (data.image?.height ?? width) * widthShrinkPercentage | ||
const aspectRatio = width / height | ||
|
||
return ( | ||
<Touchable onPress={handleOnPress}> | ||
<Image | ||
accessibilityLabel={`Image of ${data.title}`} | ||
src={data.image.url} | ||
width={width} | ||
height={height} | ||
aspectRatio={aspectRatio} | ||
/> | ||
</Touchable> | ||
) | ||
} | ||
|
||
const fragment = graphql` | ||
fragment ArticleSectionArtworkImage_artwork on Artwork { | ||
id | ||
href | ||
title | ||
image { | ||
url(version: ["main", "normalized", "larger", "large"]) | ||
width | ||
height | ||
} | ||
} | ||
` |
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
55 changes: 55 additions & 0 deletions
55
...s/Sections/ArticleSectionImageCollection/__tests__/ArticleSectionArtworkCaption.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,55 @@ | ||
import { fireEvent, screen } from "@testing-library/react-native" | ||
import { ArticleSectionArtworkCaptionTestQuery } from "__generated__/ArticleSectionArtworkCaptionTestQuery.graphql" | ||
import { ArticleSectionArtworkCaption } from "app/Scenes/Article/Components/Sections/ArticleSectionImageCollection/ArticleSectionArtworkCaption" | ||
import { navigate } from "app/system/navigation/navigate" | ||
import { setupTestWrapper } from "app/utils/tests/setupTestWrapper" | ||
import { graphql } from "react-relay" | ||
|
||
describe("ArticleSectionArtworkCaption", () => { | ||
const { renderWithRelay } = setupTestWrapper<ArticleSectionArtworkCaptionTestQuery>({ | ||
Component: ({ artwork }) => { | ||
return <ArticleSectionArtworkCaption artwork={artwork!} /> | ||
}, | ||
query: graphql` | ||
query ArticleSectionArtworkCaptionTestQuery @relay_test_operation { | ||
artwork(id: "test-id") { | ||
...ArticleSectionArtworkCaption_artwork | ||
} | ||
} | ||
`, | ||
}) | ||
|
||
it("renders", async () => { | ||
renderWithRelay({ Artwork: () => artwork }) | ||
|
||
expect(screen.getByText("Test Artwork, 2023")).toBeOnTheScreen() | ||
expect(screen.getByText("Test Partner")).toBeOnTheScreen() | ||
expect(screen.getByText("Test Artist")).toBeOnTheScreen() | ||
expect(screen.getByText("Contact for price")).toBeOnTheScreen() | ||
}) | ||
|
||
it("navigates", async () => { | ||
renderWithRelay({ Artwork: () => artwork }) | ||
|
||
fireEvent.press(screen.getByText("Test Artwork, 2023")) | ||
expect(navigate).toHaveBeenCalledWith("artwork-href") | ||
|
||
fireEvent.press(screen.getByText("Test Partner")) | ||
expect(navigate).toHaveBeenCalledWith("partner-href") | ||
|
||
fireEvent.press(screen.getByText("Test Artist")) | ||
expect(navigate).toHaveBeenCalledWith("artist-href") | ||
}) | ||
}) | ||
|
||
const artwork = { | ||
title: "Test Artwork", | ||
href: "artwork-href", | ||
partner: { | ||
name: "Test Partner", | ||
href: "partner-href", | ||
}, | ||
date: "2023", | ||
artists: [{ name: "Test Artist", href: "artist-href" }], | ||
saleMessage: "Contact for price", | ||
} |
35 changes: 35 additions & 0 deletions
35
...nts/Sections/ArticleSectionImageCollection/__tests__/ArticleSectionArtworkImage.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,35 @@ | ||
import { fireEvent, screen } from "@testing-library/react-native" | ||
import { ArticleSectionArtworkImageTestQuery } from "__generated__/ArticleSectionArtworkImageTestQuery.graphql" | ||
import { ArticleSectionArtworkImage } from "app/Scenes/Article/Components/Sections/ArticleSectionImageCollection/ArticleSectionArtworkImage" | ||
import { navigate } from "app/system/navigation/navigate" | ||
import { setupTestWrapper } from "app/utils/tests/setupTestWrapper" | ||
import { graphql } from "react-relay" | ||
|
||
describe("ArticleSectionArtworkImage", () => { | ||
const { renderWithRelay } = setupTestWrapper<ArticleSectionArtworkImageTestQuery>({ | ||
Component: ({ artwork }) => { | ||
return <ArticleSectionArtworkImage artwork={artwork!} /> | ||
}, | ||
query: graphql` | ||
query ArticleSectionArtworkImageTestQuery @relay_test_operation { | ||
artwork(id: "test-id") { | ||
...ArticleSectionArtworkImage_artwork | ||
} | ||
} | ||
`, | ||
}) | ||
|
||
it("renders", async () => { | ||
renderWithRelay() | ||
|
||
expect(screen.getByLabelText(`Image of <mock-value-for-field-\"title\">`)).toBeOnTheScreen() | ||
}) | ||
|
||
it("navigates to the artwork", async () => { | ||
renderWithRelay() | ||
|
||
fireEvent.press(screen.getByLabelText(`Image of <mock-value-for-field-\"title\">`)) | ||
|
||
expect(navigate).toHaveBeenCalledWith(`<mock-value-for-field-\"href\">`) | ||
}) | ||
}) |
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