diff --git a/src/app/Components/Artist/ArtistShows/ArtistShow.tsx b/src/app/Components/Artist/ArtistShows/ArtistShow.tsx index 3a5661ddb95..e95c85f1430 100644 --- a/src/app/Components/Artist/ArtistShows/ArtistShow.tsx +++ b/src/app/Components/Artist/ArtistShows/ArtistShow.tsx @@ -1,6 +1,7 @@ import { ActionType, ContextModule, OwnerType, TappedShowGroup } from "@artsy/cohesion" -import { Image, Touchable } from "@artsy/palette-mobile" +import { Touchable } from "@artsy/palette-mobile" import { ArtistShow_show$data, ArtistShow_show$key } from "__generated__/ArtistShow_show.graphql" +import { ImageWithFallback } from "app/Components/ImageWithFallback/ImageWithFallback" import { navigate } from "app/system/navigation/navigate" import { useFeatureFlag } from "app/utils/hooks/useFeatureFlag" import { hrefForPartialShow } from "app/utils/router" @@ -41,15 +42,13 @@ export const ArtistShow: React.FC = ({ styles, show, index, imageDimensio - {!!imageURL && ( - - )} + {/* this wrapper required to make numberOfLines work when parent is a row */} diff --git a/src/app/Components/ImageWithFallback/ImageWithFallback.tests.tsx b/src/app/Components/ImageWithFallback/ImageWithFallback.tests.tsx new file mode 100644 index 00000000000..7dfe339b276 --- /dev/null +++ b/src/app/Components/ImageWithFallback/ImageWithFallback.tests.tsx @@ -0,0 +1,23 @@ +import { ImageWithFallback } from "app/Components/ImageWithFallback/ImageWithFallback" +import { renderWithWrappers } from "app/utils/tests/renderWithWrappers" + +describe("ImageWithFallback", () => { + it("renders without error", () => { + renderWithWrappers() + }) + + it("renders the image when a url is passed", async () => { + const view = renderWithWrappers( + + ) + const image = await view.findByTestId("image") + expect(image).toBeTruthy() + }) + + it("renders the fallback when a url is not passed", async () => { + const view = renderWithWrappers() + + const fallbackImage = await view.findByTestId("fallback-image") + expect(fallbackImage).toBeTruthy() + }) +}) diff --git a/src/app/Components/ImageWithFallback/ImageWithFallback.tsx b/src/app/Components/ImageWithFallback/ImageWithFallback.tsx new file mode 100644 index 00000000000..cdc664397af --- /dev/null +++ b/src/app/Components/ImageWithFallback/ImageWithFallback.tsx @@ -0,0 +1,27 @@ +import { Box, Image, ImageProps } from "@artsy/palette-mobile" + +// Extend ImageProps but make `src` optional +type ImageWithFallbackProps = Omit & { + src?: string | null +} + +export const ImageWithFallback: React.FC = ({ + src, + width, + height, + ...props +}) => { + if (!src) { + return ( + + ) + } + + return +} diff --git a/src/app/Components/Lists/SavedItemRow.tsx b/src/app/Components/Lists/SavedItemRow.tsx index a9960062f37..232af286a9a 100644 --- a/src/app/Components/Lists/SavedItemRow.tsx +++ b/src/app/Components/Lists/SavedItemRow.tsx @@ -1,4 +1,5 @@ -import { Spacer, Flex, useColor, Text, Touchable, Image } from "@artsy/palette-mobile" +import { Spacer, Flex, useColor, Text, Touchable } from "@artsy/palette-mobile" +import { ImageWithFallback } from "app/Components/ImageWithFallback/ImageWithFallback" import { navigate } from "app/system/navigation/navigate" interface SavedItemRowProps { @@ -36,7 +37,7 @@ export const SavedItemRow: React.FC = ({ borderRadius={square_image ? 2 : size / 2} overflow="hidden" > - {!!imageURL && } + diff --git a/src/app/Components/ShowCard.tsx b/src/app/Components/ShowCard.tsx index 6c4246763fb..dd29eeb4f95 100644 --- a/src/app/Components/ShowCard.tsx +++ b/src/app/Components/ShowCard.tsx @@ -1,14 +1,7 @@ -import { - Spacer, - Flex, - Text, - Touchable, - SkeletonBox, - SkeletonText, - Image, -} from "@artsy/palette-mobile" +import { Spacer, Flex, Text, Touchable, SkeletonBox, SkeletonText } from "@artsy/palette-mobile" import { toTitleCase } from "@artsy/to-title-case" import { ShowCard_show$data } from "__generated__/ShowCard_show.graphql" +import { ImageWithFallback } from "app/Components/ImageWithFallback/ImageWithFallback" import { navigate } from "app/system/navigation/navigate" import { compact } from "lodash" import { GestureResponderEvent, ViewProps } from "react-native" @@ -47,7 +40,7 @@ export const ShowCard: React.FC = ({ show, onPress }) => { - {!!imageURL && } + {show.name} diff --git a/src/app/Components/ThreeUpImageLayout.tsx b/src/app/Components/ThreeUpImageLayout.tsx index a4adafb05f7..17c1913bbae 100644 --- a/src/app/Components/ThreeUpImageLayout.tsx +++ b/src/app/Components/ThreeUpImageLayout.tsx @@ -1,4 +1,5 @@ -import { Box, Image } from "@artsy/palette-mobile" +import { Box } from "@artsy/palette-mobile" +import { ImageWithFallback } from "app/Components/ImageWithFallback/ImageWithFallback" import styled from "styled-components/native" interface ThreeUpImageLayoutProps { @@ -16,7 +17,7 @@ export const ThreeUpImageLayout: React.FC = ({ imageURL return ( - = ({ imageURL /> - - { this.handleTap(item)}> - {!!fairImage && } + {!!item.name && ( diff --git a/src/app/Scenes/Feature/components/FeatureFeaturedLink.tsx b/src/app/Scenes/Feature/components/FeatureFeaturedLink.tsx index 2d675ee6b8d..704e2463a1f 100644 --- a/src/app/Scenes/Feature/components/FeatureFeaturedLink.tsx +++ b/src/app/Scenes/Feature/components/FeatureFeaturedLink.tsx @@ -1,5 +1,6 @@ -import { Flex, Image, Text } from "@artsy/palette-mobile" +import { Flex, Text } from "@artsy/palette-mobile" import { FeatureFeaturedLink_featuredLink$data } from "__generated__/FeatureFeaturedLink_featuredLink.graphql" +import { ImageWithFallback } from "app/Components/ImageWithFallback/ImageWithFallback" import { navigate } from "app/system/navigation/navigate" import { TouchableOpacity } from "react-native" import LinearGradient from "react-native-linear-gradient" @@ -22,9 +23,7 @@ const FeatureFeaturedLink: React.FC = ({ featuredLink, } }} > - {!!featuredLink.image?.url && ( - - )} + = ({ - {!!imageUrl && } + {!!showInitials && ( { )} - {!!imageURL && ( - - )} + diff --git a/src/app/Scenes/Inbox/Components/Conversations/ItemShow.tsx b/src/app/Scenes/Inbox/Components/Conversations/ItemShow.tsx index 7227d967c2b..12ae031e76d 100644 --- a/src/app/Scenes/Inbox/Components/Conversations/ItemShow.tsx +++ b/src/app/Scenes/Inbox/Components/Conversations/ItemShow.tsx @@ -1,5 +1,6 @@ -import { Flex, Box, Text, Separator, Touchable, Image } from "@artsy/palette-mobile" +import { Flex, Box, Text, Separator, Touchable } from "@artsy/palette-mobile" import { ItemShow_show$data } from "__generated__/ItemShow_show.graphql" +import { ImageWithFallback } from "app/Components/ImageWithFallback/ImageWithFallback" import { navigate } from "app/system/navigation/navigate" import { createFragmentContainer, graphql } from "react-relay" @@ -18,9 +19,12 @@ export const ItemShow: React.FC = ({ show }) => { show.href && navigate(show.href)}> - {!!show.image?.thumbnailUrl && ( - - )} + diff --git a/src/app/Scenes/MyBids/Components/Lot.tsx b/src/app/Scenes/MyBids/Components/Lot.tsx index 8ed93fa1c4c..b6fc4a03354 100644 --- a/src/app/Scenes/MyBids/Components/Lot.tsx +++ b/src/app/Scenes/MyBids/Components/Lot.tsx @@ -1,5 +1,6 @@ -import { Flex, Box, Text, Image } from "@artsy/palette-mobile" +import { Flex, Box, Text } from "@artsy/palette-mobile" import { Lot_saleArtwork$data } from "__generated__/Lot_saleArtwork.graphql" +import { ImageWithFallback } from "app/Components/ImageWithFallback/ImageWithFallback" import React from "react" import { createFragmentContainer, graphql } from "react-relay" @@ -20,9 +21,7 @@ class Lot extends React.Component { - {!!saleArtwork?.artwork?.image?.url && ( - - )} + {!!ArtworkBadge && ( diff --git a/src/app/Scenes/Partner/Components/PartnerShowRailItem.tsx b/src/app/Scenes/Partner/Components/PartnerShowRailItem.tsx index dca85d2c204..9fc8f8e6025 100644 --- a/src/app/Scenes/Partner/Components/PartnerShowRailItem.tsx +++ b/src/app/Scenes/Partner/Components/PartnerShowRailItem.tsx @@ -1,5 +1,6 @@ -import { Flex, Image, Spacer, Text, Touchable, useScreenDimensions } from "@artsy/palette-mobile" +import { Flex, Spacer, Text, Touchable, useScreenDimensions } from "@artsy/palette-mobile" import { PartnerShowRailItem_show$data } from "__generated__/PartnerShowRailItem_show.graphql" +import { ImageWithFallback } from "app/Components/ImageWithFallback/ImageWithFallback" import { exhibitionDates } from "app/Scenes/Map/exhibitionPeriodParser" import { navigate } from "app/system/navigation/navigate" import { Schema } from "app/utils/track" @@ -30,9 +31,12 @@ export const PartnerShowRailItem: React.FC = (props) => { return ( - {!!imageURL && ( - - )} + {name} diff --git a/src/app/Scenes/Search/components/SearchResultImage.tsx b/src/app/Scenes/Search/components/SearchResultImage.tsx index b4a15b6f052..1437086650f 100644 --- a/src/app/Scenes/Search/components/SearchResultImage.tsx +++ b/src/app/Scenes/Search/components/SearchResultImage.tsx @@ -1,4 +1,5 @@ -import { Avatar, Flex, Image } from "@artsy/palette-mobile" +import { Avatar, Flex } from "@artsy/palette-mobile" +import { ImageWithFallback } from "app/Components/ImageWithFallback/ImageWithFallback" export const IMAGE_SIZE = 40 @@ -21,15 +22,13 @@ export const SearchResultImage: React.FC<{ borderRadius={round ? IMAGE_SIZE / 2 : 0} overflow="hidden" > - {!!imageURL && ( - - )} + ) } diff --git a/src/app/Scenes/Search/components/TrendingArtistCard.tsx b/src/app/Scenes/Search/components/TrendingArtistCard.tsx index 91d531be986..0b80159a2c2 100644 --- a/src/app/Scenes/Search/components/TrendingArtistCard.tsx +++ b/src/app/Scenes/Search/components/TrendingArtistCard.tsx @@ -1,5 +1,6 @@ -import { Flex, Image, Text } from "@artsy/palette-mobile" +import { Flex, Text } from "@artsy/palette-mobile" import { TrendingArtistCard_artist$key } from "__generated__/TrendingArtistCard_artist.graphql" +import { ImageWithFallback } from "app/Components/ImageWithFallback/ImageWithFallback" import { TouchableHighlight } from "react-native" import { useFragment, graphql } from "react-relay" @@ -21,9 +22,11 @@ export const TrendingArtistCard: React.FC = ({ artist, onPress={onPress} > - {!!data.coverArtwork?.image?.url && ( - - )} +