Skip to content

Commit

Permalink
chore: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dariakoko committed Oct 25, 2024
1 parent 213ca8a commit b698e5b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Flex, Text, TextProps } from "@artsy/palette-mobile"
import { ArtworkSaleMessageComponent_artwork$key } from "__generated__/ArtworkSaleMessageComponent_artwork.graphql"
import { useMetaDataTextColor } from "app/Components/ArtworkRail/ArtworkRailUtils"
import { formattedTimeLeft } from "app/Scenes/Activity/utils/formattedTimeLeft"
import { displayAsLinethrought, parsedSaleMessage } from "app/utils/getSaleMessgeOrBidInfo"
import { getTimer } from "app/utils/getTimer"
import { useFeatureFlag } from "app/utils/hooks/useFeatureFlag"
import { graphql, useFragment } from "react-relay"
Expand Down Expand Up @@ -41,7 +42,7 @@ export const ArtworkSaleMessageComponent: React.FC<ArtworkSaleMessageComponentPr
const saleInfoTextWeight =
displayAuctionSignal && collectorSignals?.auction?.liveBiddingStarted ? "normal" : "bold"

const parts = saleMessage && saleMessage.split(/(~.*?~)/)
const { parts } = parsedSaleMessage(saleMessage)

if (!parts) return null

Expand All @@ -50,7 +51,7 @@ export const ArtworkSaleMessageComponent: React.FC<ArtworkSaleMessageComponentPr
<>
<Flex flexDirection="row">
{parts.map((part, index) => {
if (part.startsWith("~") && part.endsWith("~")) {
if (displayAsLinethrought(part)) {
return (
<Text
key={index}
Expand Down
14 changes: 14 additions & 0 deletions src/app/utils/getSaleMessgeOrBidInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,24 @@ export const saleMessageOrBidInfo = ({
}

if (collectorSignals?.partnerOffer?.isAvailable) {
// If there is a partnerOffer we have to show the message as a strikethrough
// in order to not change the type of the returned value we mark the message with ~
// and parse it in the parsedSaleMessage function to apply different styles to each part later
const salePrice = artwork.saleMessage ? `~${artwork.saleMessage}~` : ""

return `${collectorSignals.partnerOffer.priceWithDiscount?.display}${salePrice}`
}

return artwork.saleMessage
}

export const parsedSaleMessage = (saleMessage: string | null | undefined) => {
// Split the sale message into parts to apply different styles to each part
const parts = saleMessage && saleMessage.split(/(~.*?~)/)

return { parts }
}

export const displayAsLinethrought = (part: string) => {
return part.startsWith("~") && part.endsWith("~")
}

0 comments on commit b698e5b

Please sign in to comment.