katoikia-app/mobile-ui/components/Home.js

66 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-08-22 23:51:55 +00:00
import{Box, ScrollView} from "native-base";
2022-08-22 20:22:27 +00:00
import React, { useContext, useEffect, useState } from "react";
import { UserContext } from "../context/UserContext";
import { API } from "../environment/api";
import { CommentCard } from "./CommentCard";
export default function Home() {
const { user } = useContext(UserContext)
const [isRequesting, setIsRequesting] = useState(false);
const [comments, setComments] = useState([]);
useEffect(() => {
const onRequestCommentsData = async () => {
setIsRequesting(true);
try {
const jsonResponse = await fetch(`${API.BASE_URL}/post/allComments`, {
method: "GET",
headers: {
'Content-Type': 'application/json'
}
})
const response = await jsonResponse.json();
2022-08-23 00:10:59 +00:00
console.log(response);
2022-08-22 20:22:27 +00:00
setComments(response.message);
} catch (error) {
}
setIsRequesting(false)
}
onRequestCommentsData()
}, [user])
return (
<Box alignItems="center">
<ScrollView width='100%' h='550' ml='1' _contentContainerStyle={{
px: "20px",
mb: "4",
minW: "72"
}}>
{
comments.map(item => (
<CommentCard
key={item._id}
comment={item.comment}
date={item.date_entry}
/>
))
}
2022-08-22 06:51:05 +00:00
</ScrollView>
2022-08-17 16:36:33 +00:00
</Box>
2022-08-22 20:22:27 +00:00
)
}