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..15efe05 100644 --- a/frontend/app/(app)/(tabs)/beer/add.js +++ b/frontend/app/(app)/(tabs)/beer/add.js @@ -1,13 +1,78 @@ -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 Text from "@components/Text"; import { colors } from "@components/style"; +import * as ImagePicker from "expo-image-picker"; +import DropDownPicker from "react-native-dropdown-picker"; +/* import DropdownTheme from "@components/DropdownTheme"; */ +const DropdownTheme = require("@components/DropdownTheme"); 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(); + + const [open, setOpen] = useState(false); + const [value, setValue] = useState(null); + const [items, setItems] = useState([ + { label: "Tank beer", value: "tank" }, + { label: "Cask beer", value: "cask" }, + { label: "Glass bottle", value: "glass" }, + { label: "Can", value: "can" }, + { label: "PET bottle", value: "pet" }, + ]); + + DropDownPicker.addTheme("DropdownTheme", DropdownTheme); + DropDownPicker.setTheme("DropdownTheme"); + + ImagePicker.getCameraPermissionsAsync(); //check if the user has granted permission to access the camera + const pickImage = async () => { + const permissionResult = + await ImagePicker.requestMediaLibraryPermissionsAsync(); + + if (permissionResult.granted === false) { + alert("You've refused to allow this appp to access your photos!"); + return; + } + + // No permissions request is necessary for launching the image library + const result = await ImagePicker.launchImageLibraryAsync({ + mediaTypes: ImagePicker.MediaTypeOptions.Images, + allowsEditing: true, + aspect: [3, 4], + // quality: 1, + }); + + // Explore the result + console.log(result); + + if (!result.canceled) { + setImage(result.assets[0].uri); + } + }; + + const openCamera = async () => { + // Ask the user for the permission to access the camera + const permissionResult = await ImagePicker.requestCameraPermissionsAsync(); + + if (permissionResult.granted === false) { + alert("You've refused to allow this app to access your camera!"); + return; + } + + const result = await ImagePicker.launchCameraAsync(); + + // Explore the result + 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,11 +89,22 @@ export default function BeerAdd() { }), }); const res = await req.json(); + + if (res.code == 201 && res.data._id) { + window.location.href = `/beer/${res.data._id}`; + } else { + alert( + "Beer was not added successfully. Please check your data and try again.", + ); + } } return ( + + Spill your thoughts about the beer you just sipped! + setBPackaging(text)} placeholderTextColor="#aaaaaa" /> -