Skip to content

Commit

Permalink
fix: fix broken consign with artsy link (#10415)
Browse files Browse the repository at this point in the history
* fix:broken useSelectedTab

* fix: navigate to sell tab on consign with artsy press
  • Loading branch information
MounirDhahri committed Jun 20, 2024
1 parent a00a59a commit 6aa2dc8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/app/Scenes/Artwork/Components/ArtworkConsignments.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LinkText, Text } from "@artsy/palette-mobile"
import { ArtworkConsignments_artwork$key } from "__generated__/ArtworkConsignments_artwork.graphql"
import { switchTab } from "app/system/navigation/navigate"
import { popToRoot, switchTab } from "app/system/navigation/navigate"
import { useSelectedTab } from "app/utils/hooks/useSelectedTab"
import { Schema } from "app/utils/track"
import { graphql, useFragment } from "react-relay"
import { useTracking } from "react-tracking"
Expand All @@ -17,14 +18,20 @@ export const ArtworkConsignments: React.FC<ArtworkConsignmentsProps> = ({ artwor
const firstArtistName = artists[0]?.name ?? "this artist"
const label = consignableArtists.length > 1 ? "these artists" : firstArtistName

const activeTab = useSelectedTab()

const handleLinkPress = () => {
tracking.trackEvent({
action_name: Schema.ActionNames.ConsignWithArtsy,
action_type: Schema.ActionTypes.Tap,
// TODO: Update context module
context_module: Schema.ContextModules.ArtworkExtraLinks,
})
switchTab("sell")
if (activeTab === "sell") {
popToRoot()
} else {
switchTab("sell")
}
}

if (!artists.length) {
Expand Down
10 changes: 8 additions & 2 deletions src/app/Scenes/Artwork/Components/ArtworkExtraLinks/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Text } from "@artsy/palette-mobile"
import { ArtworkExtraLinks_artwork$data } from "__generated__/ArtworkExtraLinks_artwork.graphql"
import { AuctionTimerState } from "app/Components/Bidding/Components/Timer"
import { switchTab } from "app/system/navigation/navigate"
import { popToRoot, switchTab } from "app/system/navigation/navigate"
import { useSelectedTab } from "app/utils/hooks/useSelectedTab"
import { Schema } from "app/utils/track"
import { View } from "react-native"
import { createFragmentContainer, graphql } from "react-relay"
Expand Down Expand Up @@ -32,6 +33,7 @@ export const ArtworkExtraLinks: React.FC<ArtworkExtraLinksProps> = ({ artwork, a

const ConsignmentsLink: React.FC<{ artistName: string }> = ({ artistName }) => {
const tracking = useTracking()
const activeTab = useSelectedTab()

return (
<View>
Expand All @@ -46,7 +48,11 @@ const ConsignmentsLink: React.FC<{ artistName: string }> = ({ artistName }) => {
action_type: Schema.ActionTypes.Tap,
context_module: Schema.ContextModules.ArtworkExtraLinks,
})
switchTab("sell")
if (activeTab === "sell") {
popToRoot()
} else {
switchTab("sell")
}
}}
>
Consign with Artsy
Expand Down
14 changes: 9 additions & 5 deletions src/app/utils/hooks/useSelectedTab.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { useNavigationState } from "@react-navigation/native"
import { __unsafe_mainModalStackRef } from "app/NativeModules/ARScreenPresenterModule"
import { BottomTabType } from "app/Scenes/BottomTabs/BottomTabType"

export function useSelectedTab(): BottomTabType {
const tabState = useNavigationState(
(state) => state.routes.find((r) => r.state?.type === "tab")?.state
)
const tabState = __unsafe_mainModalStackRef.current
?.getState()
?.routes.find((r) => r.state?.type === "tab")?.state

if (!tabState) {
return "home"
} else {
const { index, routes } = tabState
return routes[index!].name as BottomTabType
if (index === undefined) {
return "home"
}
return routes[index].name as BottomTabType
}
}

0 comments on commit 6aa2dc8

Please sign in to comment.