2024-05-14 22:47:13 +02:00
|
|
|
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";
|
2024-05-15 02:04:16 +02:00
|
|
|
import { useAuth } from "@context/AuthContext";
|
2024-05-14 22:47:13 +02:00
|
|
|
|
|
|
|
export default function Tab() {
|
2024-05-15 02:04:16 +02:00
|
|
|
const { authState } = useAuth();
|
|
|
|
const user = authState.user;
|
2024-05-14 22:47:13 +02:00
|
|
|
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",
|
|
|
|
});
|
2024-05-15 02:04:16 +02:00
|
|
|
let data = await res.json();
|
|
|
|
// show only logged in user's data
|
|
|
|
data = data.data.filter((review) => review.user_id == user._id);
|
2024-05-15 02:33:26 +02:00
|
|
|
|
|
|
|
let beers = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/beer/get`, {
|
|
|
|
method: "GET",
|
|
|
|
credentials: "include",
|
|
|
|
});
|
|
|
|
beers = await beers.json();
|
|
|
|
beers = beers.data;
|
|
|
|
console.log(beers);
|
|
|
|
|
|
|
|
async function getBeerParam(search, beers) {
|
|
|
|
for (let i = 0; i < beers.length; i++) {
|
|
|
|
if (beers[i]._id == search) {
|
|
|
|
return beers[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.forEach(async (el) => {
|
|
|
|
el.beer = await getBeerParam(el.beer_id, beers);
|
|
|
|
});
|
|
|
|
|
2024-05-15 02:04:16 +02:00
|
|
|
console.log("reviews", data);
|
|
|
|
setData(data);
|
2024-05-14 22:47:13 +02:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
alert("Something went wrong");
|
|
|
|
}
|
|
|
|
}
|
2024-05-15 02:04:58 +02:00
|
|
|
const opt3 = ["Bad", "Medium", "Excellent!"];
|
|
|
|
const opt5 = [
|
|
|
|
"Disgust",
|
|
|
|
"Not great, not terrible",
|
|
|
|
"Good",
|
|
|
|
"Why not?",
|
|
|
|
"Excellent!",
|
|
|
|
];
|
2024-05-15 02:29:42 +02:00
|
|
|
const opt2 = ["Yes", "No"];
|
|
|
|
const sourness = ["Good", "Bad"];
|
2024-05-14 22:47:13 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<FlatList
|
|
|
|
data={data}
|
|
|
|
style={styles.reviewList}
|
|
|
|
keyExtractor={(item) => String(item._id)}
|
|
|
|
renderItem={({ item }) => (
|
|
|
|
<View style={styles.item}>
|
2024-05-15 02:29:42 +02:00
|
|
|
<Text>Foam → {opt3[item.foam - 1]}</Text>
|
|
|
|
<Text>Bitter / Sweetness → {opt3[item.bitter_sweetness - 1]}</Text>
|
|
|
|
<Text>Taste → {opt5[item.taste - 1]}</Text>
|
|
|
|
<Text>Packaging → {opt5[item.packaging - 1]}</Text>
|
|
|
|
<Text>Sourness → {sourness[item.sourness - 1]}</Text>
|
|
|
|
<Text>Would again? → {opt2[item.would_again - 1]}</Text>
|
2024-05-14 22:47:13 +02:00
|
|
|
</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%",
|
|
|
|
},
|
|
|
|
});
|