Skip to content

Commit

Permalink
feat: add update user interest mutation [wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
MounirDhahri committed Jul 21, 2023
1 parent 2732f47 commit 5e4e881
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import { MyCollectionBottomSheetModalArtistPreview_me$data } from "__generated__
import { ArtistListItemContainer, ArtistListItemPlaceholder } from "app/Components/ArtistListItem"
import { ArtistKindPills } from "app/Scenes/MyCollection/Components/MyCollectionBottomSheetModals/MyCollectionBottomSheetModalArtistPreview/ArtistKindPills"
import { deleteUserInterest } from "app/Scenes/MyCollection/mutations/deleteUserInterest"
import { updateUserInterest } from "app/Scenes/MyCollection/mutations/updateUserInterest"
import { getRelayEnvironment } from "app/system/relay/defaultEnvironment"
import { renderWithPlaceholder } from "app/utils/renderWithPlaceholder"
import { useState } from "react"
import { QueryRenderer, createFragmentContainer } from "react-relay"
import { graphql } from "relay-runtime"

Expand All @@ -32,6 +34,9 @@ export const MyCollectionBottomSheetModalArtistPreview: React.FC<
const artworksCountWithMyCollection = me?.myCollectionConnection?.totalCount ?? 0
const canBeRemoved = artworksCountWithMyCollection === 0

// Get the value from MP
const [isPrivate, setIsPrivate] = useState(false)

return (
<BottomSheetView>
<Flex px={2} pt={2}>
Expand All @@ -41,7 +46,26 @@ export const MyCollectionBottomSheetModalArtistPreview: React.FC<
<ArtistKindPills artist={artist} />
</Join>

<ShareArtistCheckbox onCheckboxPress={() => {}} />
<Touchable
haptic
onPress={() => {
updateUserInterest({
id: interestId,
private: !isPrivate,
})
}}
>
<Flex flexDirection="row" alignItems="flex-start">
<Checkbox>
<>
<Text variant="xs">Share this artist with galleries during inquiries.</Text>
<Text variant="xs" color="black60">
Galleries are more likely to respond if they can see the artists you collect.
</Text>
</>
</Checkbox>
</Flex>
</Touchable>

{canBeRemoved ? (
<Text
Expand Down Expand Up @@ -72,22 +96,6 @@ export const MyCollectionBottomSheetModalArtistPreview: React.FC<
)
}

const ShareArtistCheckbox: React.FC<{ onCheckboxPress: () => void }> = ({ onCheckboxPress }) => {
return (
<Touchable haptic onPress={onCheckboxPress}>
<Flex flexDirection="row" alignItems="flex-start">
<Checkbox>
<>
<Text variant="xs">Share this artist with galleries during inquiries.</Text>
<Text variant="xs" color="black60">
Galleries are more likely to respond if they can see the artists you collect.
</Text>
</>
</Checkbox>
</Flex>
</Touchable>
)
}
export const MyCollectionBottomSheetModalArtistPreviewFragmentContainer = createFragmentContainer(
MyCollectionBottomSheetModalArtistPreview,
{
Expand Down Expand Up @@ -115,18 +123,25 @@ export const MyCollectionBottomSheetModalArtistPreviewQueryRenderer: React.FC<{
<QueryRenderer<MyCollectionBottomSheetModalArtistPreviewQuery>
environment={getRelayEnvironment()}
query={graphql`
query MyCollectionBottomSheetModalArtistPreviewQuery($artistID: String!) {
query MyCollectionBottomSheetModalArtistPreviewQuery(
$artistID: String!
$interestId: String!
) {
artist(id: $artistID) {
...MyCollectionBottomSheetModalArtistPreview_artist
}
me {
...MyCollectionBottomSheetModalArtistPreview_me
userInterest(id: $interestId) {
private
}
}
}
`}
cacheConfig={{ force: true }}
variables={{
artistID,
interestId,
}}
render={renderWithPlaceholder({
Container: MyCollectionBottomSheetModalArtistPreviewFragmentContainer,
Expand Down
30 changes: 30 additions & 0 deletions src/app/Scenes/MyCollection/mutations/updateUserInterest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { DeleteUserInterestMutationInput } from "__generated__/deleteUserInterestMutation.graphql"
import { getRelayEnvironment } from "app/system/relay/defaultEnvironment"
import { commitMutation, graphql } from "react-relay"

export const updateUserInterest = (input: DeleteUserInterestMutationInput) => {
return new Promise((resolve, reject) => {
commitMutation(getRelayEnvironment(), {
mutation: graphql`
mutation updateUserInterestMutation($input: UpdateUserInterestMutationInput!) {
updateUserInterest(input: $input) {
userInterest {
internalID
}
}
}
`,
variables: {
input,
},
onCompleted: (response, errors) => {
if (errors?.length) {
reject(errors)
} else {
resolve(response)
}
},
onError: reject,
})
})
}

0 comments on commit 5e4e881

Please sign in to comment.