2024-05-14 22:11:23 +02:00
|
|
|
import {
|
|
|
|
StyleSheet,
|
|
|
|
View,
|
|
|
|
FlatList,
|
|
|
|
Dimensions,
|
|
|
|
StatusBar,
|
2024-05-15 00:42:18 +02:00
|
|
|
Image,
|
2024-05-14 22:11:23 +02:00
|
|
|
} from "react-native";
|
2024-05-08 21:18:47 +02:00
|
|
|
import Text from "@components/Text";
|
|
|
|
import Button from "@components/Button";
|
|
|
|
import { colors } from "@components/style";
|
|
|
|
import { router } from "expo-router";
|
2024-05-08 23:39:49 +02:00
|
|
|
import { useEffect, useState } from "react";
|
2024-05-15 00:42:18 +02:00
|
|
|
// import { FlashList } from "@shopify/flash-list";
|
2024-05-08 21:18:47 +02:00
|
|
|
|
|
|
|
export default function Tab() {
|
2024-05-15 00:42:18 +02:00
|
|
|
const API_HOST = process.env.EXPO_PUBLIC_API_URL.replace("/api/v1", "");
|
2024-05-08 23:39:49 +02:00
|
|
|
const [data, setData] = useState([]);
|
|
|
|
useEffect(() => {
|
|
|
|
fetchData();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
async function fetchData() {
|
|
|
|
try {
|
|
|
|
const res = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/beer/get`, {
|
|
|
|
method: "GET",
|
|
|
|
credentials: "include",
|
|
|
|
});
|
|
|
|
const data = await res.json();
|
|
|
|
setData(data.data);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
alert("Something went wrong");
|
|
|
|
}
|
|
|
|
}
|
2024-05-08 21:18:47 +02:00
|
|
|
|
2024-05-08 23:39:49 +02:00
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2024-05-08 21:18:47 +02:00
|
|
|
<Button
|
2024-05-14 22:11:23 +02:00
|
|
|
title="Add new beer"
|
2024-05-08 21:18:47 +02:00
|
|
|
color={colors.gold}
|
|
|
|
onPress={() => {
|
|
|
|
router.replace("/beer/add");
|
|
|
|
}}
|
|
|
|
/>
|
2024-05-08 23:39:49 +02:00
|
|
|
|
2024-05-14 22:44:32 +02:00
|
|
|
{/* <FlashList
|
2024-05-14 22:11:23 +02:00
|
|
|
data={data}
|
|
|
|
estimatedItemSize={100}
|
|
|
|
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>
|
|
|
|
)}
|
|
|
|
/> */}
|
|
|
|
|
2024-05-14 22:44:32 +02:00
|
|
|
<FlatList
|
|
|
|
data={data}
|
|
|
|
style={styles.beerList}
|
|
|
|
keyExtractor={(item) => String(item._id)}
|
|
|
|
renderItem={({ item }) => (
|
|
|
|
<View style={styles.item}>
|
2024-05-15 00:42:18 +02:00
|
|
|
<Image
|
|
|
|
source={
|
|
|
|
item.imgs[0]
|
|
|
|
? {
|
|
|
|
uri: `${API_HOST}/public/uploads/${item.imgs[0]}`,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
uri: "https://imagesvc.meredithcorp.io/v3/mm/image?url=https:%2F%2Fstatic.onecms.io%2Fwp-content%2Fuploads%2Fsites%2F44%2F2020%2F09%2F29%2Flight-beer.jpg",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
style={styles.itemImg}
|
|
|
|
/>
|
|
|
|
<View style={styles.itemDesc}>
|
|
|
|
<Text>Name: {item.name}</Text>
|
|
|
|
<Text>Brand: {item.brand}</Text>
|
|
|
|
<Text>Degree: {item.degree}</Text>
|
|
|
|
<Text>Packaging: {item.packaging}</Text>
|
|
|
|
</View>
|
|
|
|
<View style={styles.itemAddReview}>
|
|
|
|
<Button
|
|
|
|
title="Add review"
|
|
|
|
color={colors.gold}
|
|
|
|
onPress={() => {
|
|
|
|
router.push(`/review/${item._id}`);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</View>
|
2024-05-14 22:44:32 +02:00
|
|
|
</View>
|
|
|
|
)}
|
|
|
|
/>
|
2024-05-08 21:18:47 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2024-05-08 23:39:49 +02:00
|
|
|
|
|
|
|
export const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: "center",
|
|
|
|
alignItems: "center",
|
2024-05-14 22:44:32 +02:00
|
|
|
marginTop: "2%",
|
2024-05-08 23:39:49 +02:00
|
|
|
},
|
|
|
|
beerList: {
|
|
|
|
width: "100%",
|
|
|
|
paddingHorizontal: "15%",
|
2024-05-14 22:11:23 +02:00
|
|
|
marginTop: "2%",
|
2024-05-08 23:39:49 +02:00
|
|
|
},
|
|
|
|
item: {
|
|
|
|
borderColor: "gray",
|
|
|
|
borderWidth: 1,
|
|
|
|
borderRadius: 10,
|
|
|
|
padding: 13,
|
|
|
|
marginBottom: "5%",
|
|
|
|
},
|
2024-05-15 00:42:18 +02:00
|
|
|
itemImg: {
|
|
|
|
height: 300,
|
|
|
|
resizeMode: "contain",
|
|
|
|
},
|
|
|
|
itemDesc: {
|
|
|
|
alignItems: "center",
|
|
|
|
paddingBottom: "2%",
|
|
|
|
},
|
2024-05-08 23:39:49 +02:00
|
|
|
});
|