Skip to content

Commit

Permalink
chore: remove TS SwitchBoard class + purge navRef pattern (#4170)
Browse files Browse the repository at this point in the history
* clean up TS SwitchBoard class

* update changelog

* goodbye navRef

* run yarn relay
  • Loading branch information
ds300 committed Nov 25, 2020
1 parent d823079 commit 4a90fdc
Show file tree
Hide file tree
Showing 151 changed files with 443 additions and 885 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.yml
Expand Up @@ -12,6 +12,8 @@ upcoming:
- Rename AppStore to GlobalStore - david
- Update STRICTNESS_MIGRATION comments - david
- Don't pass email to segment - brian
- Remove SwitchBoard.tsx - david
- Fix device token checking logic - david
user_facing:
-
releases:
Expand Down Expand Up @@ -232,7 +234,6 @@ releases:
- Add method for rendering wrapped components - brian
- Refactor recent searches to use easy-peasy - brian, mounir, david
- Add easy-peasy app store persistence & migration - david
- Fix device token checking logic - david
user_facing:
- Prevent follow button going off screen in artist page - brian
- don't show password on wrong password entry - brian
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Components/Artist/Articles/Article.tsx
Expand Up @@ -5,7 +5,7 @@ import { StyleSheet, TouchableWithoutFeedback, View, ViewProperties } from "reac

import ImageView from "lib/Components/OpaqueImageView/OpaqueImageView"
import fonts from "lib/data/fonts"
import SwitchBoard from "lib/NativeModules/SwitchBoard"
import { navigate } from "lib/navigation/navigate"

import { Article_article } from "__generated__/Article_article.graphql"
import { Sans, Spacer } from "palette"
Expand All @@ -16,7 +16,7 @@ interface Props extends ViewProperties {

class Article extends React.Component<Props> {
handleTap() {
SwitchBoard.presentNavigationViewController(this, this.props.article.href!)
navigate(this.props.article.href!)
}

render() {
Expand Down
6 changes: 2 additions & 4 deletions src/lib/Components/Artist/ArtistAbout.tsx
Expand Up @@ -6,7 +6,7 @@ import Articles from "./Articles"
import Biography from "./Biography"

import { ArtistAbout_artist } from "__generated__/ArtistAbout_artist.graphql"
import SwitchBoard from "lib/NativeModules/SwitchBoard"
import { navigate } from "lib/navigation/navigate"
import { extractNodes } from "lib/utils/extractNodes"
import { CaretButton } from "../Buttons/CaretButton"
import { Stack } from "../Stack"
Expand All @@ -28,9 +28,7 @@ class ArtistAbout extends React.Component<Props> {
{!!this.props.artist.is_display_auction_link && (
<CaretButton
text="Auction results"
onPress={() =>
SwitchBoard.presentNavigationViewController(this, `/artist/${this.props.artist.slug}/auction-results`)
}
onPress={() => navigate(`/artist/${this.props.artist.slug}/auction-results`)}
/>
)}
<ArtistConsignButton artist={this.props.artist} />
Expand Down
Expand Up @@ -2,7 +2,7 @@ import { ArtistNotableWorksRail_artist } from "__generated__/ArtistNotableWorksR
import { AboveTheFoldFlatList } from "lib/Components/AboveTheFoldFlatList"
import { ArtworkTileRailCard } from "lib/Components/ArtworkTileRail"
import { SectionTitle } from "lib/Components/SectionTitle"
import SwitchBoard from "lib/NativeModules/SwitchBoard"
import { navigate } from "lib/navigation/navigate"
import { Box, Spacer } from "palette"
import React from "react"
import { createFragmentContainer, graphql } from "react-relay"
Expand All @@ -21,13 +21,11 @@ const ArtistNotableWorksRail: React.FC<ArtistNotableWorksRailProps> = ({ artist
return null
}

const navRef = React.useRef<any>()

const handleNavigation = (slug: string | undefined) => {
if (!slug) {
return
}
return SwitchBoard.presentNavigationViewController(navRef.current, `/artwork/${slug}`)
return navigate(`/artwork/${slug}`)
}
const saleMessage = (artwork: NotableArtwork) => {
const sale = artwork?.node?.sale
Expand Down Expand Up @@ -55,7 +53,6 @@ const ArtistNotableWorksRail: React.FC<ArtistNotableWorksRailProps> = ({ artist
</Box>
<ArtistNotableWorksRailWrapper>
<AboveTheFoldFlatList<NotableArtwork>
listRef={navRef}
horizontal
ListHeaderComponent={() => <Spacer mr={2}></Spacer>}
ListFooterComponent={() => <Spacer mr={2}></Spacer>}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Components/Artist/ArtistConsignButton.tsx
Expand Up @@ -6,7 +6,7 @@ import { useTracking } from "react-tracking"
import styled from "styled-components/native"

import { ArtistConsignButton_artist } from "__generated__/ArtistConsignButton_artist.graphql"
import SwitchBoard from "lib/NativeModules/SwitchBoard"
import { navigate } from "lib/navigation/navigate"
import { useSelectedTab } from "lib/store/GlobalStore"
import { Schema } from "lib/utils/track"

Expand Down Expand Up @@ -44,7 +44,7 @@ export const ArtistConsignButton: React.FC<ArtistConsignButtonProps> = (props) =
destination_path: destination,
})

SwitchBoard.presentNavigationViewController(buttonRef.current!, destination)
navigate(destination)
}}
>
<BorderBox p={0}>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Components/Artist/ArtistShows/ArtistShow.tsx
Expand Up @@ -3,10 +3,10 @@ import { TouchableWithoutFeedback, View, ViewStyle } from "react-native"
import { createFragmentContainer, graphql } from "react-relay"

import OpaqueImageView from "lib/Components/OpaqueImageView/OpaqueImageView"
import SwitchBoard from "../../../NativeModules/SwitchBoard"
import Metadata from "./Metadata"

import { ArtistShow_show } from "__generated__/ArtistShow_show.graphql"
import { navigate } from "lib/navigation/navigate"
import { hrefForPartialShow } from "lib/utils/router"

interface Props {
Expand All @@ -20,7 +20,7 @@ interface Props {

class Show extends React.Component<Props> {
handleTap() {
SwitchBoard.presentNavigationViewController(this, hrefForPartialShow(this.props.show))
navigate(hrefForPartialShow(this.props.show))
}

render() {
Expand Down
13 changes: 3 additions & 10 deletions src/lib/Components/Artist/__tests__/ArtistConsignButton-tests.tsx
@@ -1,5 +1,5 @@
import { ArtistConsignButtonTestsQuery } from "__generated__/ArtistConsignButtonTestsQuery.graphql"
import SwitchBoard from "lib/NativeModules/SwitchBoard"
import { navigate } from "lib/navigation/navigate"
import { __globalStoreTestUtils__, GlobalStoreProvider } from "lib/store/GlobalStore"
import { extractText } from "lib/tests/extractText"
import { renderWithWrappers } from "lib/tests/renderWithWrappers"
Expand All @@ -13,9 +13,6 @@ import { createMockEnvironment } from "relay-test-utils"
import { ArtistConsignButtonFragmentContainer, tests } from "../ArtistConsignButton"

jest.unmock("react-relay")
jest.mock("lib/NativeModules/SwitchBoard", () => ({
presentNavigationViewController: jest.fn(),
}))

describe("ArtistConsignButton", () => {
let env: ReturnType<typeof createMockEnvironment>
Expand Down Expand Up @@ -57,7 +54,6 @@ describe("ArtistConsignButton", () => {

afterEach(() => {
trackEvent.mockClear()
;(SwitchBoard.presentNavigationViewController as jest.Mock<any>).mockClear()
})

describe("Top 20 Artist ('Microfunnel') or Target Supply button", () => {
Expand Down Expand Up @@ -224,7 +220,7 @@ describe("ArtistConsignButton", () => {
})
tree.root.findByType(TouchableOpacity).props.onPress()

expect(SwitchBoard.presentNavigationViewController).toHaveBeenCalledWith(expect.anything(), "/sales")
expect(navigate).toHaveBeenCalledWith("/sales")
})

it("sends user to a new instance of landing page if user is already in sales tab", () => {
Expand All @@ -241,10 +237,7 @@ describe("ArtistConsignButton", () => {
})
tree.root.findByType(TouchableOpacity).props.onPress()

expect(SwitchBoard.presentNavigationViewController).toHaveBeenCalledWith(
expect.anything(),
"/collections/my-collection/marketing-landing"
)
expect(navigate).toHaveBeenCalledWith("/collections/my-collection/marketing-landing")
})
})
})
4 changes: 2 additions & 2 deletions src/lib/Components/ArtistListItem.tsx
@@ -1,6 +1,6 @@
import { ArtistListItem_artist } from "__generated__/ArtistListItem_artist.graphql"
import { ArtistListItemFollowArtistMutation } from "__generated__/ArtistListItemFollowArtistMutation.graphql"
import SwitchBoard from "lib/NativeModules/SwitchBoard"
import { navigate } from "lib/navigation/navigate"
import { Schema, track } from "lib/utils/track"
import { Button, color, EntityHeader, Flex, Theme } from "palette"
import { Touchable } from "palette"
Expand Down Expand Up @@ -116,7 +116,7 @@ export class ArtistListItem extends React.Component<Props, State> {
} as any
})
handleTap(href: string) {
SwitchBoard.presentNavigationViewController(this, href)
navigate(href)
}

render() {
Expand Down
10 changes: 2 additions & 8 deletions src/lib/Components/ArtworkGrids/ArtworkGridItem.tsx
@@ -1,7 +1,7 @@
import { ScreenOwnerType, tappedMainArtworkGrid } from "@artsy/cohesion"
import { ArtworkGridItem_artwork } from "__generated__/ArtworkGridItem_artwork.graphql"
import OpaqueImageView from "lib/Components/OpaqueImageView/OpaqueImageView"
import SwitchBoard from "lib/NativeModules/SwitchBoard"
import { navigate } from "lib/navigation/navigate"
import { getUrgencyTag } from "lib/utils/getUrgencyTag"
import { PlaceholderBox, PlaceholderRaggedText, RandomNumberGenerator } from "lib/utils/placeholders"
import { Box, Flex, Sans, Spacer } from "palette"
Expand Down Expand Up @@ -50,13 +50,7 @@ export const Artwork: React.FC<ArtworkProps> = ({

const handleTap = () => {
trackArtworkTap()
onPress && artwork.slug
? onPress(artwork.slug)
: SwitchBoard.presentNavigationViewController(
itemRef.current!,
// @ts-expect-error STRICTNESS_MIGRATION --- 🚨 Unsafe legacy code 🚨 Please delete this and fix any type errors if you have time 🙏
artwork.href
)
onPress && artwork.slug ? onPress(artwork.slug) : navigate(artwork.href!)
}

const trackArtworkTap = () => {
Expand Down
11 changes: 4 additions & 7 deletions src/lib/Components/ArtworkTileRail/ArtworkTileRail.tsx
@@ -1,9 +1,9 @@
import { ArtworkTileRail_artworksConnection } from "__generated__/ArtworkTileRail_artworksConnection.graphql"
import SwitchBoard from "lib/NativeModules/SwitchBoard"
import { navigate } from "lib/navigation/navigate"
import { extractNodes } from "lib/utils/extractNodes"
import { Schema } from "lib/utils/track"
import { Spacer } from "palette"
import React, { useRef } from "react"
import React from "react"
import { FlatList, View } from "react-native"
import { createFragmentContainer, graphql } from "react-relay"
import { useTracking } from "react-tracking"
Expand Down Expand Up @@ -31,10 +31,9 @@ export const ArtworkTileRailContainer: React.FC<ArtworkTileRailContainerProps> =
}) => {
const artworks = extractNodes(artworksConnection)
const tracking = useTracking()
const navRef = useRef<any>()

return (
<View ref={navRef}>
<View>
<FlatList
horizontal
ListHeaderComponent={() => <Spacer mr={2}></Spacer>}
Expand All @@ -51,9 +50,7 @@ export const ArtworkTileRailContainer: React.FC<ArtworkTileRailContainerProps> =
tracking.trackEvent(tappedArtworkGroupThumbnail(contextModule!, item.internalID, item.slug))
}
{
!!onTilePress
? onTilePress(item.slug, item.internalID)
: SwitchBoard.presentNavigationViewController(navRef.current!, item.href!)
!!onTilePress ? onTilePress(item.slug, item.internalID) : navigate(item.href!)
}
}}
imageURL={item.image?.imageURL}
Expand Down
@@ -1,5 +1,5 @@
import { ArtworkTileRailTestsQuery } from "__generated__/ArtworkTileRailTestsQuery.graphql"
import SwitchBoard from "lib/NativeModules/SwitchBoard"
import { navigate } from "lib/navigation/navigate"
import { renderWithWrappers } from "lib/tests/renderWithWrappers"
import { Schema } from "lib/utils/track"
import React from "react"
Expand All @@ -10,9 +10,6 @@ import { ArtworkTileRail, tappedArtworkGroupThumbnail } from "../ArtworkTileRail
import { ArtworkTileRailCard } from "../ArtworkTileRailCard"

jest.unmock("react-relay")
jest.mock("lib/NativeModules/SwitchBoard", () => ({
presentNavigationViewController: jest.fn(),
}))

describe("ArtworkTileRail", () => {
let mockEnvironment: ReturnType<typeof createMockEnvironment>
Expand Down Expand Up @@ -70,10 +67,7 @@ describe("ArtworkTileRail", () => {

tree.root.findByType(ArtworkTileRailCard).props.onPress()

expect(SwitchBoard.presentNavigationViewController).toHaveBeenCalledWith(
expect.anything(),
"/artwork/nicolas-party-rocks-ii"
)
expect(navigate).toHaveBeenCalledWith("/artwork/nicolas-party-rocks-ii")
expect(useTracking().trackEvent).toHaveBeenCalledWith(
tappedArtworkGroupThumbnail(
Schema.ContextModules.ViewingRoomArtworkRail,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Components/Bidding/Screens/BidResult.tsx
Expand Up @@ -3,7 +3,7 @@ import { View } from "react-native"
import NavigatorIOS from "react-native-navigator-ios"
import { createFragmentContainer, graphql } from "react-relay"

import SwitchBoard from "lib/NativeModules/SwitchBoard"
import { dismissModal, navigate } from "lib/navigation/navigate"

import { Button } from "palette"
import { Icon20 } from "../Components/Icon"
Expand Down Expand Up @@ -65,9 +65,9 @@ export class BidResult extends React.Component<BidResultProps> {
// @ts-expect-error STRICTNESS_MIGRATION --- 🚨 Unsafe legacy code 🚨 Please delete this and fix any type errors if you have time 🙏
const saleSlug = this.props.sale_artwork.sale.slug
const url = `${getCurrentEmissionState().predictionURL}/${saleSlug}`
SwitchBoard.presentModalViewController(this, url)
navigate(url, { modal: true })
} else {
SwitchBoard.dismissModalViewController(this)
dismissModal()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/Components/Bidding/Screens/ConfirmBid/index.tsx
Expand Up @@ -22,7 +22,7 @@ import { PriceSummary } from "lib/Components/Bidding/Screens/ConfirmBid/PriceSum
import { SelectMaxBidEdit } from "lib/Components/Bidding/Screens/SelectMaxBidEdit"
import { Address, Bid, PaymentCardTextFieldParams, StripeToken } from "lib/Components/Bidding/types"
import { LinkText } from "lib/Components/Text/LinkText"
import SwitchBoard from "lib/NativeModules/SwitchBoard"
import { navigate } from "lib/navigation/navigate"
import { Schema, screenTrack, track } from "lib/utils/track"

import { BidderPositionQueryResponse } from "__generated__/BidderPositionQuery.graphql"
Expand Down Expand Up @@ -358,7 +358,7 @@ export class ConfirmBid extends React.Component<ConfirmBidProps, ConfirmBidState
}

onConditionsOfSaleLinkPressed() {
SwitchBoard.presentModalViewController(this, "/conditions-of-sale")
navigate("/conditions-of-sale", { modal: true })
}

refreshBidderInfo = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Components/Bidding/Screens/Registration.tsx
Expand Up @@ -10,7 +10,7 @@ import stripe from "tipsi-stripe"
import { bidderNeedsIdentityVerification } from "lib/utils/auction"
import { Schema, screenTrack } from "lib/utils/track"

import SwitchBoard from "lib/NativeModules/SwitchBoard"
import { navigate } from "lib/navigation/navigate"

import { Flex } from "../Elements/Flex"

Expand Down Expand Up @@ -95,7 +95,7 @@ export class Registration extends React.Component<RegistrationProps, Registratio
}

onPressConditionsOfSale = () => {
SwitchBoard.presentModalViewController(this, "/conditions-of-sale")
navigate("/conditions-of-sale", { modal: true })
}

onCreditCardAdded(token: StripeToken, params: PaymentCardTextFieldParams) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Components/Bidding/Screens/RegistrationResult.tsx
Expand Up @@ -11,7 +11,7 @@ import { BiddingThemeProvider } from "../Components/BiddingThemeProvider"
import { Container } from "../Components/Containers"
import { Title } from "../Components/Title"

import SwitchBoard from "lib/NativeModules/SwitchBoard"
import { dismissModal } from "lib/navigation/navigate"
import { defaultRules } from "lib/utils/renderMarkdown"
import { Schema, screenTrack } from "lib/utils/track"

Expand Down Expand Up @@ -106,8 +106,8 @@ const resultEnumToPageName = (result: RegistrationStatus) => {
} as any) /* STRICTNESS_MIGRATION */
)
export class RegistrationResult extends React.Component<RegistrationResultProps> {
exitBidFlow = async () => {
await SwitchBoard.dismissModalViewController(this)
exitBidFlow = () => {
dismissModal()
}

render() {
Expand Down

0 comments on commit 4a90fdc

Please sign in to comment.