Skip to content

Commit 34374e3

Browse files
authored
Merge pull request #18 from PI-FindIt/FINDIT-163-Delete-finally-a-prod-from-list
add a fucking delete button finally
2 parents c2703a6 + 91f74e6 commit 34374e3

6 files changed

Lines changed: 46 additions & 407 deletions

File tree

app/(tabs)/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ export default function HomeScreen() {
225225
params: { id: item.ean },
226226
})
227227
}
228+
onPress={(item) =>
229+
router.push({
230+
pathname: "/productInfo",
231+
params: { id: item.ean },
232+
})
233+
}
228234
/>
229235
<View className="items-center pt-4">
230236
<Button

app/(tabs)/shopping-list.tsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { useCallback, useMemo, useRef, useState } from "react";
22
import { TouchableOpacity, useColorScheme, View } from "react-native";
33
import { useSafeAreaInsets } from "react-native-safe-area-context";
44
import {
5-
EllipsisVertical,
65
Mic,
76
NotebookPen,
87
Pencil,
98
Search,
109
Sparkles,
10+
Trash2,
1111
} from "lucide-react-native";
1212
import ListTitle from "@/components/ui/list/listTitle";
1313
import List from "@/components/ui/list/list";
@@ -105,6 +105,12 @@ const UPSERT_PRODUCT_FROM_LIST = gql(`
105105
}
106106
`);
107107

108+
const DELETE_PRODUCT_FROM_LIST = gql(`
109+
mutation DeleteProductFromList($ids: CompositeKeyInput!) {
110+
deleteProductFromList(ids: $ids)
111+
}
112+
`);
113+
108114
const ListScreen = () => {
109115
const { id } = useAuth();
110116
const insets = useSafeAreaInsets();
@@ -148,6 +154,16 @@ const ListScreen = () => {
148154
],
149155
});
150156

157+
const [deleteProductFromList] = useMutation(DELETE_PRODUCT_FROM_LIST, {
158+
refetchQueries: [
159+
{
160+
query: GET_PRODUCTS_LIST,
161+
variables: { userId: id },
162+
},
163+
],
164+
onError: toastOnError,
165+
});
166+
151167
useFocusEffect(
152168
useCallback(() => {
153169
refetch().catch(toastOnError);
@@ -439,13 +455,23 @@ const ListScreen = () => {
439455
supermarketId: e.supermarketInfo.id,
440456
type: e.type,
441457
}))}
442-
icon={EllipsisVertical}
458+
icon={Trash2}
443459
onIconPress={(item) =>
460+
deleteProductFromList({
461+
variables: {
462+
ids: {
463+
listId: data?.user?.actualList?._id || "",
464+
productEan: item.ean,
465+
},
466+
},
467+
})
468+
}
469+
onPress={(item) => {
444470
router.push({
445471
pathname: "/productInfo",
446472
params: { id: item.ean },
447-
})
448-
}
473+
});
474+
}}
449475
onQuantityPress={(item, type) =>
450476
handleQuantityPress(item, type)
451477
}

components/ListItem.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { LinearGradient } from "@/components/LinearGradient";
2-
import { TouchableOpacity, View } from "react-native";
2+
import { Pressable, TouchableOpacity, View } from "react-native";
33
import themeConfig from "@/tailwind.config";
44
import { ThemedView } from "@/components/ThemedView";
55
import { Image } from "expo-image";
@@ -19,6 +19,7 @@ import { ItemType } from "@/graphql/graphql";
1919
type InfoProps = {
2020
type: "info";
2121
item: ProductFiltered;
22+
onPress: (item: ProductFiltered) => void;
2223
};
2324

2425
type SearchProps = {
@@ -31,6 +32,7 @@ type ExtendedProps = {
3132
type: "extended";
3233
item: ProductFilteredExtended;
3334
onQuantityPress: (item: ProductFilteredExtended, type: "inc" | "dec") => void;
35+
onPress: (item: ProductFilteredExtended) => void;
3436
};
3537

3638
type ListItemProps = (InfoProps | SearchProps | ExtendedProps) &
@@ -45,13 +47,12 @@ const ListItem = (props: ListItemProps) => {
4547
const ItemWrapper = type === "search" ? TouchableOpacity : View;
4648

4749
return (
48-
<ItemWrapper
50+
<Pressable
4951
onPress={
50-
type === "search"
51-
? () => props.onPress(item as ProductFilteredSearch)
52-
: undefined
52+
// @ts-ignore
53+
() => props.onPress(item)
5354
}
54-
activeOpacity={0.8}
55+
className={"transition-opacity duration-150 active:opacity-70"}
5556
>
5657
<ContentWrapper
5758
direction="0deg"
@@ -160,7 +161,7 @@ const ListItem = (props: ListItemProps) => {
160161
)}
161162
</ThemedView>
162163
</ContentWrapper>
163-
</ItemWrapper>
164+
</Pressable>
164165
);
165166
};
166167

components/ui/list/list.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type InfoProps = {
1313
type: "info";
1414
items: ProductFiltered[];
15+
onPress: (item: ProductFiltered) => void;
1516
};
1617

1718
type SearchProps = {
@@ -24,6 +25,7 @@ type ExtendedProps = {
2425
type: "extended";
2526
items: ProductFilteredExtended[];
2627
onQuantityPress: (item: ProductFilteredExtended, type: "inc" | "dec") => void;
28+
onPress: (item: ProductFilteredExtended) => void;
2729
};
2830

2931
type ListProps = {

graphql/gql.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ type Documents = {
1919
"\n mutation AddTortillaProducts($models: [ListProductInput!]!) {\n upsertProductFromList(models: $models) {\n product {\n ean\n name\n quantity\n }\n }\n }\n": typeof types.AddTortillaProductsDocument;
2020
"\n mutation CreateList($userId: String!) {\n createList(userId: $userId) {\n _id\n products {\n product {\n name\n }\n }\n }\n }\n": typeof types.CreateListDocument;
2121
"\n query GetFilteredSupermarkets($userId: String!, $coordinateFilter: CoordinateFilter!) {\n user(id: $userId) {\n actualList {\n products {\n quantity\n supermarketInfo {\n price\n }\n }\n }\n }\n supermarketLocations(filters: { coordinates: $coordinateFilter }) {\n id\n latitude\n longitude\n supermarket {\n id\n name\n description\n image\n imageBlurhash\n services\n }\n }\n }\n": typeof types.GetFilteredSupermarketsDocument;
22-
"\n query CurrentSupermarketListWithProducts($userId: String!) {\n user(id: $userId) {\n actualList {\n _id\n raw\n status\n products {\n product {\n ean\n name\n genericName\n quantity\n images\n categoryName\n brandName\n blurhash\n }\n supermarketInfo {\n price\n id\n }\n quantity\n type\n }\n }\n }\n }\n": typeof types.CurrentSupermarketListWithProductsDocument;
23-
"\n query GetRecommendations($userId: String!) {\n rawListByUserAndAi(userId: $userId, k: 5) {\n ean\n name\n genericName\n quantity\n images\n brandName\n blurhash\n supermarkets {\n price\n id\n }\n }\n }\n": typeof types.GetRecommendationsDocument;
24-
"\n mutation UpsertProductFromList($models: [ListProductInput!]!) {\n upsertProductFromList(models: $models) {\n product {\n ean\n }\n quantity\n }\n }\n": typeof types.UpsertProductFromListDocument;
2522
"\n query GetProductSheet($ean: String!) {\n product(ean: $ean) {\n ean\n name\n images\n categoryName\n blurhash\n }\n }\n": typeof types.GetProductSheetDocument;
2623
"\n query GetProduct($ean: String!) {\n product(ean: $ean) {\n ean\n name\n genericName\n nutrition\n nutriScore\n ingredients\n quantity\n images\n categoryName\n keywords\n brandName\n blurhash\n supermarkets {\n price\n supermarket {\n id\n name\n logo\n logoBlurhash\n }\n }\n }\n }\n": typeof types.GetProductDocument;
2724
"\n query CurrentListId($userId: String!) {\n user(id: $userId) {\n actualList {\n _id\n }\n }\n }\n": typeof types.CurrentListIdDocument;
@@ -51,12 +48,6 @@ const documents: Documents = {
5148
types.CreateListDocument,
5249
"\n query GetFilteredSupermarkets($userId: String!, $coordinateFilter: CoordinateFilter!) {\n user(id: $userId) {\n actualList {\n products {\n quantity\n supermarketInfo {\n price\n }\n }\n }\n }\n supermarketLocations(filters: { coordinates: $coordinateFilter }) {\n id\n latitude\n longitude\n supermarket {\n id\n name\n description\n image\n imageBlurhash\n services\n }\n }\n }\n":
5350
types.GetFilteredSupermarketsDocument,
54-
"\n query CurrentSupermarketListWithProducts($userId: String!) {\n user(id: $userId) {\n actualList {\n _id\n raw\n status\n products {\n product {\n ean\n name\n genericName\n quantity\n images\n categoryName\n brandName\n blurhash\n }\n supermarketInfo {\n price\n id\n }\n quantity\n type\n }\n }\n }\n }\n":
55-
types.CurrentSupermarketListWithProductsDocument,
56-
"\n query GetRecommendations($userId: String!) {\n rawListByUserAndAi(userId: $userId, k: 5) {\n ean\n name\n genericName\n quantity\n images\n brandName\n blurhash\n supermarkets {\n price\n id\n }\n }\n }\n":
57-
types.GetRecommendationsDocument,
58-
"\n mutation UpsertProductFromList($models: [ListProductInput!]!) {\n upsertProductFromList(models: $models) {\n product {\n ean\n }\n quantity\n }\n }\n":
59-
types.UpsertProductFromListDocument,
6051
"\n query GetProductSheet($ean: String!) {\n product(ean: $ean) {\n ean\n name\n images\n categoryName\n blurhash\n }\n }\n":
6152
types.GetProductSheetDocument,
6253
"\n query GetProduct($ean: String!) {\n product(ean: $ean) {\n ean\n name\n genericName\n nutrition\n nutriScore\n ingredients\n quantity\n images\n categoryName\n keywords\n brandName\n blurhash\n supermarkets {\n price\n supermarket {\n id\n name\n logo\n logoBlurhash\n }\n }\n }\n }\n":
@@ -137,24 +128,6 @@ export function gql(
137128
export function gql(
138129
source: "\n query GetFilteredSupermarkets($userId: String!, $coordinateFilter: CoordinateFilter!) {\n user(id: $userId) {\n actualList {\n products {\n quantity\n supermarketInfo {\n price\n }\n }\n }\n }\n supermarketLocations(filters: { coordinates: $coordinateFilter }) {\n id\n latitude\n longitude\n supermarket {\n id\n name\n description\n image\n imageBlurhash\n services\n }\n }\n }\n",
139130
): (typeof documents)["\n query GetFilteredSupermarkets($userId: String!, $coordinateFilter: CoordinateFilter!) {\n user(id: $userId) {\n actualList {\n products {\n quantity\n supermarketInfo {\n price\n }\n }\n }\n }\n supermarketLocations(filters: { coordinates: $coordinateFilter }) {\n id\n latitude\n longitude\n supermarket {\n id\n name\n description\n image\n imageBlurhash\n services\n }\n }\n }\n"];
140-
/**
141-
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
142-
*/
143-
export function gql(
144-
source: "\n query CurrentSupermarketListWithProducts($userId: String!) {\n user(id: $userId) {\n actualList {\n _id\n raw\n status\n products {\n product {\n ean\n name\n genericName\n quantity\n images\n categoryName\n brandName\n blurhash\n }\n supermarketInfo {\n price\n id\n }\n quantity\n type\n }\n }\n }\n }\n",
145-
): (typeof documents)["\n query CurrentSupermarketListWithProducts($userId: String!) {\n user(id: $userId) {\n actualList {\n _id\n raw\n status\n products {\n product {\n ean\n name\n genericName\n quantity\n images\n categoryName\n brandName\n blurhash\n }\n supermarketInfo {\n price\n id\n }\n quantity\n type\n }\n }\n }\n }\n"];
146-
/**
147-
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
148-
*/
149-
export function gql(
150-
source: "\n query GetRecommendations($userId: String!) {\n rawListByUserAndAi(userId: $userId, k: 5) {\n ean\n name\n genericName\n quantity\n images\n brandName\n blurhash\n supermarkets {\n price\n id\n }\n }\n }\n",
151-
): (typeof documents)["\n query GetRecommendations($userId: String!) {\n rawListByUserAndAi(userId: $userId, k: 5) {\n ean\n name\n genericName\n quantity\n images\n brandName\n blurhash\n supermarkets {\n price\n id\n }\n }\n }\n"];
152-
/**
153-
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
154-
*/
155-
export function gql(
156-
source: "\n mutation UpsertProductFromList($models: [ListProductInput!]!) {\n upsertProductFromList(models: $models) {\n product {\n ean\n }\n quantity\n }\n }\n",
157-
): (typeof documents)["\n mutation UpsertProductFromList($models: [ListProductInput!]!) {\n upsertProductFromList(models: $models) {\n product {\n ean\n }\n quantity\n }\n }\n"];
158131
/**
159132
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
160133
*/

0 commit comments

Comments
 (0)