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: support navigating to artist artworks grid - mounir #9403

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
},
"dependencies": {
"@artsy/cohesion": "4.154.0",
"@artsy/palette-mobile": "13.0.16",
"@artsy/palette-mobile": "13.0.18",
"@artsy/to-title-case": "1.1.0",
"@expo/react-native-action-sheet": "4.0.1",
"@gorhom/bottom-sheet": "4.5.1",
Expand Down
16 changes: 15 additions & 1 deletion src/app/Components/Artist/ArtistArtworks/ArtistArtworks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useScreenDimensions,
useSpace,
} from "@artsy/palette-mobile"
import { MasonryFlashListRef } from "@shopify/flash-list"
import { ArtistArtworks_artist$data } from "__generated__/ArtistArtworks_artist.graphql"
import { ArtistArtworksFilterHeader } from "app/Components/Artist/ArtistArtworks/ArtistArtworksFilterHeader"
import { CreateSavedSearchModal } from "app/Components/Artist/ArtistArtworks/CreateSavedSearchModal"
Expand All @@ -36,7 +37,7 @@ import {
ON_END_REACHED_THRESHOLD_MASONRY,
} from "app/utils/masonryHelpers"
import { Schema } from "app/utils/track"
import React, { useCallback, useEffect, useMemo, useState } from "react"
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react"
import { RelayPaginationProp, createPaginationContainer, graphql } from "react-relay"
import { useTracking } from "react-tracking"

Expand All @@ -45,12 +46,14 @@ interface ArtworksGridProps extends InfiniteScrollGridProps {
searchCriteria: SearchCriteriaAttributes | null
relay: RelayPaginationProp
predefinedFilters?: FilterArray
scrollToArtworksGrid: boolean
}

const ArtworksGrid: React.FC<ArtworksGridProps> = ({
artist,
relay,
predefinedFilters,
scrollToArtworksGrid,
searchCriteria,
...props
}) => {
Expand All @@ -64,6 +67,9 @@ const ArtworksGrid: React.FC<ArtworksGridProps> = ({
const showCreateAlertAtEndOfList = useFeatureFlag("ARShowCreateAlertInArtistArtworksListFooter")
const enableAlertsFilters = useFeatureFlag("AREnableAlertsFilters")
const artworks = useMemo(() => extractNodes(artist.artworks), [artist.artworks])

const gridRef = useRef<MasonryFlashListRef<typeof artworks[0]>>(null)

const appliedFilters = ArtworksFiltersStore.useStoreState((state) => state.appliedFilters)

const { navigateToPageableRoute } = useNavigateToPageableRoute({ items: artworks })
Expand Down Expand Up @@ -100,6 +106,13 @@ const ArtworksGrid: React.FC<ArtworksGridProps> = ({
setInitialFilterStateAction(filters)
}, [])

useEffect(() => {
if (scrollToArtworksGrid) {
setTimeout(() => {
gridRef.current?.scrollToOffset({ offset: 0, animated: true })
}, 1000)
gkartalis marked this conversation as resolved.
Show resolved Hide resolved
}
})
const { savedSearchEntity, attributes } = useCreateSavedSearchModalFilters({
entityId: artist.internalID!,
entityName: artist.name ?? "",
Expand Down Expand Up @@ -232,6 +245,7 @@ const ArtworksGrid: React.FC<ArtworksGridProps> = ({
numColumns={NUM_COLUMNS_MASONRY}
estimatedItemSize={ESTIMATED_MASONRY_ITEM_SIZE}
keyboardShouldPersistTaps="handled"
innerRef={gridRef}
ListEmptyComponent={
<Box mb="80px" pt={2}>
<FilteredArtworkGridZeroState
Expand Down
15 changes: 11 additions & 4 deletions src/app/Scenes/Activity/utils/navigateToActivityItem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FilterArray } from "app/Components/ArtworkFilter/ArtworkFilterHelpers"
import { ORDERED_ARTWORK_SORTS } from "app/Components/ArtworkFilter/Filters/SortOptions"
import { matchRoute } from "app/routes"
import { navigate } from "app/system/navigation/navigate"
import { last } from "lodash"
import { parse as parseQueryString } from "query-string"
Expand All @@ -13,10 +14,16 @@ export const navigateToActivityItem = (targetHref: string) => {
(sortEntity) => sortEntity.paramValue === "-published_at"
)!

const passProps: any = {
predefinedFilters: [sortFilterItem] as FilterArray,
searchCriteriaID: parsed.search_criteria_id,
}

if ((matchRoute(targetHref) as any).module === "Artist") {
Copy link
Member Author

Choose a reason for hiding this comment

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

matchRoute return type depends on the module type. I could have typecasted this in a different way probably. let me know if you have better suggestions

passProps.scrollToArtworksGrid = true
}

navigate(targetHref, {
passProps: {
predefinedFilters: [sortFilterItem] as FilterArray,
searchCriteriaID: parsed.search_criteria_id,
},
passProps,
})
}
21 changes: 14 additions & 7 deletions src/app/Scenes/Artist/Artist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ interface ArtistProps {
initialTab?: string
me: ArtistAboveTheFoldQuery["response"]["me"]
predefinedFilters?: FilterArray
scrollToArtworksGrid: boolean
searchCriteria: SearchCriteriaAttributes | null
}

Expand All @@ -69,6 +70,7 @@ export const Artist: React.FC<ArtistProps> = (props) => {
initialTab = INITIAL_TAB,
me,
predefinedFilters,
scrollToArtworksGrid,
searchCriteria,
} = props

Expand Down Expand Up @@ -142,6 +144,7 @@ export const Artist: React.FC<ArtistProps> = (props) => {
artist={artistAboveTheFold}
searchCriteria={searchCriteria}
predefinedFilters={predefinedFilters}
scrollToArtworksGrid={scrollToArtworksGrid}
/>
</Tabs.Lazy>
</Tabs.Tab>
Expand Down Expand Up @@ -175,13 +178,14 @@ export const Artist: React.FC<ArtistProps> = (props) => {
}

interface ArtistQueryRendererProps {
artistID: string
categories?: string[]
environment?: RelayModernEnvironment
initialTab?: string
searchCriteriaID?: string
search_criteria_id?: string
artistID: string
predefinedFilters?: FilterArray
categories?: string[]
scrollToArtworksGrid?: boolean
search_criteria_id?: string
searchCriteriaID?: string
sizes?: string[]
}

Expand Down Expand Up @@ -213,14 +217,16 @@ export const defaultArtistVariables = () => ({
})

export const ArtistQueryRenderer: React.FC<ArtistQueryRendererProps> = (props) => {
console.log({ props })
const {
artistID,
categories,
environment,
initialTab,
searchCriteriaID,
search_criteria_id,
predefinedFilters,
categories,
search_criteria_id,
scrollToArtworksGrid = false,
searchCriteriaID,
sizes,
} = props

Expand Down Expand Up @@ -290,6 +296,7 @@ export const ArtistQueryRenderer: React.FC<ArtistQueryRendererProps> = (props) =
categories: categories ?? [],
sizes: sizes ?? [],
})}
scrollToArtworksGrid={scrollToArtworksGrid}
/>
)
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Touchable } from "@artsy/palette-mobile"
import { fireEvent } from "@testing-library/react-native"
import { SearchContext } from "app/Scenes/Search/SearchContext"
import { GlobalStore, GlobalStoreProvider } from "app/store/GlobalStore"
import { EntityType, navigate, navigateToEntity, SlugType } from "app/system/navigation/navigate"
import { CatchErrors } from "app/utils/CatchErrors"
import { extractText } from "app/utils/tests/extractText"
import { renderWithWrappers, renderWithWrappersLEGACY } from "app/utils/tests/renderWithWrappers"
import { Touchable } from "@artsy/palette-mobile"
import { Pressable } from "react-native"
import { act } from "react-test-renderer"
import { AutosuggestSearchResult } from "./AutosuggestSearchResult"
Expand Down Expand Up @@ -92,7 +92,7 @@ describe(AutosuggestSearchResult, () => {
tree.root.findByType(Touchable).props.onPress()
await new Promise((r) => setTimeout(r, 50))
expect(inputBlurMock).toHaveBeenCalled()
expect(navigate).toHaveBeenCalledWith(result.href, { passProps: { initialTab: "Artworks" } })
expect(navigate).toHaveBeenCalledWith(result.href, { passProps: undefined })
Copy link
Member Author

Choose a reason for hiding this comment

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

no need to inject any props if you didn't press on "Artworks" or "AuctionResults"

})

it(`highlights a part of the string even when the string has diacritics but the highlight doesn't`, async () => {
Expand Down Expand Up @@ -254,7 +254,7 @@ describe(AutosuggestSearchResult, () => {
})
await new Promise((r) => setTimeout(r, 50))
expect(navigate).toHaveBeenCalledWith("/artist/anto-carte", {
passProps: { initialTab: "Artworks" },
passProps: { initialTab: "Artworks", scrollToArtworksGrid: true },
})

act(() => {
Expand Down
17 changes: 11 additions & 6 deletions src/app/Scenes/Search/components/AutosuggestSearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export type TrackResultPress = (result: AutosuggestResult, itemIndex?: number) =

type ArtistTabs = "Insights" | "Artworks"

type HandleResultPress = (passProps?: { artistTab: ArtistTabs }) => void
type PassedProps = {
initialTab: ArtistTabs
scrollToArtworksGrid?: boolean
}

type HandleResultPress = (passProps?: PassedProps) => void

const getResultType = (result: AutosuggestResult) => {
if (result.displayType) {
Expand Down Expand Up @@ -77,7 +82,7 @@ export const AutosuggestSearchResult: React.FC<{
inputRef.current?.blur()
// need to wait a tick to push next view otherwise the input won't blur ¯\_(ツ)_/¯
setTimeout(() => {
navigateToResult(result, passProps?.artistTab)
navigateToResult(result, passProps)
if (updateRecentSearchesOnTap) {
GlobalStore.actions.search.addRecentSearch({
type: "AUTOSUGGEST_RESULT_TAPPED",
Expand Down Expand Up @@ -162,7 +167,7 @@ export const AutosuggestSearchResult: React.FC<{
highlightEnabled
Icon={ArtworkIcon}
rounded
onPress={() => onPress({ artistTab: "Artworks" })}
onPress={() => onPress({ initialTab: "Artworks", scrollToArtworksGrid: true })}
block
>
Artworks
Expand All @@ -172,7 +177,7 @@ export const AutosuggestSearchResult: React.FC<{
highlightEnabled
Icon={AuctionIcon}
rounded
onPress={() => onPress({ artistTab: "Insights" })}
onPress={() => onPress({ initialTab: "Insights" })}
block
>
Auction Results
Expand All @@ -189,13 +194,13 @@ export const AutosuggestSearchResult: React.FC<{
* about the entity type to render the correct placeholder/skeleton loader
* @param result
*/
function navigateToResult(result: AutosuggestResult, artistTab: ArtistTabs = "Artworks") {
function navigateToResult(result: AutosuggestResult, props?: PassedProps) {
if (result.displayType === "Gallery" || result.displayType === "Institution") {
navigateToPartner(result.href!)
} else if (result.displayType === "Fair") {
navigateToEntity(result.href!, EntityType.Fair, SlugType.ProfileID)
} else if (result.__typename === "Artist") {
navigate(result.href!, { passProps: { initialTab: artistTab } })
navigate(result.href!, { passProps: props })
} else {
navigate(result.href!)
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
dependencies:
core-js "3"

"@artsy/[email protected].16":
version "13.0.16"
resolved "https://registry.yarnpkg.com/@artsy/palette-mobile/-/palette-mobile-13.0.16.tgz#7bc4adeba350ac81e0baee2f27809e55f4ad8778"
integrity sha512-fZeXaRFK6BrKq+iXRF+enD8+BATmUJV5ME2DwgT/x9bKNnocfuGPGGwVVLXO2vYetWDRXkntVDuNbx89HM4//A==
"@artsy/[email protected].18":
version "13.0.18"
resolved "https://registry.yarnpkg.com/@artsy/palette-mobile/-/palette-mobile-13.0.18.tgz#401e8d7650214969c2f45f55dcf7f03f211017a7"
integrity sha512-zgECF6QcMO46Ymoc/01QfW7Q6ZwK9eYF6LVkrBb7yFBtkqhMeFJjS/FnrBchGiyQQVha9MWRmoidoreEbtbDiA==
dependencies:
"@artsy/palette-tokens" "^5.0.0"
"@shopify/flash-list" "^1.5.0"
Expand Down