diff --git a/app/components/Rating.tsx b/app/components/Rating.tsx index ad0c3eab..ab1b1b86 100644 --- a/app/components/Rating.tsx +++ b/app/components/Rating.tsx @@ -1,7 +1,7 @@ import React from "react"; import { useNavigation } from "@react-navigation/native"; import { HStack, Spacer, Stack, Text } from "native-base"; -import { GetRatingsQuery } from "../generated/graphql"; +import { GetRatingsQuery, useDeleteRatingMutation } from "../generated/graphql"; import { Navigation } from "../utils/Navigation"; import { useUser } from "../utils/useUser"; import { Avatar } from "./Avatar"; @@ -9,7 +9,6 @@ import { printStars } from "./Stars"; import { Unpacked, isMobile } from "../utils/constants"; import { Card } from "./Card"; import { Alert } from "react-native"; -import { ApolloError, gql, useMutation } from "@apollo/client"; type Rating = Unpacked; @@ -18,12 +17,6 @@ interface Props { index: number; } -export const DeleteRating = gql` - mutation DeleteRating($id: String!) { - deleteRating(id: $id) - } -`; - export function Rating(props: Props) { const { item } = props; const { user } = useUser(); @@ -32,7 +25,22 @@ export function Rating(props: Props) { const isRater = user?.id === item.rater.id; - const [_deleteRating] = useMutation(DeleteRating); + const [deleteRating] = useDeleteRatingMutation({ + variables: { + id: item.id + }, + onError(error) { + alert(error.message); + }, + update(cache) { + cache.evict({ + id: cache.identify({ + __typename: "Rating", + id: item.id, + }), + }); + } + }); const onLongPress = () => { if (isMobile) { @@ -44,7 +52,7 @@ export function Rating(props: Props) { text: "No", style: "cancel", }, - { text: "Yes", onPress: deleteRating }, + { text: "Yes", onPress: () => deleteRating() }, ], { cancelable: true } ); @@ -53,20 +61,6 @@ export function Rating(props: Props) { } }; - const deleteRating = () => { - _deleteRating({ - variables: { id: item.id }, - update: (cache) => { - cache.evict({ - id: cache.identify({ - __typename: "Rating", - id: item.id, - }), - }); - }, - }).catch((error: ApolloError) => alert(error?.message)); - }; - return ( = T | { [P in keyof T]?: P extends ' $fragmentName' | const defaultOptions = {} as const; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { - ID: { input: string | number; output: string; } + ID: { input: string; output: string; } String: { input: string; output: string; } Boolean: { input: boolean; output: boolean; } Int: { input: number; output: number; } @@ -698,6 +698,13 @@ export type GetRateDataQueryVariables = Exact<{ [key: string]: never; }>; export type GetRateDataQuery = { __typename?: 'Query', getLastBeepToRate?: { __typename?: 'Beep', id: string, beeper: { __typename?: 'User', id: string, name: string, username: string, photo?: string | null, isBeeping: boolean } } | null }; +export type DeleteRatingMutationVariables = Exact<{ + id: Scalars['String']['input']; +}>; + + +export type DeleteRatingMutation = { __typename?: 'Mutation', deleteRating: boolean }; + export type LogoutMutationVariables = Exact<{ [key: string]: never; }>; @@ -949,13 +956,6 @@ export type AddProfilePictureMutationVariables = Exact<{ export type AddProfilePictureMutation = { __typename?: 'Mutation', addProfilePicture: { __typename?: 'User', id: string, photo?: string | null } }; -export type RemoveTokenMutationVariables = Exact<{ - token: Scalars['String']['input']; -}>; - - -export type RemoveTokenMutation = { __typename?: 'Mutation', removeToken: boolean }; - export type UserDataQueryVariables = Exact<{ [key: string]: never; }>; @@ -1089,6 +1089,37 @@ export function useGetRateDataLazyQuery(baseOptions?: ApolloReactHooks.LazyQuery export type GetRateDataQueryHookResult = ReturnType; export type GetRateDataLazyQueryHookResult = ReturnType; export type GetRateDataQueryResult = ApolloReactCommon.QueryResult; +export const DeleteRatingDocument = gql` + mutation DeleteRating($id: String!) { + deleteRating(id: $id) +} + `; +export type DeleteRatingMutationFn = ApolloReactCommon.MutationFunction; + +/** + * __useDeleteRatingMutation__ + * + * To run a mutation, you first call `useDeleteRatingMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useDeleteRatingMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [deleteRatingMutation, { data, loading, error }] = useDeleteRatingMutation({ + * variables: { + * id: // value for 'id' + * }, + * }); + */ +export function useDeleteRatingMutation(baseOptions?: ApolloReactHooks.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return ApolloReactHooks.useMutation(DeleteRatingDocument, options); + } +export type DeleteRatingMutationHookResult = ReturnType; +export type DeleteRatingMutationResult = ApolloReactCommon.MutationResult; +export type DeleteRatingMutationOptions = ApolloReactCommon.BaseMutationOptions; export const LogoutDocument = gql` mutation Logout { logout(isApp: true) @@ -2495,37 +2526,6 @@ export function useAddProfilePictureMutation(baseOptions?: ApolloReactHooks.Muta export type AddProfilePictureMutationHookResult = ReturnType; export type AddProfilePictureMutationResult = ApolloReactCommon.MutationResult; export type AddProfilePictureMutationOptions = ApolloReactCommon.BaseMutationOptions; -export const RemoveTokenDocument = gql` - mutation RemoveToken($token: String!) { - removeToken(token: $token) -} - `; -export type RemoveTokenMutationFn = ApolloReactCommon.MutationFunction; - -/** - * __useRemoveTokenMutation__ - * - * To run a mutation, you first call `useRemoveTokenMutation` within a React component and pass it any options that fit your needs. - * When your component renders, `useRemoveTokenMutation` returns a tuple that includes: - * - A mutate function that you can call at any time to execute the mutation - * - An object with fields that represent the current status of the mutation's execution - * - * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; - * - * @example - * const [removeTokenMutation, { data, loading, error }] = useRemoveTokenMutation({ - * variables: { - * token: // value for 'token' - * }, - * }); - */ -export function useRemoveTokenMutation(baseOptions?: ApolloReactHooks.MutationHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return ApolloReactHooks.useMutation(RemoveTokenDocument, options); - } -export type RemoveTokenMutationHookResult = ReturnType; -export type RemoveTokenMutationResult = ApolloReactCommon.MutationResult; -export type RemoveTokenMutationOptions = ApolloReactCommon.BaseMutationOptions; export const UserDataDocument = gql` query UserData { getUser { diff --git a/website/src/generated/graphql.tsx b/website/src/generated/graphql.tsx index ff0fc17c..4a64cc33 100644 --- a/website/src/generated/graphql.tsx +++ b/website/src/generated/graphql.tsx @@ -10,7 +10,7 @@ export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | const defaultOptions = {} as const; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { - ID: { input: string | number; output: string; } + ID: { input: string; output: string; } String: { input: string; output: string; } Boolean: { input: boolean; output: boolean; } Int: { input: number; output: number; } @@ -822,6 +822,14 @@ export type VerifyAccountMutationVariables = Exact<{ export type VerifyAccountMutation = { __typename?: 'Mutation', verifyAccount: boolean }; +export type FeedbackQueryVariables = Exact<{ + offset?: InputMaybe; + show?: InputMaybe; +}>; + + +export type FeedbackQuery = { __typename?: 'Query', getFeedback: { __typename?: 'FeedbackResonse', count: number, items: Array<{ __typename?: 'Feedback', id: string, message: string, created: any, user: { __typename?: 'User', id: string, photo?: string | null, name: string } }> } }; + export type GetUsersPerDomainQueryVariables = Exact<{ [key: string]: never; }>; @@ -832,14 +840,6 @@ export type RedisChannelsQueryQueryVariables = Exact<{ [key: string]: never; }>; export type RedisChannelsQueryQuery = { __typename?: 'Query', getRedisChannels: Array }; -export type FeedbackQueryVariables = Exact<{ - offset?: InputMaybe; - show?: InputMaybe; -}>; - - -export type FeedbackQuery = { __typename?: 'Query', getFeedback: { __typename?: 'FeedbackResonse', count: number, items: Array<{ __typename?: 'Feedback', id: string, message: string, created: any, user: { __typename?: 'User', id: string, photo?: string | null, name: string } }> } }; - export type GetBeepersQueryVariables = Exact<{ latitude: Scalars['Float']['input']; longitude: Scalars['Float']['input']; @@ -1879,6 +1879,52 @@ export function useVerifyAccountMutation(baseOptions?: Apollo.MutationHookOption export type VerifyAccountMutationHookResult = ReturnType; export type VerifyAccountMutationResult = Apollo.MutationResult; export type VerifyAccountMutationOptions = Apollo.BaseMutationOptions; +export const FeedbackDocument = gql` + query Feedback($offset: Int, $show: Int) { + getFeedback(offset: $offset, show: $show) { + items { + id + message + created + user { + id + photo + name + } + } + count + } +} + `; + +/** + * __useFeedbackQuery__ + * + * To run a query within a React component, call `useFeedbackQuery` and pass it any options that fit your needs. + * When your component renders, `useFeedbackQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useFeedbackQuery({ + * variables: { + * offset: // value for 'offset' + * show: // value for 'show' + * }, + * }); + */ +export function useFeedbackQuery(baseOptions?: Apollo.QueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useQuery(FeedbackDocument, options); + } +export function useFeedbackLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useLazyQuery(FeedbackDocument, options); + } +export type FeedbackQueryHookResult = ReturnType; +export type FeedbackLazyQueryHookResult = ReturnType; +export type FeedbackQueryResult = Apollo.QueryResult; export const GetUsersPerDomainDocument = gql` query GetUsersPerDomain { getUsersPerDomain { @@ -1946,52 +1992,6 @@ export function useRedisChannelsQueryLazyQuery(baseOptions?: Apollo.LazyQueryHoo export type RedisChannelsQueryQueryHookResult = ReturnType; export type RedisChannelsQueryLazyQueryHookResult = ReturnType; export type RedisChannelsQueryQueryResult = Apollo.QueryResult; -export const FeedbackDocument = gql` - query Feedback($offset: Int, $show: Int) { - getFeedback(offset: $offset, show: $show) { - items { - id - message - created - user { - id - photo - name - } - } - count - } -} - `; - -/** - * __useFeedbackQuery__ - * - * To run a query within a React component, call `useFeedbackQuery` and pass it any options that fit your needs. - * When your component renders, `useFeedbackQuery` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useFeedbackQuery({ - * variables: { - * offset: // value for 'offset' - * show: // value for 'show' - * }, - * }); - */ -export function useFeedbackQuery(baseOptions?: Apollo.QueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useQuery(FeedbackDocument, options); - } -export function useFeedbackLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useLazyQuery(FeedbackDocument, options); - } -export type FeedbackQueryHookResult = ReturnType; -export type FeedbackLazyQueryHookResult = ReturnType; -export type FeedbackQueryResult = Apollo.QueryResult; export const GetBeepersDocument = gql` query GetBeepers($latitude: Float!, $longitude: Float!, $radius: Float) { getBeepers(latitude: $latitude, longitude: $longitude, radius: $radius) {