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

chore(ONYX-150): use myCollectionConnection to fetch artworks count within my collection #9027

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { BottomSheetView } from "@gorhom/bottom-sheet"
import { MyCollectionBottomSheetModalArtistPreviewQuery } from "__generated__/MyCollectionBottomSheetModalArtistPreviewQuery.graphql"
import { MyCollectionBottomSheetModalArtistPreview_artist$data } from "__generated__/MyCollectionBottomSheetModalArtistPreview_artist.graphql"
import { MyCollectionBottomSheetModalArtistPreview_me$data } from "__generated__/MyCollectionBottomSheetModalArtistPreview_me.graphql"
import { ArtistListItemContainer, ArtistListItemPlaceholder } from "app/Components/ArtistListItem"
import { ArtistKindPills } from "app/Scenes/MyCollection/Components/MyCollectionBottomSheetModals/MyCollectionBottomSheetModalArtistPreview/ArtistKindPills"
import { getRelayEnvironment } from "app/system/relay/defaultEnvironment"
Expand All @@ -20,20 +21,21 @@ import { graphql } from "relay-runtime"

interface MyCollectionBottomSheetModalArtistPreviewProps {
artist: MyCollectionBottomSheetModalArtistPreview_artist$data
uploadsCount: number | null
me: MyCollectionBottomSheetModalArtistPreview_me$data
}

export const MyCollectionBottomSheetModalArtistPreview: React.FC<
MyCollectionBottomSheetModalArtistPreviewProps
> = ({ artist, uploadsCount }) => {
const canBeRemoved = uploadsCount === 0
> = ({ artist, me }) => {
const artworksCountWithMyCollection = me?.myCollectionConnection?.totalCount ?? 0
const canBeRemoved = artworksCountWithMyCollection === 0

return (
<BottomSheetView>
<Flex px={2} pt={2}>
<Join separator={<Spacer y={4} />}>
<Join separator={<Spacer y={2} />}>
<ArtistListItemContainer artist={artist} uploadsCount={uploadsCount} />
<ArtistListItemContainer artist={artist} uploadsCount={artworksCountWithMyCollection} />
<ArtistKindPills artist={artist} />
</Join>

Expand Down Expand Up @@ -87,13 +89,19 @@ export const MyCollectionBottomSheetModalArtistPreviewFragmentContainer = create
...ArtistKindPills_artist
}
`,
me: graphql`
fragment MyCollectionBottomSheetModalArtistPreview_me on Me {
myCollectionConnection(artistIDs: [$artistID]) {
totalCount
}
}
`,
}
)

export const MyCollectionBottomSheetModalArtistPreviewQueryRenderer: React.FC<{
artistID: string
uploadsCount: number | null
}> = ({ artistID, uploadsCount }) => {
}> = ({ artistID }) => {
return (
<QueryRenderer<MyCollectionBottomSheetModalArtistPreviewQuery>
environment={getRelayEnvironment()}
Expand All @@ -102,6 +110,9 @@ export const MyCollectionBottomSheetModalArtistPreviewQueryRenderer: React.FC<{
artist(id: $artistID) {
...MyCollectionBottomSheetModalArtistPreview_artist
}
me {
...MyCollectionBottomSheetModalArtistPreview_me
}
}
`}
cacheConfig={{ force: true }}
Expand All @@ -112,7 +123,6 @@ export const MyCollectionBottomSheetModalArtistPreviewQueryRenderer: React.FC<{
Container: MyCollectionBottomSheetModalArtistPreviewFragmentContainer,
renderPlaceholder: LoadingSkeleton,
renderFallback: () => null,
initialProps: { uploadsCount },
})}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export const MyCollectionBottomSheetModals: React.FC<{}> = () => {
const setViewKind = MyCollectionTabsStore.useStoreActions((actions) => actions.setViewKind)
const view = MyCollectionTabsStore.useStoreState((state) => state.viewKind)
const id = MyCollectionTabsStore.useStoreState((state) => state.id)
// TODO: Implement this
const uploadsCount = 0

const snapPoints = useMemo(() => [view === "Artist" ? 410 : 370], [])

Expand Down Expand Up @@ -48,10 +46,7 @@ export const MyCollectionBottomSheetModals: React.FC<{}> = () => {
>
{view === "Add" && <MyCollectionBottomSheetModalAdd />}
{view === "Artist" && !!id && (
<MyCollectionBottomSheetModalArtistPreviewQueryRenderer
artistID={id}
uploadsCount={uploadsCount}
/>
<MyCollectionBottomSheetModalArtistPreviewQueryRenderer artistID={id} />
)}
</BottomSheet>
</>
Expand Down