Added: folder with routes to review and add review page, added package RangeSlider; in _layout.js added add review as invisible
This commit is contained in:
		@@ -43,7 +43,7 @@ export default function TabLayout() {
 | 
			
		||||
					}}
 | 
			
		||||
				/>
 | 
			
		||||
				<Tabs.Screen
 | 
			
		||||
					name="review"
 | 
			
		||||
					name="review/index"
 | 
			
		||||
					options={{
 | 
			
		||||
						title: "Reviews",
 | 
			
		||||
						tabBarIcon: ({ color }) => (
 | 
			
		||||
@@ -66,6 +66,10 @@ export default function TabLayout() {
 | 
			
		||||
					name="beer/add"
 | 
			
		||||
					options={{ href: null, title: "Add beer" }}
 | 
			
		||||
				/>
 | 
			
		||||
				<Tabs.Screen
 | 
			
		||||
					name="review/add"
 | 
			
		||||
					options={{ href: null, title: "Add review" }}
 | 
			
		||||
				/>
 | 
			
		||||
			</Tabs>
 | 
			
		||||
		</View>
 | 
			
		||||
	);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
import { View } from "react-native";
 | 
			
		||||
import Text from "@components/Text";
 | 
			
		||||
 | 
			
		||||
export default function Tab() {
 | 
			
		||||
	return (
 | 
			
		||||
		<View style={{ justifyContent: "center", alignItems: "center", flex: 1 }}>
 | 
			
		||||
			<Text>Tab REVIEW</Text>
 | 
			
		||||
		</View>
 | 
			
		||||
	);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								frontend/app/(app)/(tabs)/review/.index.js.swp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								frontend/app/(app)/(tabs)/review/.index.js.swp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										233
									
								
								frontend/app/(app)/(tabs)/review/add.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										233
									
								
								frontend/app/(app)/(tabs)/review/add.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,233 @@
 | 
			
		||||
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";
 | 
			
		||||
const DropdownTheme = require("@components/DropdownTheme");
 | 
			
		||||
import { Platform } from "react-native";
 | 
			
		||||
import RangeSlider, { Slider } from "react-native-range-slider-expo";
 | 
			
		||||
 | 
			
		||||
export default function reviewAdd() {
 | 
			
		||||
	const [b_name, setBName] = useState("");
 | 
			
		||||
	const [b_degree, setBDegree] = useState("");
 | 
			
		||||
	const [b_packaging, setBPackaging] = useState(null);
 | 
			
		||||
	const [b_brand, setBBrand] = useState("");
 | 
			
		||||
	const [image, setImage] = useState(null);
 | 
			
		||||
 | 
			
		||||
	const [open, setOpen] = useState(false);
 | 
			
		||||
	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);
 | 
			
		||||
		}
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	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() {
 | 
			
		||||
		// 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`, {
 | 
			
		||||
			method: "POST",
 | 
			
		||||
			credentials: "include",
 | 
			
		||||
			headers: { "Content-Type": "application/json" },
 | 
			
		||||
			body: JSON.stringify({
 | 
			
		||||
				brand: b_brand,
 | 
			
		||||
				name: b_name,
 | 
			
		||||
				degree: b_degree,
 | 
			
		||||
				packaging: b_packaging,
 | 
			
		||||
				photos: null,
 | 
			
		||||
			}),
 | 
			
		||||
		});
 | 
			
		||||
		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 (
 | 
			
		||||
		<View style={styles.container}>
 | 
			
		||||
			<View style={styles.form}>
 | 
			
		||||
				<Text style={styles.text}>
 | 
			
		||||
					Spill your thoughts about the beer you just sipped!
 | 
			
		||||
				</Text>
 | 
			
		||||
				<TextInput
 | 
			
		||||
					style={styles.input}
 | 
			
		||||
					placeholder="Name"
 | 
			
		||||
					value={b_name}
 | 
			
		||||
					onChangeText={(text) => setBName(text)}
 | 
			
		||||
					placeholderTextColor="#aaaaaa"
 | 
			
		||||
				/>
 | 
			
		||||
				<TextInput
 | 
			
		||||
					style={styles.input}
 | 
			
		||||
					placeholder="Brand"
 | 
			
		||||
					value={b_brand}
 | 
			
		||||
					onChangeText={(text) => setBBrand(text)}
 | 
			
		||||
					placeholderTextColor="#aaaaaa"
 | 
			
		||||
				/>
 | 
			
		||||
				<TextInput
 | 
			
		||||
					style={styles.input}
 | 
			
		||||
					placeholder="Degree"
 | 
			
		||||
					value={b_degree}
 | 
			
		||||
					onChangeText={(text) => validateDegreeInput(text)}
 | 
			
		||||
					placeholderTextColor="#aaaaaa"
 | 
			
		||||
					keyboardType="numeric"
 | 
			
		||||
					maxLength={3}
 | 
			
		||||
				/>
 | 
			
		||||
 | 
			
		||||
				<DropDownPicker
 | 
			
		||||
					open={open}
 | 
			
		||||
					value={b_packaging}
 | 
			
		||||
					items={items}
 | 
			
		||||
					setOpen={setOpen}
 | 
			
		||||
					setValue={setBPackaging}
 | 
			
		||||
					setItems={setItems}
 | 
			
		||||
					placeholder={"What are you drinking from?"}
 | 
			
		||||
					theme="DropdownTheme"
 | 
			
		||||
					//searchable={true} //maybe we can use it later...
 | 
			
		||||
				/>
 | 
			
		||||
				{/* 				<View style={styles.imageContainer}>
 | 
			
		||||
					<Button
 | 
			
		||||
						title="Open gallery"
 | 
			
		||||
						onPress={pickImage}
 | 
			
		||||
						buttonStyle={styles.imageButton}
 | 
			
		||||
						textStyle={styles.imageTextButton}
 | 
			
		||||
					/>
 | 
			
		||||
 | 
			
		||||
					{Platform.OS != "web" ? (
 | 
			
		||||
						<Button
 | 
			
		||||
							onPress={openCamera}
 | 
			
		||||
							title={"Open camera"}
 | 
			
		||||
							buttonStyle={styles.imageButton}
 | 
			
		||||
							textStyle={styles.imageTextButton}
 | 
			
		||||
						/>
 | 
			
		||||
					) : (
 | 
			
		||||
						false
 | 
			
		||||
					)}
 | 
			
		||||
 | 
			
		||||
					{image && <Image source={{ uri: image }} style={styles.image} />}
 | 
			
		||||
				</View> */}
 | 
			
		||||
				<Button title="Add beer" color={colors.gold} onPress={addBeer} />
 | 
			
		||||
			</View>
 | 
			
		||||
		</View>
 | 
			
		||||
	);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const styles = StyleSheet.create({
 | 
			
		||||
	container: {
 | 
			
		||||
		width: "100%",
 | 
			
		||||
		height: "100%",
 | 
			
		||||
		alignItems: "center",
 | 
			
		||||
		display: "flex",
 | 
			
		||||
	},
 | 
			
		||||
	form: {
 | 
			
		||||
		alignItems: "center",
 | 
			
		||||
		gap: 15,
 | 
			
		||||
		width: "80%",
 | 
			
		||||
	},
 | 
			
		||||
	input: {
 | 
			
		||||
		height: "auto",
 | 
			
		||||
		width: "100%",
 | 
			
		||||
		borderColor: "gray",
 | 
			
		||||
		borderWidth: 1,
 | 
			
		||||
		borderRadius: 10,
 | 
			
		||||
		padding: 13,
 | 
			
		||||
		color: "#fff",
 | 
			
		||||
	},
 | 
			
		||||
	imageContainer: {
 | 
			
		||||
		alignItems: "center",
 | 
			
		||||
		justifyContent: "center",
 | 
			
		||||
		display: "flex",
 | 
			
		||||
		flexDirection: "row",
 | 
			
		||||
		gap: 10,
 | 
			
		||||
	},
 | 
			
		||||
	imageButton: {
 | 
			
		||||
		backgroundColor: colors.dark,
 | 
			
		||||
		borderColor: "gray",
 | 
			
		||||
		borderWidth: 1,
 | 
			
		||||
		borderRadius: 10,
 | 
			
		||||
	},
 | 
			
		||||
	imageTextButton: {
 | 
			
		||||
		color: colors.white,
 | 
			
		||||
	},
 | 
			
		||||
	image: {
 | 
			
		||||
		width: 150,
 | 
			
		||||
		height: 150,
 | 
			
		||||
	},
 | 
			
		||||
	text: {
 | 
			
		||||
		color: colors.white,
 | 
			
		||||
		fontSize: 24,
 | 
			
		||||
		textAlign: "center",
 | 
			
		||||
		paddingBottom: "3%",
 | 
			
		||||
		paddingTop: "10%",
 | 
			
		||||
	},
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										74
									
								
								frontend/app/(app)/(tabs)/review/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								frontend/app/(app)/(tabs)/review/index.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,74 @@
 | 
			
		||||
import { View, StyleSheet, FlatList } from "react-native";
 | 
			
		||||
import Text from "@components/Text";
 | 
			
		||||
import Button from "@components/Button";
 | 
			
		||||
import { colors } from "@components/style";
 | 
			
		||||
import { router } from "expo-router";
 | 
			
		||||
import { useEffect, useState } from "react";
 | 
			
		||||
 | 
			
		||||
export default function Tab() {
 | 
			
		||||
	const [data, setData] = useState([]);
 | 
			
		||||
	useEffect(() => {
 | 
			
		||||
		fetchData();
 | 
			
		||||
	}, []);
 | 
			
		||||
 | 
			
		||||
	async function fetchData() {
 | 
			
		||||
		try {
 | 
			
		||||
			const res = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/review/get`, {
 | 
			
		||||
				method: "GET",
 | 
			
		||||
				credentials: "include",
 | 
			
		||||
			});
 | 
			
		||||
			const data = await res.json();
 | 
			
		||||
			setData(data.data);
 | 
			
		||||
		} catch (err) {
 | 
			
		||||
			console.error(err);
 | 
			
		||||
			alert("Something went wrong");
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return (
 | 
			
		||||
		<View style={styles.container}>
 | 
			
		||||
			<Button
 | 
			
		||||
				title="Add Review"
 | 
			
		||||
				color={colors.gold}
 | 
			
		||||
				onPress={() => {
 | 
			
		||||
					router.replace("/review/add");
 | 
			
		||||
				}}
 | 
			
		||||
			/>
 | 
			
		||||
 | 
			
		||||
			<FlatList
 | 
			
		||||
				data={data}
 | 
			
		||||
				style={styles.reviewList}
 | 
			
		||||
				keyExtractor={(item) => String(item._id)}
 | 
			
		||||
				renderItem={({ item }) => (
 | 
			
		||||
					<View style={styles.item}>
 | 
			
		||||
						<Text>Name: {item.name}</Text>
 | 
			
		||||
						<Text>Brand: {item.brand}</Text>
 | 
			
		||||
						<Text>Degree: {item.degree}</Text>
 | 
			
		||||
						<Text>Packaging: {item.packaging}</Text>
 | 
			
		||||
					</View>
 | 
			
		||||
				)}
 | 
			
		||||
			/>
 | 
			
		||||
		</View>
 | 
			
		||||
	);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const styles = StyleSheet.create({
 | 
			
		||||
	container: {
 | 
			
		||||
		flex: 1,
 | 
			
		||||
		justifyContent: "center",
 | 
			
		||||
		alignItems: "center",
 | 
			
		||||
		marginTop: "5%",
 | 
			
		||||
	},
 | 
			
		||||
	reviewList: {
 | 
			
		||||
		width: "100%",
 | 
			
		||||
		paddingHorizontal: "15%",
 | 
			
		||||
		marginTop: "5%",
 | 
			
		||||
	},
 | 
			
		||||
	item: {
 | 
			
		||||
		borderColor: "gray",
 | 
			
		||||
		borderWidth: 1,
 | 
			
		||||
		borderRadius: 10,
 | 
			
		||||
		padding: 13,
 | 
			
		||||
		marginBottom: "5%",
 | 
			
		||||
	},
 | 
			
		||||
});
 | 
			
		||||
		Reference in New Issue
	
	Block a user