Skip to content

Commit

Permalink
chore: clean up new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
bnussman committed Oct 16, 2023
1 parent a302e87 commit 43b568b
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 118 deletions.
42 changes: 18 additions & 24 deletions app/components/Rating.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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";
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<GetRatingsQuery["getRatings"]["items"]>;

Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -44,7 +52,7 @@ export function Rating(props: Props) {
text: "No",
style: "cancel",
},
{ text: "Yes", onPress: deleteRating },
{ text: "Yes", onPress: () => deleteRating() },
],
{ cancelable: true }
);
Expand All @@ -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 (
<Card
mt={2}
Expand Down
78 changes: 39 additions & 39 deletions app/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type Incremental<T> = 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; }
Expand Down Expand Up @@ -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; }>;


Expand Down Expand Up @@ -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; }>;


Expand Down Expand Up @@ -1089,6 +1089,37 @@ export function useGetRateDataLazyQuery(baseOptions?: ApolloReactHooks.LazyQuery
export type GetRateDataQueryHookResult = ReturnType<typeof useGetRateDataQuery>;
export type GetRateDataLazyQueryHookResult = ReturnType<typeof useGetRateDataLazyQuery>;
export type GetRateDataQueryResult = ApolloReactCommon.QueryResult<GetRateDataQuery, GetRateDataQueryVariables>;
export const DeleteRatingDocument = gql`
mutation DeleteRating($id: String!) {
deleteRating(id: $id)
}
`;
export type DeleteRatingMutationFn = ApolloReactCommon.MutationFunction<DeleteRatingMutation, DeleteRatingMutationVariables>;

/**
* __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<DeleteRatingMutation, DeleteRatingMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useMutation<DeleteRatingMutation, DeleteRatingMutationVariables>(DeleteRatingDocument, options);
}
export type DeleteRatingMutationHookResult = ReturnType<typeof useDeleteRatingMutation>;
export type DeleteRatingMutationResult = ApolloReactCommon.MutationResult<DeleteRatingMutation>;
export type DeleteRatingMutationOptions = ApolloReactCommon.BaseMutationOptions<DeleteRatingMutation, DeleteRatingMutationVariables>;
export const LogoutDocument = gql`
mutation Logout {
logout(isApp: true)
Expand Down Expand Up @@ -2495,37 +2526,6 @@ export function useAddProfilePictureMutation(baseOptions?: ApolloReactHooks.Muta
export type AddProfilePictureMutationHookResult = ReturnType<typeof useAddProfilePictureMutation>;
export type AddProfilePictureMutationResult = ApolloReactCommon.MutationResult<AddProfilePictureMutation>;
export type AddProfilePictureMutationOptions = ApolloReactCommon.BaseMutationOptions<AddProfilePictureMutation, AddProfilePictureMutationVariables>;
export const RemoveTokenDocument = gql`
mutation RemoveToken($token: String!) {
removeToken(token: $token)
}
`;
export type RemoveTokenMutationFn = ApolloReactCommon.MutationFunction<RemoveTokenMutation, RemoveTokenMutationVariables>;

/**
* __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<RemoveTokenMutation, RemoveTokenMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useMutation<RemoveTokenMutation, RemoveTokenMutationVariables>(RemoveTokenDocument, options);
}
export type RemoveTokenMutationHookResult = ReturnType<typeof useRemoveTokenMutation>;
export type RemoveTokenMutationResult = ApolloReactCommon.MutationResult<RemoveTokenMutation>;
export type RemoveTokenMutationOptions = ApolloReactCommon.BaseMutationOptions<RemoveTokenMutation, RemoveTokenMutationVariables>;
export const UserDataDocument = gql`
query UserData {
getUser {
Expand Down
110 changes: 55 additions & 55 deletions website/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type Incremental<T> = 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; }
Expand Down Expand Up @@ -822,6 +822,14 @@ export type VerifyAccountMutationVariables = Exact<{

export type VerifyAccountMutation = { __typename?: 'Mutation', verifyAccount: boolean };

export type FeedbackQueryVariables = Exact<{
offset?: InputMaybe<Scalars['Int']['input']>;
show?: InputMaybe<Scalars['Int']['input']>;
}>;


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; }>;


Expand All @@ -832,14 +840,6 @@ export type RedisChannelsQueryQueryVariables = Exact<{ [key: string]: never; }>;

export type RedisChannelsQueryQuery = { __typename?: 'Query', getRedisChannels: Array<string> };

export type FeedbackQueryVariables = Exact<{
offset?: InputMaybe<Scalars['Int']['input']>;
show?: InputMaybe<Scalars['Int']['input']>;
}>;


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'];
Expand Down Expand Up @@ -1879,6 +1879,52 @@ export function useVerifyAccountMutation(baseOptions?: Apollo.MutationHookOption
export type VerifyAccountMutationHookResult = ReturnType<typeof useVerifyAccountMutation>;
export type VerifyAccountMutationResult = Apollo.MutationResult<VerifyAccountMutation>;
export type VerifyAccountMutationOptions = Apollo.BaseMutationOptions<VerifyAccountMutation, VerifyAccountMutationVariables>;
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<FeedbackQuery, FeedbackQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<FeedbackQuery, FeedbackQueryVariables>(FeedbackDocument, options);
}
export function useFeedbackLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<FeedbackQuery, FeedbackQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<FeedbackQuery, FeedbackQueryVariables>(FeedbackDocument, options);
}
export type FeedbackQueryHookResult = ReturnType<typeof useFeedbackQuery>;
export type FeedbackLazyQueryHookResult = ReturnType<typeof useFeedbackLazyQuery>;
export type FeedbackQueryResult = Apollo.QueryResult<FeedbackQuery, FeedbackQueryVariables>;
export const GetUsersPerDomainDocument = gql`
query GetUsersPerDomain {
getUsersPerDomain {
Expand Down Expand Up @@ -1946,52 +1992,6 @@ export function useRedisChannelsQueryLazyQuery(baseOptions?: Apollo.LazyQueryHoo
export type RedisChannelsQueryQueryHookResult = ReturnType<typeof useRedisChannelsQueryQuery>;
export type RedisChannelsQueryLazyQueryHookResult = ReturnType<typeof useRedisChannelsQueryLazyQuery>;
export type RedisChannelsQueryQueryResult = Apollo.QueryResult<RedisChannelsQueryQuery, RedisChannelsQueryQueryVariables>;
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<FeedbackQuery, FeedbackQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<FeedbackQuery, FeedbackQueryVariables>(FeedbackDocument, options);
}
export function useFeedbackLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<FeedbackQuery, FeedbackQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<FeedbackQuery, FeedbackQueryVariables>(FeedbackDocument, options);
}
export type FeedbackQueryHookResult = ReturnType<typeof useFeedbackQuery>;
export type FeedbackLazyQueryHookResult = ReturnType<typeof useFeedbackLazyQuery>;
export type FeedbackQueryResult = Apollo.QueryResult<FeedbackQuery, FeedbackQueryVariables>;
export const GetBeepersDocument = gql`
query GetBeepers($latitude: Float!, $longitude: Float!, $radius: Float) {
getBeepers(latitude: $latitude, longitude: $longitude, radius: $radius) {
Expand Down

0 comments on commit 43b568b

Please sign in to comment.