From 674ee65c29c87236f1e707d8f06119f6f45d7739 Mon Sep 17 00:00:00 2001 From: KeviNmp4 Date: Sun, 12 May 2024 12:10:32 +0200 Subject: [PATCH 1/6] Added: check if beer was added, if not, show alert; Added packages picker,expo-camera --- frontend/app.json | 69 +- frontend/app/(app)/(tabs)/beer/add.js | 77 +- frontend/package-lock.json | 1848 ++++++++++--------------- frontend/package.json | 28 +- 4 files changed, 867 insertions(+), 1155 deletions(-) diff --git a/frontend/app.json b/frontend/app.json index 433b24a..35551c7 100644 --- a/frontend/app.json +++ b/frontend/app.json @@ -1,30 +1,43 @@ { - "expo": { - "name": "deguapp", - "slug": "deguapp", - "scheme": "deguapp", - "version": "1.0.0", - "orientation": "portrait", - "icon": "./assets/icon.png", - "userInterfaceStyle": "light", - "splash": { - "image": "./assets/splash.png", - "resizeMode": "contain", - "backgroundColor": "#ffffff" - }, - "assetBundlePatterns": ["**/*"], - "ios": { - "supportsTablet": true - }, - "android": { - "adaptiveIcon": { - "foregroundImage": "./assets/adaptive-icon.png", - "backgroundColor": "#ffffff" - } - }, - "web": { - "favicon": "./assets/favicon.png" - }, - "plugins": ["expo-router"] - } + "expo": { + "name": "deguapp", + "slug": "deguapp", + "scheme": "deguapp", + "version": "1.0.0", + "orientation": "portrait", + "icon": "./assets/icon.png", + "userInterfaceStyle": "light", + "splash": { + "image": "./assets/splash.png", + "resizeMode": "contain", + "backgroundColor": "#ffffff" + }, + "assetBundlePatterns": [ + "**/*" + ], + "ios": { + "supportsTablet": true + }, + "android": { + "adaptiveIcon": { + "foregroundImage": "./assets/adaptive-icon.png", + "backgroundColor": "#ffffff" + } + }, + "web": { + "favicon": "./assets/favicon.png" + }, + "plugins": [ + "expo-router", + [ + "expo-image-picker", + { + "photosPermission": "The app accesses your photos to let you share them with your friends.", + "cameraPermission": "The app accesses your camera to let you take photos of your beer and share them with your friends.", + "microphonePermission": "The app accesses your microphone to let you record audio and share it with your friends." + } + ], + "expo-secure-store" + ] + } } diff --git a/frontend/app/(app)/(tabs)/beer/add.js b/frontend/app/(app)/(tabs)/beer/add.js index 5fcb041..b9629e4 100644 --- a/frontend/app/(app)/(tabs)/beer/add.js +++ b/frontend/app/(app)/(tabs)/beer/add.js @@ -1,13 +1,34 @@ -import { StyleSheet, TextInput, View } from "react-native"; +import { StyleSheet, TextInput, View, Image } from "react-native"; import { useState } from "react"; import Button from "@components/Button"; import { colors } from "@components/style"; +import * as ImagePicker from "expo-image-picker"; +import { Picker } from "@react-native-picker/picker"; export default function BeerAdd() { const [b_name, setBName] = useState(""); const [b_degree, setBDegree] = useState(""); const [b_packaging, setBPackaging] = useState(""); const [b_brand, setBBrand] = useState(""); + const [image, setImage] = useState(null); + const [selectPackaging, setSelectedPackaging] = useState(); + + ImagePicker.getCameraPermissionsAsync(); //check if the user has granted permission to access the camera + const pickImage = async () => { + // No permissions request is necessary for launching the image library + let result = await ImagePicker.launchImageLibraryAsync({ + mediaTypes: ImagePicker.MediaTypeOptions.All, + allowsEditing: true, + aspect: [4, 3], + quality: 1, + }); + + console.log(result); + + if (!result.canceled) { + setImage(result.assets[0].uri); + } + }; async function addBeer() { // TODO: after the request - redirect to /beer/{new_beer_id}?; plus some modal about successful state @@ -24,6 +45,14 @@ export default function BeerAdd() { }), }); const res = await req.json(); + + if (res.success & res.new_beer_id) { + window.location.href = `/beer/${res.new_beer_id}`; + } else { + alert( + "Beer was not added successfully. Please check your data and try again.", + ); + } } return ( @@ -57,6 +86,27 @@ export default function BeerAdd() { onChangeText={(text) => setBPackaging(text)} placeholderTextColor="#aaaaaa" /> + + setSelectedPackaging(itemValue) + } + > + + + + + + + + +