From 5e4e881b10c094f0f503e1e1dc9fce2b2115f8f9 Mon Sep 17 00:00:00 2001 From: Mounir Dhahri Date: Fri, 21 Jul 2023 16:13:45 +0200 Subject: [PATCH] feat: add update user interest mutation [wip] --- ...ollectionBottomSheetModalArtistPreview.tsx | 51 ++++++++++++------- .../mutations/updateUserInterest.ts | 30 +++++++++++ 2 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 src/app/Scenes/MyCollection/mutations/updateUserInterest.ts diff --git a/src/app/Scenes/MyCollection/Components/MyCollectionBottomSheetModals/MyCollectionBottomSheetModalArtistPreview.tsx b/src/app/Scenes/MyCollection/Components/MyCollectionBottomSheetModals/MyCollectionBottomSheetModalArtistPreview.tsx index a51bb11e35d..71d3049ee48 100644 --- a/src/app/Scenes/MyCollection/Components/MyCollectionBottomSheetModals/MyCollectionBottomSheetModalArtistPreview.tsx +++ b/src/app/Scenes/MyCollection/Components/MyCollectionBottomSheetModals/MyCollectionBottomSheetModalArtistPreview.tsx @@ -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" @@ -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 ( @@ -41,7 +46,26 @@ export const MyCollectionBottomSheetModalArtistPreview: React.FC< - {}} /> + { + updateUserInterest({ + id: interestId, + private: !isPrivate, + }) + }} + > + + + <> + Share this artist with galleries during inquiries. + + Galleries are more likely to respond if they can see the artists you collect. + + + + + {canBeRemoved ? ( void }> = ({ onCheckboxPress }) => { - return ( - - - - <> - Share this artist with galleries during inquiries. - - Galleries are more likely to respond if they can see the artists you collect. - - - - - - ) -} export const MyCollectionBottomSheetModalArtistPreviewFragmentContainer = createFragmentContainer( MyCollectionBottomSheetModalArtistPreview, { @@ -115,18 +123,25 @@ export const MyCollectionBottomSheetModalArtistPreviewQueryRenderer: React.FC<{ 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, diff --git a/src/app/Scenes/MyCollection/mutations/updateUserInterest.ts b/src/app/Scenes/MyCollection/mutations/updateUserInterest.ts new file mode 100644 index 00000000000..17e581ddb47 --- /dev/null +++ b/src/app/Scenes/MyCollection/mutations/updateUserInterest.ts @@ -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, + }) + }) +}