import { StyleSheet, TextInput, View, Image } from "react-native"; import { useCallback, 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"; const DropdownTheme = require("@components/DropdownTheme"); import { Platform } from "react-native"; import { useLocalSearchParams } from "expo-router"; export default function reviewAdd() { // States for each dropdown const routeParams = useLocalSearchParams(); const [openFoam, setOpenFoam] = useState(false); const [openBitterSweetness, setOpenBitterSweetness] = useState(false); const [openTaste, setOpenTaste] = useState(false); const [openPackaging, setOpenPackaging] = useState(false); const [openSourness, setOpenSourness] = useState(false); const [openAgain, setOpenAgain] = useState(false); // pěna const [itemFoam, setFoamValue] = useState(null); const [foam, setFoam] = useState([ { label: "Bad", value: "1", icon: () => ( ), }, { label: "Medium", value: "2", icon: () => ( ), }, { label: "Excellent", value: "3", icon: () => ( ), }, ]); // hořkost / sladkost const [itemBitter_sweetness, setBitter_sweetnessValue] = useState(null); const [bitter_sweetness, setBitter_sweetness] = useState([ { label: "Bad", value: "1", icon: () => ( ), }, { label: "Medium", value: "2", icon: () => ( ), }, { label: "Excellent", value: "3", icon: () => ( ), }, ]); //chuť const [itemTaste, setTasteValue] = useState(null); const [taste, setTaste] = useState([ { label: "Disgust", value: "1", icon: () => ( ), }, { label: "Not great, not terrible", value: "2", icon: () => ( ), }, { label: "Good", value: "3", icon: () => ( ), }, { label: "Why not", value: "4", icon: () => ( ), }, { label: "Excellent!", value: "5", icon: () => ( ), }, ]); // packaging const [itemPackaging, setPackagingValue] = useState(null); const [packaging, setPackaging] = useState([ { label: "Disgust", value: "1", icon: () => ( ), }, { label: "Not great, not terrible", value: "2", icon: () => ( ), }, { label: "Good", value: "3", icon: () => ( ), }, { label: "Why not", value: "4", icon: () => ( ), }, { label: "Excellent!", value: "5", icon: () => ( ), }, ]); //kyselost const [itemSourness, setSournessValue] = useState(null); const [sourness, setSourness] = useState([ { label: "True", value: true, icon: () => ( ), }, { label: "False", value: false, icon: () => ( ), }, ]); //dal bych si znovu? const [itemAgain, setAgainValue] = useState(null); const [again, setAgain] = useState([ { label: "Yes", value: true, icon: () => ( ), }, { label: "No", value: false, icon: () => ( ), }, ]); //podmínky pro zavření ostatních dropdownů, pokud je jiný otevřený const onOpenFoam = useCallback(() => { setOpenBitterSweetness(false); setOpenTaste(false); setOpenPackaging(false); setOpenSourness(false); setOpenAgain(false); setOpenFoam(true); }, []); const onOpenBitterSweetness = useCallback(() => { setOpenFoam(false); setOpenTaste(false); setOpenPackaging(false); setOpenSourness(false); setOpenAgain(false); setOpenBitterSweetness(true); }, []); const onOpenTaste = useCallback(() => { setOpenFoam(false); setOpenBitterSweetness(false); setOpenPackaging(false); setOpenSourness(false); setOpenAgain(false); setOpenTaste(true); }, []); const onOpenPackaging = useCallback(() => { setOpenFoam(false); setOpenBitterSweetness(false); setOpenTaste(false); setOpenSourness(false); setOpenAgain(false); setOpenPackaging(true); }, []); const onOpenSourness = useCallback(() => { setOpenFoam(false); setOpenBitterSweetness(false); setOpenTaste(false); setOpenPackaging(false); setOpenAgain(false); setOpenSourness(true); }, []); const onOpenAgain = useCallback(() => { setOpenFoam(false); setOpenBitterSweetness(false); setOpenTaste(false); setOpenPackaging(false); setOpenSourness(false); setOpenAgain(true); }, []); DropDownPicker.addTheme("DropdownTheme", DropdownTheme); DropDownPicker.setTheme("DropdownTheme"); async function addBeer() { const req = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/review/add`, { method: "POST", credentials: "include", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ beer_id: routeParams.beer_id, foam: itemFoam, bitter_sweetness: itemBitter_sweetness, taste: itemTaste, packaging: itemPackaging, sourness: itemSourness, would_again: itemAgain, }), }); const res = await req.json(); if (res.code == 201 && res.data._id) { // window.location.href = `/review/${res.data._id}`; // TODO: use react router for redirect alert("Review was added!"); } else { alert( "Review was not added successfully. Please check your data and try again.", ); } } return ( How does your beer taste? Write a review! How does the foam look like? More bitter, or more sweet? How does it taste? How do you like the packaging? Is it sour? Would you drink it again?