-
Notifications
You must be signed in to change notification settings - Fork 573
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(ExploreBy): address bugs, layout issues and relay fetching issues #11008
Merged
araujobarret
merged 2 commits into
main
from
araujobarret/fix/broken-links-collections-misc
Oct 24, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { Flex, Skeleton, SkeletonText, Text, useSpace } from "@artsy/palette-mobile" | ||
import { Flex, Separator, Skeleton, SkeletonText, Text, useSpace } from "@artsy/palette-mobile" | ||
import { useRoute } from "@react-navigation/native" | ||
import { FlashList } from "@shopify/flash-list" | ||
import { BodyCollectionsByCategoryQuery } from "__generated__/BodyCollectionsByCategoryQuery.graphql" | ||
import { BodyCollectionsByCategory_marketingCollection$key } from "__generated__/BodyCollectionsByCategory_marketingCollection.graphql" | ||
import { CollectionsChips_marketingCollections$key } from "__generated__/CollectionsChips_marketingCollections.graphql" | ||
import { BodyCollectionsByCategory_viewer$key } from "__generated__/BodyCollectionsByCategory_viewer.graphql" | ||
import { | ||
CollectionRailPlaceholder, | ||
CollectionRailWithSuspense, | ||
|
@@ -16,41 +16,56 @@ import { NoFallback, withSuspense } from "app/utils/hooks/withSuspense" | |
import { graphql, useLazyLoadQuery, useFragment } from "react-relay" | ||
|
||
interface BodyProps { | ||
marketingCollections: BodyCollectionsByCategory_marketingCollection$key & | ||
CollectionsChips_marketingCollections$key | ||
viewer: BodyCollectionsByCategory_viewer$key | ||
} | ||
|
||
export const Body: React.FC<BodyProps> = ({ marketingCollections: _marketingCollections }) => { | ||
export const Body: React.FC<BodyProps> = ({ viewer }) => { | ||
const space = useSpace() | ||
const marketingCollections = useFragment(fragment, _marketingCollections) | ||
const data = useFragment(fragment, viewer) | ||
const { params } = useRoute<CollectionsByCategoriesRouteProp>() | ||
const category = params.props.category | ||
|
||
if (!marketingCollections) { | ||
if (!data?.marketingCollections) { | ||
return null | ||
} | ||
|
||
return ( | ||
<Flex px={2} gap={space(4)}> | ||
<Text variant="xl">{category}</Text> | ||
<Flex gap={space(4)}> | ||
<Text variant="xl" px={2}> | ||
{category} | ||
</Text> | ||
|
||
<Flex gap={space(1)}> | ||
<Flex px={2} gap={space(2)}> | ||
<Text>Explore collections with {category}</Text> | ||
<CollectionsChips marketingCollections={_marketingCollections} /> | ||
{/* TODO: fix typings broken by some unknown reason here, prob related to @plural */} | ||
<CollectionsChips marketingCollections={data.marketingCollections as any} /> | ||
</Flex> | ||
|
||
{marketingCollections.map((collection) => { | ||
const slug = collection?.slug ?? "" | ||
return <CollectionRailWithSuspense key={`artwork_rail_${slug}`} slug={slug} /> | ||
})} | ||
<Separator borderColor="black10" /> | ||
|
||
<FlashList | ||
estimatedItemSize={ESTIMATED_ITEM_SIZE} | ||
data={data.marketingCollections} | ||
keyExtractor={(item) => `artwork_rail_${item?.slug}`} | ||
renderItem={({ item }) => { | ||
return <CollectionRailWithSuspense slug={item?.slug ?? ""} /> | ||
}} | ||
ItemSeparatorComponent={() => <Separator borderColor="black10" my={4} />} | ||
/> | ||
</Flex> | ||
) | ||
} | ||
|
||
const ESTIMATED_ITEM_SIZE = 390 | ||
|
||
const fragment = graphql` | ||
fragment BodyCollectionsByCategory_marketingCollection on MarketingCollection | ||
@relay(plural: true) { | ||
slug @required(action: NONE) | ||
fragment BodyCollectionsByCategory_viewer on Viewer | ||
@argumentDefinitions(category: { type: "String" }) { | ||
marketingCollections(category: $category, first: 20) { | ||
...CollectionsChips_marketingCollections | ||
|
||
slug @required(action: NONE) | ||
} | ||
} | ||
` | ||
|
||
|
@@ -59,42 +74,49 @@ const BodyPlaceholder: React.FC = () => { | |
|
||
return ( | ||
<Skeleton> | ||
<Flex px={2} gap={space(2)}> | ||
<SkeletonText variant="xl">Category</SkeletonText> | ||
<Flex gap={space(4)}> | ||
<Flex px={2}> | ||
<SkeletonText variant="xl">Category</SkeletonText> | ||
</Flex> | ||
|
||
<Flex gap={space(1)}> | ||
<Flex gap={space(1)} px={2}> | ||
<SkeletonText>Category description text</SkeletonText> | ||
|
||
<CollectionsChipsPlaceholder /> | ||
</Flex> | ||
|
||
<Separator borderColor="black10" /> | ||
|
||
<CollectionRailPlaceholder /> | ||
</Flex> | ||
</Skeleton> | ||
) | ||
} | ||
|
||
const query = graphql` | ||
query BodyCollectionsByCategoryQuery($category: String!) { | ||
marketingCollections(category: $category, first: 20) { | ||
...BodyCollectionsByCategory_marketingCollection | ||
...CollectionsChips_marketingCollections | ||
query BodyCollectionsByCategoryQuery($category: String!) @cacheable { | ||
viewer { | ||
...BodyCollectionsByCategory_viewer @arguments(category: $category) | ||
} | ||
} | ||
` | ||
|
||
export const BodyWithSuspense = withSuspense({ | ||
Component: () => { | ||
const { params } = useRoute<CollectionsByCategoriesRouteProp>() | ||
const data = useLazyLoadQuery<BodyCollectionsByCategoryQuery>(query, { | ||
category: params.props.entityID, | ||
}) | ||
|
||
if (!data.marketingCollections) { | ||
const data = useLazyLoadQuery<BodyCollectionsByCategoryQuery>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
query, | ||
{ | ||
category: params.props.entityID, | ||
}, | ||
{ fetchPolicy: "store-and-network" } | ||
) | ||
|
||
if (!data.viewer) { | ||
return <BodyPlaceholder /> | ||
} | ||
|
||
return <Body marketingCollections={data.marketingCollections} /> | ||
return <Body viewer={data.viewer} /> | ||
}, | ||
LoadingFallback: BodyPlaceholder, | ||
ErrorFallback: NoFallback, | ||
|
This file contains 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 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 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 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
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.
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.
@joeyAghion added the
@cacheable
here since, in this first part we have no custom-user-data being fetched, we only use to display the chips collections list and to get each collection slug.