-
Notifications
You must be signed in to change notification settings - Fork 591
feat: Featured Fairs screen #11476
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
Merged
Merged
feat: Featured Fairs screen #11476
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7d62421
feat: Featured Fairs screen
olerichter00 59af715
comment
olerichter00 ea9e155
owner type
olerichter00 26c1d7d
route name and tracking
olerichter00 68debd3
chore: merge with main
dariakoko 749affb
feat: adjust the fair screen
dariakoko 8b67458
chore: refactor
dariakoko 13e6c0a
feat: adjust tracking
dariakoko b99f63c
chore: remove redundant prop
dariakoko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { fireEvent, screen, waitForElementToBeRemoved } from "@testing-library/react-native" | ||
import { FeaturedFairsScreen } from "app/Scenes/Fair/FeaturedFairsScreen" | ||
import { navigate } from "app/system/navigation/navigate" | ||
import { setupTestWrapper } from "app/utils/tests/setupTestWrapper" | ||
import { useTracking } from "react-tracking" | ||
|
||
describe("FeaturedFairsScreen", () => { | ||
const { renderWithRelay } = setupTestWrapper({ | ||
Component: () => <FeaturedFairsScreen />, | ||
}) | ||
|
||
it("renders fairs", async () => { | ||
renderWithRelay({ | ||
Query: () => ({ | ||
viewer: { | ||
featuredFairs: mockFairsData, | ||
}, | ||
}), | ||
}) | ||
|
||
await waitForElementToBeRemoved(() => screen.queryByTestId("featured-fairs-screen-placeholder")) | ||
|
||
expect(screen.getByText("Art Saloon International")).toBeTruthy() | ||
expect(screen.getByText("Art Saloon II")).toBeTruthy() | ||
}) | ||
|
||
it("opens fair screen and tracks on press", async () => { | ||
renderWithRelay({ | ||
Query: () => ({ | ||
viewer: { | ||
featuredFairs: mockFairsData, | ||
}, | ||
}), | ||
}) | ||
|
||
await waitForElementToBeRemoved(() => screen.queryByTestId("featured-fairs-screen-placeholder")) | ||
|
||
fireEvent.press(screen.getByText("Art Saloon International")) | ||
|
||
expect(useTracking().trackEvent).toHaveBeenCalledWith({ | ||
action: "tappedFairGroup", | ||
context_module: "fairCard", | ||
context_screen_owner_type: "fairs", | ||
destination_screen_owner_id: "art-saloon-international", | ||
destination_screen_owner_slug: '<mock-value-for-field-"slug">', | ||
destination_screen_owner_type: "fair", | ||
}) | ||
|
||
expect(navigate).toHaveBeenCalledWith('/fair/<mock-value-for-field-"slug">') | ||
}) | ||
}) | ||
|
||
const mockFairsData = [ | ||
{ internalID: "art-saloon-international", name: "Art Saloon International" }, | ||
{ | ||
internalID: "art-saloon-ii", | ||
name: "Art Saloon II", | ||
}, | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { ActionType, ContextModule, OwnerType } from "@artsy/cohesion" | ||
import { Screen, Spacer } from "@artsy/palette-mobile" | ||
import { FairCard_fair$data } from "__generated__/FairCard_fair.graphql" | ||
import { FeaturedFairsScreenQuery } from "__generated__/FeaturedFairsScreenQuery.graphql" | ||
import { FeaturedFairsScreen_viewer$key } from "__generated__/FeaturedFairsScreen_viewer.graphql" | ||
import { | ||
CardWithMetaDataListItem, | ||
useNumColumns, | ||
CardsWithMetaDataListPlaceholder as FeaturedFairsScreenPlaceholder, | ||
} from "app/Components/Cards/CardWithMetaData" | ||
import { FairCard } from "app/Scenes/HomeView/Sections/FairCard" | ||
import { HORIZONTAL_FLATLIST_INTIAL_NUMBER_TO_RENDER_DEFAULT } from "app/Scenes/HomeView/helpers/constants" | ||
import { goBack } from "app/system/navigation/navigate" | ||
import { NoFallback, withSuspense } from "app/utils/hooks/withSuspense" | ||
import { ProvideScreenTrackingWithCohesionSchema } from "app/utils/track" | ||
import { screen } from "app/utils/track/helpers" | ||
|
||
import { graphql, useFragment, useLazyLoadQuery } from "react-relay" | ||
import { useTracking } from "react-tracking" | ||
|
||
interface FeaturedFairsProps { | ||
viewer: FeaturedFairsScreen_viewer$key | ||
} | ||
|
||
export const FeaturedFairs: React.FC<FeaturedFairsProps> = ({ viewer }) => { | ||
const fairs = useFragment(viewerFragment, viewer) | ||
|
||
const { trackEvent } = useTracking() | ||
const numColumns = useNumColumns() | ||
|
||
const handleOnPress = (fair: FairCard_fair$data) => { | ||
trackEvent(tracks.tapFair(fair.internalID, fair.slug || "")) | ||
} | ||
|
||
if (!fairs?.featuredFairs?.length) return null | ||
|
||
return ( | ||
<ProvideScreenTrackingWithCohesionSchema | ||
info={screen({ | ||
context_screen_owner_type: OwnerType.featuredFairs, | ||
})} | ||
> | ||
<Screen> | ||
<Screen.AnimatedHeader onBack={goBack} title="Featured Fairs" /> | ||
<Screen.StickySubHeader title="Featured Fairs" /> | ||
|
||
<Screen.Body fullwidth> | ||
<Spacer y={2} /> | ||
<Screen.FlatList | ||
keyExtractor={(_item, index) => `fair-${index}`} | ||
numColumns={numColumns} | ||
data={fairs?.featuredFairs} | ||
initialNumToRender={HORIZONTAL_FLATLIST_INTIAL_NUMBER_TO_RENDER_DEFAULT} | ||
renderItem={({ item, index }) => { | ||
return ( | ||
<CardWithMetaDataListItem index={index}> | ||
<FairCard fair={item} isFluid onPress={handleOnPress} /> | ||
</CardWithMetaDataListItem> | ||
) | ||
}} | ||
ItemSeparatorComponent={() => <Spacer y={4} />} | ||
ListFooterComponent={<Spacer y={2} />} | ||
/> | ||
</Screen.Body> | ||
</Screen> | ||
</ProvideScreenTrackingWithCohesionSchema> | ||
) | ||
} | ||
|
||
const viewerFragment = graphql` | ||
fragment FeaturedFairsScreen_viewer on Viewer { | ||
featuredFairs(size: 10, includeBackfill: true) { | ||
internalID | ||
...FairCard_fair | ||
} | ||
} | ||
` | ||
|
||
export const featuredFairsScreenQuery = graphql` | ||
query FeaturedFairsScreenQuery { | ||
viewer { | ||
...FeaturedFairsScreen_viewer | ||
} | ||
} | ||
` | ||
|
||
export const FeaturedFairsScreen: React.FC = withSuspense({ | ||
Component: () => { | ||
const data = useLazyLoadQuery<FeaturedFairsScreenQuery>(featuredFairsScreenQuery, {}) | ||
|
||
if (!data?.viewer) { | ||
return null | ||
} | ||
|
||
return <FeaturedFairs viewer={data.viewer} /> | ||
}, | ||
LoadingFallback: () => ( | ||
<FeaturedFairsScreenPlaceholder | ||
testID="featured-fairs-screen-placeholder" | ||
title="Featured Fairs" | ||
/> | ||
), | ||
ErrorFallback: NoFallback, | ||
}) | ||
|
||
export const tracks = { | ||
tapFair: (fairID: string, fairSlug: string) => ({ | ||
action: ActionType.tappedFairGroup, | ||
context_module: ContextModule.fairCard, | ||
context_screen_owner_type: OwnerType.fairs, | ||
destination_screen_owner_type: OwnerType.fair, | ||
destination_screen_owner_id: fairID, | ||
destination_screen_owner_slug: fairSlug, | ||
}), | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a comment by Ole suggesting to use
Not sure if we need it, I think
ContextModule.fairCard
works well and it is already on Cohesion