Commit de848f4e authored by Daniel Puchala's avatar Daniel Puchala
Browse files

feat: review component added

parent 65f80627
......@@ -9,6 +9,12 @@ import useSWR from 'swr';
import fetcher from '../models/fetcher';
import { getToken, getUser } from '../services/auth';
import formatDuration from '../services/formatDuration';
import review from './Review';
import Review from './Review';
function getAverageRating(review: any) {
return (review.actingRating + review.ideaRating + review.scriptRating + review.musicRating + review.visualsEditRating) / 5
}
export const Movie = () => {
const [ showReviews, setShowReviews ] = useState<boolean>(false);
......@@ -49,6 +55,7 @@ export const Movie = () => {
if (!recommended) return <div>loading...</div>;
const recommendedMovies = recommended.slice(0, 5)
console.log(reviews)
return (
<div>
......@@ -81,8 +88,9 @@ export const Movie = () => {
<div className={`h-full flex flex-col ${showReviews || 'hidden'}`}>
<p className="text-2xl text-center font-bold">Reviews</p>
<div className="">
//TODO After get reviews
{reviews.map((review: any) =>
<Review averageRating={getAverageRating(review)} text={review.text} userName={review.user.name} key={review.id}/>
)}
</div>
{getUser() &&
<form
......
export interface ReviewProps {
text: string,
averageRating: number,
userName: string,
}
export const Review = ({text, averageRating, userName}: ReviewProps) => {
return (
<div className="w-full h-40 p-4">
<div className="border-solid border-4 border-slate-900 bg-slate-300 w-full h-full p-2">
<div className="flex justify-between">
<p>Username: {userName}</p>
<p>Average Rating: {averageRating}</p>
</div>
<p>{text}</p>
</div>
</div>
)
};
export default Review;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment