Compare commits

..

2 Commits

Author SHA1 Message Date
b210c5a3e2 Fixes: #25 2024-05-13 16:52:20 +02:00
e6d26011cb Fixes: #15 2024-05-12 22:59:15 +02:00

View File

@ -5,19 +5,17 @@ import Text from "@components/Text";
import { colors } from "@components/style"; import { colors } from "@components/style";
import * as ImagePicker from "expo-image-picker"; import * as ImagePicker from "expo-image-picker";
import DropDownPicker from "react-native-dropdown-picker"; import DropDownPicker from "react-native-dropdown-picker";
/* import DropdownTheme from "@components/DropdownTheme"; */
const DropdownTheme = require("@components/DropdownTheme"); const DropdownTheme = require("@components/DropdownTheme");
import { Platform } from "react-native";
export default function BeerAdd() { export default function BeerAdd() {
const [b_name, setBName] = useState(""); const [b_name, setBName] = useState("");
const [b_degree, setBDegree] = useState(""); const [b_degree, setBDegree] = useState("");
const [b_packaging, setBPackaging] = useState(""); const [b_packaging, setBPackaging] = useState(null);
const [b_brand, setBBrand] = useState(""); const [b_brand, setBBrand] = useState("");
const [image, setImage] = useState(null); const [image, setImage] = useState(null);
const [selectPackaging, setSelectedPackaging] = useState();
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [value, setValue] = useState(null);
const [items, setItems] = useState([ const [items, setItems] = useState([
{ label: "Tank beer", value: "tank" }, { label: "Tank beer", value: "tank" },
{ label: "Cask beer", value: "cask" }, { label: "Cask beer", value: "cask" },
@ -74,6 +72,22 @@ export default function BeerAdd() {
} }
}; };
function validateDegreeInput(text) {
let newText = "";
let numbers = "0123456789.";
for (var i = 0; i < text.length; i++) {
if (numbers.indexOf(text[i]) > -1) {
newText = newText + text[i];
setBDegree(newText);
} else {
// your call back function
alert("Please enter numbers only.");
setBDegree("");
}
}
}
async function addBeer() { async function addBeer() {
// TODO: after the request - redirect to /beer/{new_beer_id}?; plus some modal about successful state // TODO: after the request - redirect to /beer/{new_beer_id}?; plus some modal about successful state
const req = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/beer/add`, { const req = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/beer/add`, {
@ -123,25 +137,22 @@ export default function BeerAdd() {
style={styles.input} style={styles.input}
placeholder="Degree" placeholder="Degree"
value={b_degree} value={b_degree}
onChangeText={(text) => setBDegree(text)} onChangeText={(text) => validateDegreeInput(text)}
placeholderTextColor="#aaaaaa"
/>
<TextInput
style={styles.input}
placeholder="Packaging"
value={b_packaging}
onChangeText={(text) => setBPackaging(text)}
placeholderTextColor="#aaaaaa" placeholderTextColor="#aaaaaa"
keyboardType="numeric"
maxLength={3}
/> />
<DropDownPicker <DropDownPicker
open={open} open={open}
value={value} value={b_packaging}
items={items} items={items}
setOpen={setOpen} setOpen={setOpen}
setValue={setValue} setValue={setBPackaging}
setItems={setItems} setItems={setItems}
placeholder={"What are you drinking from?"} placeholder={"What are you drinking from?"}
theme="DropdownTheme" theme="DropdownTheme"
//searchable={true} //maybe we can use it later...
/> />
<View style={styles.imageContainer}> <View style={styles.imageContainer}>
<Button <Button
@ -151,12 +162,16 @@ export default function BeerAdd() {
textStyle={styles.imageTextButton} textStyle={styles.imageTextButton}
/> />
<Button {Platform.OS != "web" ? (
onPress={openCamera} <Button
title="Open camera" onPress={openCamera}
buttonStyle={styles.imageButton} title={"Open camera"}
textStyle={styles.imageTextButton} buttonStyle={styles.imageButton}
/> textStyle={styles.imageTextButton}
/>
) : (
false
)}
{image && <Image source={{ uri: image }} style={styles.image} />} {image && <Image source={{ uri: image }} style={styles.image} />}
</View> </View>