-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReviewPage.js
137 lines (127 loc) · 3.88 KB
/
ReviewPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { useState, useEffect } from "react";
import { getReviews } from "../../api/thirdPartyApi.js";
import { Box, Text, Avatar, Stack, Divider } from "@chakra-ui/react";
import { StarIcon } from "@chakra-ui/icons";
function ReviewPage() {
const [apiData, setApiData] = useState(null);
const [isLoading, setIsLoading] = useState(true);
const [hasError, setHasError] = useState(false);
const getApiData = async () => {
try {
setIsLoading(true);
setHasError(false);
const reviews = await getReviews();
setApiData(reviews);
} catch (error) {
setHasError(true);
} finally {
setIsLoading(false);
}
};
useEffect(() => {
getApiData();
}, [setApiData]);
return (
<>
{hasError && <p>Something went wrong.</p>}
{isLoading ? (
<p>Loading ...</p>
) : (
<Box p="6">
<Box
mt="1"
fontWeight="semibold"
as="h1"
fontSize="4xl"
spacing="8"
noOfLines={1}
>
Hotel GURUPRASAD
</Box>
<Box
color="gray.500"
fontWeight="semibold"
letterSpacing="wide"
fontSize="md"
>
Ujire, Karnataka 574240, India
</Box>
<Box display="flex" alignItems="baseline">
<Box display="flex" mt="2" alignItems="center">
{Array(5)
.fill("")
.map((_, i) => (
<StarIcon
key={i}
color={
i < apiData.result.rating ? "orange.500" : "gray.300"
}
/>
))}
</Box>
<Box as="span" ml="2" color="gray.600" fontSize="sm">
{apiData.result.user_ratings_total} reviews
</Box>
</Box>
{/* Mapping*/}
{apiData.result.reviews.map((review) => {
return (
<Box key={review.time}>
<Box py={6} key={review.time}>
{" "}
<Stack spacing={8} direction="row">
{" "}
<Box>
<Avatar
mt="1"
ml="1"
size="md"
name={review.author_name}
src={review.author_url}
/>{" "}
</Box>{" "}
<Box>
{" "}
<Box
mt="1"
fontWeight="semibold"
as="h4"
lineHeight="tight"
noOfLines={1}
>
{review.author_name}
</Box>
<Box
color="gray.500"
fontWeight="semibold"
letterSpacing="wide"
fontSize="xs"
>
{review.relative_time_description}
</Box>
<Box display="flex" mt="2" alignItems="center">
{Array(5)
.fill("")
.map((_, i) => (
<StarIcon
key={i}
color={
i < review.rating ? "orange.500" : "gray.300"
}
/>
))}
</Box>
<Text>{review.text}</Text>
</Box>
</Stack>
</Box>
<Divider orientation="horizontal" />
</Box>
);
})}
</Box>
)}
</>
);
}
export default ReviewPage;