Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ export default function HomeScreen() {
params: { id: item.ean },
})
}
onPress={(item) =>
router.push({
pathname: "/productInfo",
params: { id: item.ean },
})
}
/>
<View className="items-center pt-4">
<Button
Expand Down
34 changes: 30 additions & 4 deletions app/(tabs)/shopping-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { useCallback, useMemo, useRef, useState } from "react";
import { TouchableOpacity, useColorScheme, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import {
EllipsisVertical,
Mic,
NotebookPen,
Pencil,
Search,
Sparkles,
Trash2,
} from "lucide-react-native";
import ListTitle from "@/components/ui/list/listTitle";
import List from "@/components/ui/list/list";
Expand Down Expand Up @@ -105,6 +105,12 @@ const UPSERT_PRODUCT_FROM_LIST = gql(`
}
`);

const DELETE_PRODUCT_FROM_LIST = gql(`
mutation DeleteProductFromList($ids: CompositeKeyInput!) {
deleteProductFromList(ids: $ids)
}
`);

const ListScreen = () => {
const { id } = useAuth();
const insets = useSafeAreaInsets();
Expand Down Expand Up @@ -148,6 +154,16 @@ const ListScreen = () => {
],
});

const [deleteProductFromList] = useMutation(DELETE_PRODUCT_FROM_LIST, {
refetchQueries: [
{
query: GET_PRODUCTS_LIST,
variables: { userId: id },
},
],
onError: toastOnError,
});

useFocusEffect(
useCallback(() => {
refetch().catch(toastOnError);
Expand Down Expand Up @@ -439,13 +455,23 @@ const ListScreen = () => {
supermarketId: e.supermarketInfo.id,
type: e.type,
}))}
icon={EllipsisVertical}
icon={Trash2}
onIconPress={(item) =>
deleteProductFromList({
variables: {
ids: {
listId: data?.user?.actualList?._id || "",
productEan: item.ean,
},
},
})
}
onPress={(item) => {
router.push({
pathname: "/productInfo",
params: { id: item.ean },
})
}
});
}}
onQuantityPress={(item, type) =>
handleQuantityPress(item, type)
}
Expand Down
15 changes: 8 additions & 7 deletions components/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LinearGradient } from "@/components/LinearGradient";
import { TouchableOpacity, View } from "react-native";
import { Pressable, TouchableOpacity, View } from "react-native";
import themeConfig from "@/tailwind.config";
import { ThemedView } from "@/components/ThemedView";
import { Image } from "expo-image";
Expand All @@ -19,6 +19,7 @@ import { ItemType } from "@/graphql/graphql";
type InfoProps = {
type: "info";
item: ProductFiltered;
onPress: (item: ProductFiltered) => void;
};

type SearchProps = {
Expand All @@ -31,6 +32,7 @@ type ExtendedProps = {
type: "extended";
item: ProductFilteredExtended;
onQuantityPress: (item: ProductFilteredExtended, type: "inc" | "dec") => void;
onPress: (item: ProductFilteredExtended) => void;
};

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

return (
<ItemWrapper
<Pressable
onPress={
type === "search"
? () => props.onPress(item as ProductFilteredSearch)
: undefined
// @ts-ignore
() => props.onPress(item)
}
activeOpacity={0.8}
className={"transition-opacity duration-150 active:opacity-70"}
>
<ContentWrapper
direction="0deg"
Expand Down Expand Up @@ -160,7 +161,7 @@ const ListItem = (props: ListItemProps) => {
)}
</ThemedView>
</ContentWrapper>
</ItemWrapper>
</Pressable>
);
};

Expand Down
2 changes: 2 additions & 0 deletions components/ui/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
type InfoProps = {
type: "info";
items: ProductFiltered[];
onPress: (item: ProductFiltered) => void;
};

type SearchProps = {
Expand All @@ -24,6 +25,7 @@ type ExtendedProps = {
type: "extended";
items: ProductFilteredExtended[];
onQuantityPress: (item: ProductFilteredExtended, type: "inc" | "dec") => void;
onPress: (item: ProductFilteredExtended) => void;
};

type ListProps = {
Expand Down
27 changes: 0 additions & 27 deletions graphql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ type Documents = {
"\n mutation AddTortillaProducts($models: [ListProductInput!]!) {\n upsertProductFromList(models: $models) {\n product {\n ean\n name\n quantity\n }\n }\n }\n": typeof types.AddTortillaProductsDocument;
"\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;
"\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;
"\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;
"\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;
"\n mutation UpsertProductFromList($models: [ListProductInput!]!) {\n upsertProductFromList(models: $models) {\n product {\n ean\n }\n quantity\n }\n }\n": typeof types.UpsertProductFromListDocument;
"\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;
"\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;
"\n query CurrentListId($userId: String!) {\n user(id: $userId) {\n actualList {\n _id\n }\n }\n }\n": typeof types.CurrentListIdDocument;
Expand Down Expand Up @@ -51,12 +48,6 @@ const documents: Documents = {
types.CreateListDocument,
"\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":
types.GetFilteredSupermarketsDocument,
"\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":
types.CurrentSupermarketListWithProductsDocument,
"\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":
types.GetRecommendationsDocument,
"\n mutation UpsertProductFromList($models: [ListProductInput!]!) {\n upsertProductFromList(models: $models) {\n product {\n ean\n }\n quantity\n }\n }\n":
types.UpsertProductFromListDocument,
"\n query GetProductSheet($ean: String!) {\n product(ean: $ean) {\n ean\n name\n images\n categoryName\n blurhash\n }\n }\n":
types.GetProductSheetDocument,
"\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":
Expand Down Expand Up @@ -137,24 +128,6 @@ export function gql(
export function gql(
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",
): (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"];
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function gql(
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",
): (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"];
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function gql(
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",
): (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"];
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function gql(
source: "\n mutation UpsertProductFromList($models: [ListProductInput!]!) {\n upsertProductFromList(models: $models) {\n product {\n ean\n }\n quantity\n }\n }\n",
): (typeof documents)["\n mutation UpsertProductFromList($models: [ListProductInput!]!) {\n upsertProductFromList(models: $models) {\n product {\n ean\n }\n quantity\n }\n }\n"];
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Loading
Loading