Skip to content

Commit

Permalink
feat: add delete recipe button
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-software committed Oct 19, 2021
1 parent 4f0db67 commit 73589ab
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 4 deletions.
69 changes: 69 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,39 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "deleteRecipe",
"description": null,
"args": [
{
"name": "recipeId",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "DeleteRecipeResult",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down Expand Up @@ -4708,6 +4741,42 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "DeleteRecipeResult",
"description": null,
"specifiedByUrl": null,
"fields": [
{
"name": "data",
"description": null,
"args": [],
"type": {
"kind": "OBJECT",
"name": "Recipe",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "error",
"description": null,
"args": [],
"type": {
"kind": "OBJECT",
"name": "Error",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "DietaryPreferenceDetails",
Expand Down
15 changes: 15 additions & 0 deletions src/graphql/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,18 @@ export const READ_NOTIFICATIONS = gql`
${Fragments.NotificationFragment}
${Fragments.ErrorFragment}
`;

export const DELETE_RECIPE = gql`
mutation DeleteRecipe($recipeId: String!) {
deleteRecipe(recipeId: $recipeId) {
data {
...RecipeFragment
}
error {
...ErrorFragment
}
}
}
${Fragments.RecipeFragment}
${Fragments.ErrorFragment}
`;
2 changes: 1 addition & 1 deletion src/graphql/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,4 @@ export const GET_NOTIFICATION_COUNT = gql`
}
}
${Fragments.ErrorFragment}
`;
`;
47 changes: 47 additions & 0 deletions src/screens/recipe/recipe-more-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { FC, useState } from "react";
import { Icon, Menu, MenuItem, Popover } from "@ui-kitten/components";
import { View } from "react-native";
import { useMutation } from "@apollo/client";
import { DeleteRecipe } from "@greeneggs/types/graphql";
import { Mutations, Queries } from "@greeneggs/graphql";
import { useNavigation } from "@react-navigation/core";

interface RecipeMoreButtonProps {
recipeId: string;
}

export const RecipeMoreButton: FC<RecipeMoreButtonProps> = ({ recipeId }) => {
const [visible, setVisible] = useState(false);
const navigation = useNavigation();
const [deleteRecipe] = useMutation<DeleteRecipe>(Mutations.DELETE_RECIPE, {
variables: {
recipeId,
},
});

function handleDeleteRecipe() {
deleteRecipe();
navigation.goBack();
}

return (
<Popover
visible={visible}
anchor={() => (
<Icon
name="more-vertical-outline"
fill="black"
style={{ width: 24, height: 24 }}
onPress={() => setVisible(true)}
/>
)}
onBackdropPress={() => setVisible(false)}
>
<View style={{ width: 132 }}>
<Menu>
<MenuItem title="DELETE RECIPE" onPress={() => handleDeleteRecipe()}/>
</Menu>
</View>
</Popover>
);
};
12 changes: 9 additions & 3 deletions src/screens/recipe/recipe.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useContext, useState } from "react";
import { useMutation, useQuery } from "@apollo/client";
import { ImageBackground, View, StyleSheet } from "react-native";
import { Mutations, Queries } from "@greeneggs/graphql";
Expand Down Expand Up @@ -27,6 +27,8 @@ import {
EmptyState,
Select,
} from "@greeneggs/ui";
import { RecipeMoreButton } from "./recipe-more-button";
import { UserContext } from "@greeneggs/providers";

const styles = StyleSheet.create({
coverPhoto: {
Expand Down Expand Up @@ -64,7 +66,8 @@ const styles = StyleSheet.create({
export const Recipe = ({ route, navigation }: any) => {
const { recipeId } = route.params;
const [servingCount, setServingCount] = useState<number | undefined>(undefined);
const [selectedIndex, setSelectedIndex] = useState<IndexPath | IndexPath[]>(new IndexPath(0))
const [selectedIndex, setSelectedIndex] = useState<IndexPath | IndexPath[]>(new IndexPath(0));
const { me } = useContext(UserContext);
const { loading, error, data } = useQuery<recipe, recipeVariables>(
Queries.GET_RECIPE,
{
Expand All @@ -87,7 +90,10 @@ export const Recipe = ({ route, navigation }: any) => {
<TopNavigation
style={{ height: 64, alignItems: "flex-start" }}
accessoryRight={() => (
<SaveRecipeButton recipeId={recipeId} saved={recipe.saved} />
<>
<SaveRecipeButton recipeId={recipeId} saved={recipe.saved} />
{ me?.id === recipe.submittedBy.id ? <RecipeMoreButton recipeId={recipeId} /> : undefined }
</>
)}
/>
)}
Expand Down
137 changes: 137 additions & 0 deletions src/types/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2642,6 +2642,143 @@ export interface NotificationCount {
// @generated
// This file was automatically generated and should not be edited.

// ====================================================
// GraphQL mutation operation: DeleteRecipe
// ====================================================

export interface DeleteRecipe_deleteRecipe_data_submittedBy {
__typename: "User";
id: string;
firstName: string;
lastName: string;
bio: string | null;
email: string;
avatarURI: string | null;
verified: boolean;
}

export interface DeleteRecipe_deleteRecipe_data_categories {
__typename: "Category";
id: string;
name: string;
}

export interface DeleteRecipe_deleteRecipe_data_diets {
__typename: "Diet";
name: string;
}

export interface DeleteRecipe_deleteRecipe_data_allergies {
__typename: "Allergy";
name: string;
}

export interface DeleteRecipe_deleteRecipe_data_ingredients {
__typename: "Ingredient";
name: string;
description: string | null;
quantity: number | null;
unit: string | null;
}

export interface DeleteRecipe_deleteRecipe_data_steps {
__typename: "RecipeStep";
title: string;
description: string;
image: string | null;
}

export interface DeleteRecipe_deleteRecipe_data_comments_submittedBy {
__typename: "User";
id: string;
firstName: string;
lastName: string;
bio: string | null;
email: string;
avatarURI: string | null;
verified: boolean;
}

export interface DeleteRecipe_deleteRecipe_data_comments_replies_submittedBy {
__typename: "User";
id: string;
firstName: string;
lastName: string;
bio: string | null;
email: string;
avatarURI: string | null;
verified: boolean;
}

export interface DeleteRecipe_deleteRecipe_data_comments_replies {
__typename: "RecipeCommentReply";
id: string;
contents: string;
likeCount: number;
replyCount: number;
liked: boolean;
submittedBy: DeleteRecipe_deleteRecipe_data_comments_replies_submittedBy;
}

export interface DeleteRecipe_deleteRecipe_data_comments {
__typename: "RecipeComment";
id: string;
contents: string;
likeCount: number;
replyCount: number;
liked: boolean;
createdAt: string;
deleted: boolean;
submittedBy: DeleteRecipe_deleteRecipe_data_comments_submittedBy;
replies: DeleteRecipe_deleteRecipe_data_comments_replies[];
}

export interface DeleteRecipe_deleteRecipe_data {
__typename: "Recipe";
id: string;
title: string;
description: string | null;
submittedBy: DeleteRecipe_deleteRecipe_data_submittedBy;
commentCount: number;
likeCount: number;
createdAt: string;
servingCount: number | null;
timeEstimate: string | null;
coverImage: string;
liked: boolean;
saved: boolean;
categories: DeleteRecipe_deleteRecipe_data_categories[];
diets: DeleteRecipe_deleteRecipe_data_diets[];
allergies: DeleteRecipe_deleteRecipe_data_allergies[];
ingredients: DeleteRecipe_deleteRecipe_data_ingredients[];
steps: DeleteRecipe_deleteRecipe_data_steps[];
comments: DeleteRecipe_deleteRecipe_data_comments[];
}

export interface DeleteRecipe_deleteRecipe_error {
__typename: "Error";
message: string;
}

export interface DeleteRecipe_deleteRecipe {
__typename: "DeleteRecipeResult";
data: DeleteRecipe_deleteRecipe_data | null;
error: DeleteRecipe_deleteRecipe_error | null;
}

export interface DeleteRecipe {
deleteRecipe: DeleteRecipe_deleteRecipe;
}

export interface DeleteRecipeVariables {
recipeId: string;
}

/* tslint:disable */
/* eslint-disable */
// @generated
// This file was automatically generated and should not be edited.

// ====================================================
// GraphQL fragment: UserFragment
// ====================================================
Expand Down

0 comments on commit 73589ab

Please sign in to comment.