Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Prefetch links on Artwork screen #11650

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/Components/ArtistListItem.tests.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Touchable } from "@artsy/palette-mobile"
import { ArtistListItemTestsQuery } from "__generated__/ArtistListItemTestsQuery.graphql"
import { RouterLink } from "app/system/navigation/RouterLink"
import { renderWithWrappers, renderWithWrappersLEGACY } from "app/utils/tests/renderWithWrappers"
import { resolveMostRecentRelayOperation } from "app/utils/tests/resolveMostRecentRelayOperation"
import { graphql, QueryRenderer } from "react-relay"
Expand Down Expand Up @@ -45,13 +45,13 @@ describe("ArtistListItem", () => {
it("renders without feedback without throwing an error", () => {
const tree = renderWithWrappersLEGACY(<TestRenderer />).root
resolveMostRecentRelayOperation(mockEnvironment)
expect(tree.findByType(Touchable).props.noFeedback).toBe(true)
expect(tree.findByType(RouterLink).props.noFeedback).toBe(true)
})

it("renders with feedback without throwing an error", () => {
const tree = renderWithWrappersLEGACY(<TestRenderer withFeedback />).root
resolveMostRecentRelayOperation(mockEnvironment)
expect(tree.findByType(Touchable).props.noFeedback).toBe(false)
expect(tree.findByType(RouterLink).props.noFeedback).toBe(false)
})

it("shows uploaded artworks counts when specified", () => {
Expand Down
28 changes: 9 additions & 19 deletions src/app/Components/ArtistListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {
AvatarSize,
EntityHeader,
Flex,
FollowButton,
Text,
Touchable,
useColor,
} from "@artsy/palette-mobile"
import { AvatarSize, EntityHeader, Flex, FollowButton, Text, useColor } from "@artsy/palette-mobile"
import { ArtistListItemFollowArtistMutation } from "__generated__/ArtistListItemFollowArtistMutation.graphql"
import { ArtistListItem_artist$data } from "__generated__/ArtistListItem_artist.graphql"
import { navigate } from "app/system/navigation/navigate"
import { RouterLink } from "app/system/navigation/RouterLink"
import { PlaceholderBox, PlaceholderText } from "app/utils/placeholders"
import { pluralize } from "app/utils/pluralize"
import { Schema } from "app/utils/track"
Expand Down Expand Up @@ -107,11 +99,6 @@ const ArtistListItem: React.FC<Props> = ({
)
}

const handleTap = (href: string) => {
tracks.tapArtistGroup(artist)
navigate(href)
}

let meta

if (includeTombstone) {
Expand Down Expand Up @@ -155,23 +142,26 @@ const ArtistListItem: React.FC<Props> = ({
return null
}

const navigateOnPress = !disableNavigation && !onPress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took me some time to understand this. I wonder if a comment could be helpful here


return (
<Touchable
<RouterLink
noFeedback={!withFeedback}
to={navigateOnPress ? href : undefined}
onPress={() => {
if (onPress) {
onPress()
return
}

if (href && !disableNavigation) {
handleTap(href)
tracks.tapArtistGroup(artist)
}
}}
underlayColor={color("black5")}
style={containerStyle}
>
<Flex flexDirection="row" justifyContent="space-between" alignItems="center">
<Flex flexDirection="row" justifyContent="space-between" alignItems="center" width="100%">
<Flex flex={1}>
<EntityHeader
mr={1}
Expand All @@ -191,7 +181,7 @@ const ArtistListItem: React.FC<Props> = ({
</Flex>
)}
</Flex>
</Touchable>
</RouterLink>
)
}

Expand Down
21 changes: 17 additions & 4 deletions src/app/Navigation/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,25 @@ import {
defaultArtistVariables,
} from "app/Scenes/Artist/Artist"
import { ArtistArticlesQueryRenderer } from "app/Scenes/ArtistArticles/ArtistArticles"
import { ArtistSeriesQueryRenderer } from "app/Scenes/ArtistSeries/ArtistSeries"
import { ArtistSeriesFullArtistSeriesListQueryRenderer } from "app/Scenes/ArtistSeries/ArtistSeriesFullArtistSeriesList"
import {
ArtistSeriesQueryRenderer,
ArtistSeriesScreenQuery,
} from "app/Scenes/ArtistSeries/ArtistSeries"
import {
ArtistSeriesFullArtistSeriesListQueryRenderer,
ArtistSeriesFullArtistSeriesListScreenQuery,
} from "app/Scenes/ArtistSeries/ArtistSeriesFullArtistSeriesList"
import { ArtistShows2QueryRenderer } from "app/Scenes/ArtistShows/ArtistShows2"
import { ArtworkScreen, ArtworkScreenQuery } from "app/Scenes/Artwork/Artwork"
import { BrowseSimilarWorksQueryRenderer } from "app/Scenes/Artwork/Components/BrowseSimilarWorks/BrowseSimilarWorks"
import { CertificateOfAuthenticity } from "app/Scenes/Artwork/Components/CertificateAuthenticity"
import { UnlistedArtworksFAQScreen } from "app/Scenes/Artwork/Components/UnlistedArtworksFAQScreen"
import { ArtworkAttributionClassFAQQueryRenderer } from "app/Scenes/ArtworkAttributionClassFAQ/ArtworkAttributionClassFAQ"
import { ArtworkListScreen } from "app/Scenes/ArtworkList/ArtworkList"
import { ArtworkMediumQueryRenderer } from "app/Scenes/ArtworkMedium/ArtworkMedium"
import {
ARTWORK_MEDIUM_QUERY,
ArtworkMediumQueryRenderer,
} from "app/Scenes/ArtworkMedium/ArtworkMedium"
import { ArtworkRecommendationsScreen } from "app/Scenes/ArtworkRecommendations/ArtworkRecommendations"
import { AuctionBuyersPremiumQueryRenderer } from "app/Scenes/AuctionBuyersPremium/AuctionBuyersPremium"
import { AuctionResultQueryRenderer } from "app/Scenes/AuctionResult/AuctionResult"
Expand Down Expand Up @@ -113,7 +122,7 @@ import { NewWorksForYouQueryRenderer } from "app/Scenes/NewWorksForYou/NewWorksF
import { NewWorksFromGalleriesYouFollowScreen } from "app/Scenes/NewWorksFromGalleriesYouFollow/NewWorksFromGalleriesYouFollow"
import { OrderDetailsQueryRender } from "app/Scenes/OrderHistory/OrderDetails/Components/OrderDetails"
import { OrderHistoryQueryRender } from "app/Scenes/OrderHistory/OrderHistory"
import { PartnerQueryRenderer } from "app/Scenes/Partner/Partner"
import { PartnerQueryRenderer, PartnerScreenQuery } from "app/Scenes/Partner/Partner"
import { PartnerLocationsQueryRenderer } from "app/Scenes/Partner/Screens/PartnerLocations"
import { PartnerOfferContainer } from "app/Scenes/PartnerOffer/PartnerOfferContainer"
import { PriceDatabase } from "app/Scenes/PriceDatabase/PriceDatabase"
Expand Down Expand Up @@ -340,6 +349,7 @@ export const artsyDotNetRoutes = defineRoutes([
headerShown: false,
},
},
queries: [ArtistSeriesScreenQuery],
},
{
path: "/artist/:artistID",
Expand Down Expand Up @@ -372,6 +382,7 @@ export const artsyDotNetRoutes = defineRoutes([
headerTitle: "Artist Series",
},
},
queries: [ArtistSeriesFullArtistSeriesListScreenQuery],
},
{
path: "/artist/:artistID/auction-result/:auctionResultInternalID",
Expand Down Expand Up @@ -496,6 +507,7 @@ export const artsyDotNetRoutes = defineRoutes([
path: "/artwork/:artworkID/medium",
name: "ArtworkMedium",
Component: ArtworkMediumQueryRenderer,
queries: [ARTWORK_MEDIUM_QUERY],
},
{
path: "/artwork/:artworkID/browse-similar-works",
Expand Down Expand Up @@ -1169,6 +1181,7 @@ export const artsyDotNetRoutes = defineRoutes([
headerShown: false,
},
},
queries: [PartnerScreenQuery],
},
{
path: "/partner/:partnerID/artists/:artistID",
Expand Down
26 changes: 14 additions & 12 deletions src/app/Scenes/ArtistSeries/ArtistSeries.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
Spacer,
Flex,
Screen,
Tabs,
useScreenDimensions,
Separator,
Skeleton,
SkeletonBox,
Flex,
SkeletonText,
Separator,
Spacer,
Tabs,
useScreenDimensions,
} from "@artsy/palette-mobile"
import { ArtistSeriesQuery } from "__generated__/ArtistSeriesQuery.graphql"
import { ArtistSeries_artistSeries$key } from "__generated__/ArtistSeries_artistSeries.graphql"
Expand Down Expand Up @@ -134,13 +134,7 @@ export const ArtistSeriesQueryRenderer: React.FC<{ artistSeriesID: string }> = (
<ArtworkFiltersStoreProvider>
<QueryRenderer<ArtistSeriesQuery>
environment={getRelayEnvironment()}
query={graphql`
query ArtistSeriesQuery($artistSeriesID: ID!) {
artistSeries(id: $artistSeriesID) {
...ArtistSeries_artistSeries
}
}
`}
query={ArtistSeriesScreenQuery}
cacheConfig={{ force: true }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olerichter00 I've noticed that here you do not remove force: true, but in ArtistSeriesFullArtistSeriesList.tsx you do. Is it intentional?

variables={{
artistSeriesID,
Expand All @@ -153,3 +147,11 @@ export const ArtistSeriesQueryRenderer: React.FC<{ artistSeriesID: string }> = (
</ArtworkFiltersStoreProvider>
)
}

export const ArtistSeriesScreenQuery = graphql`
query ArtistSeriesQuery($artistSeriesID: ID!) {
artistSeries(id: $artistSeriesID) {
...ArtistSeries_artistSeries
}
}
`
17 changes: 9 additions & 8 deletions src/app/Scenes/ArtistSeries/ArtistSeriesFullArtistSeriesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,21 @@ export const ArtistSeriesFullArtistSeriesListFragmentContainer = createFragmentC
}
)

export const ArtistSeriesFullArtistSeriesListScreenQuery = graphql`
query ArtistSeriesFullArtistSeriesListQuery($artistID: String!) {
artist(id: $artistID) {
...ArtistSeriesFullArtistSeriesList_artist
}
}
`

export const ArtistSeriesFullArtistSeriesListQueryRenderer: React.FC<{ artistID: string }> = ({
artistID,
}) => {
return (
<QueryRenderer<ArtistSeriesFullArtistSeriesListQuery>
environment={getRelayEnvironment()}
query={graphql`
query ArtistSeriesFullArtistSeriesListQuery($artistID: String!) {
artist(id: $artistID) {
...ArtistSeriesFullArtistSeriesList_artist
}
}
`}
cacheConfig={{ force: true }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we had this force: true here before

query={ArtistSeriesFullArtistSeriesListScreenQuery}
variables={{
artistID,
}}
Expand Down
9 changes: 4 additions & 5 deletions src/app/Scenes/ArtistSeries/ArtistSeriesMoreSeries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { ActionType, ContextModule, OwnerType, ScreenOwnerType } from "@artsy/co
import { Flex, FlexProps, Text, TextProps } from "@artsy/palette-mobile"
import { ArtistSeriesMoreSeries_artist$data } from "__generated__/ArtistSeriesMoreSeries_artist.graphql"
import { ArtistSeriesListItem } from "app/Scenes/ArtistSeries/ArtistSeriesListItem"
import { navigate } from "app/system/navigation/navigate"
import { RouterLink } from "app/system/navigation/RouterLink"
import React, { useEffect, useState } from "react"
import { TouchableOpacity } from "react-native"
import { createFragmentContainer, graphql } from "react-relay"
import { useTracking } from "react-tracking"

Expand Down Expand Up @@ -59,16 +58,16 @@ export const ArtistSeriesMoreSeries: React.FC<ArtistSeriesMoreSeriesProps> = ({
{artistSeriesHeader}
</Text>
{totalCount > 4 && (
<TouchableOpacity
<RouterLink
to={`/artist/${artist?.internalID}/artist-series`}
onPress={() => {
if (artist.internalID) {
trackEvent(tracks.tapViewAllArtistSeries(artist?.internalID, artist?.slug))
navigate(`/artist/${artist?.internalID}/artist-series`)
}
}}
>
<Text variant="xs" underline testID="viewAll">{`View All (${totalCount})`}</Text>
</TouchableOpacity>
</RouterLink>
)}
</Flex>
{artistSeries.map((item, index) => {
Expand Down
9 changes: 4 additions & 5 deletions src/app/Scenes/Artwork/Components/ArtworkDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Spacer, Flex, Box, Text, Join } from "@artsy/palette-mobile"
import { Box, Flex, Join, Spacer, Text } from "@artsy/palette-mobile"
import { ArtworkDetails_artwork$key } from "__generated__/ArtworkDetails_artwork.graphql"
import { navigate } from "app/system/navigation/navigate"
import { RouterLink } from "app/system/navigation/RouterLink"
import { Schema } from "app/utils/track"
import React from "react"
import { TouchableWithoutFeedback } from "react-native"
import { graphql, useFragment } from "react-relay"
import { useTracking } from "react-tracking"
import { ArtworkDetailsRow } from "./ArtworkDetailsRow"
Expand All @@ -27,11 +26,11 @@ export const ArtworkDetails: React.FC<ArtworkDetailsProps> = ({
{
title: "Medium",
value: artworkData?.mediumType?.name && (
<TouchableWithoutFeedback onPress={() => navigate(`/artwork/${artworkData.slug}/medium`)}>
<RouterLink to={`/artwork/${artworkData.slug}/medium`} disablePrefetch>
<Text variant="xs" color="black100" style={{ textDecorationLine: "underline" }}>
{artworkData?.mediumType?.name}
</Text>
</TouchableWithoutFeedback>
</RouterLink>
),
},
{
Expand Down
14 changes: 7 additions & 7 deletions src/app/Scenes/Artwork/Components/ArtworkMakerTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Flex, Text } from "@artsy/palette-mobile"
import { ArtworkMakerTitle_artwork$data } from "__generated__/ArtworkMakerTitle_artwork.graphql"
import { navigate } from "app/system/navigation/navigate"
import { RouterLink } from "app/system/navigation/RouterLink"
import { Schema } from "app/utils/track"
import React, { useState } from "react"
import { TouchableWithoutFeedback } from "react-native"
Expand All @@ -15,26 +15,26 @@ interface ArtworkMakerProps {
const ArtworkMaker: React.FC<ArtworkMakerProps> = ({ artistName, href }) => {
const { trackEvent } = useTracking()

const handleArtistTap = (artistHref?: string | null) => {
if (artistHref) {
const handleArtistTap = () => {
if (href) {
trackEvent({
action_name: Schema.ActionNames.ArtistName,
action_type: Schema.ActionTypes.Tap,
context_module: Schema.ContextModules.ArtworkTombstone,
})
navigate(artistHref)
}
}

return (
<TouchableWithoutFeedback
<RouterLink
accessibilityRole="link"
accessibilityHint="Go to artist page"
disabled={!href}
onPress={() => handleArtistTap(href)}
to={href}
onPress={handleArtistTap}
>
<Text variant="lg-display">{artistName}</Text>
</TouchableWithoutFeedback>
</RouterLink>
)
}

Expand Down
3 changes: 1 addition & 2 deletions src/app/Scenes/Artwork/Components/ArtworksInSeriesRail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
} from "__generated__/ArtworksInSeriesRail_artwork.graphql"
import { ArtworkRail } from "app/Components/ArtworkRail/ArtworkRail"
import { SectionTitle } from "app/Components/SectionTitle"
import { navigate } from "app/system/navigation/navigate"
import { extractNodes } from "app/utils/extractNodes"
import {
CollectorSignals,
Expand Down Expand Up @@ -39,8 +38,8 @@ export const ArtworksInSeriesRail: React.FC<ArtworksInSeriesRailProps> = (props)
titleVariant="md"
onPress={() => {
trackEvent(tracks.tappedHeader(artwork, firstArtistSeries))
navigate(`/artist-series/${firstArtistSeries?.slug}`)
}}
href={`/artist-series/${firstArtistSeries?.slug}`}
/>
<ArtworkRail
artworks={artworks}
Expand Down
15 changes: 4 additions & 11 deletions src/app/Scenes/Artwork/Components/ContextCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Avatar, Flex, Box, Text } from "@artsy/palette-mobile"
import { Avatar, Box, Flex, Text } from "@artsy/palette-mobile"
import { ContextCard_artwork$data } from "__generated__/ContextCard_artwork.graphql"
import { navigate } from "app/system/navigation/navigate"
import { TouchableWithoutFeedback } from "react-native"
import { RouterLink } from "app/system/navigation/RouterLink"
import { createFragmentContainer, graphql, RelayProp } from "react-relay"

interface ContextCardProps {
Expand All @@ -24,13 +23,7 @@ export const ContextCard: React.FC<ContextCardProps> = ({ artwork: { context } }
</Text>
</Box>
<Flex>
<TouchableWithoutFeedback
onPress={() => {
if (context.href) {
navigate(context.href)
}
}}
>
<RouterLink to={context.href}>
<Flex flexDirection="row" flexWrap="nowrap" accessibilityLabel="Context Card Image">
{!!imageUrl && (
<Flex mr={1} justifyContent="center">
Expand All @@ -42,7 +35,7 @@ export const ContextCard: React.FC<ContextCardProps> = ({ artwork: { context } }
<Text variant="sm">{context.formattedStartDateTime}</Text>
</Flex>
</Flex>
</TouchableWithoutFeedback>
</RouterLink>
</Flex>
</>
)
Expand Down
Loading