Commit 56e5f7a2 authored by Daniel Puchala's avatar Daniel Puchala
Browse files

feat: review component delete button

parent de848f4e
......@@ -33,7 +33,7 @@ export const Movie = () => {
const reviewData = {
...data,
movieId: id,
userId: getUser().sub,
userId: getUser()!.sub,
};
console.log(reviewData)
await instance.post('reviews/create', reviewData, { headers });
......@@ -55,7 +55,6 @@ export const Movie = () => {
if (!recommended) return <div>loading...</div>;
const recommendedMovies = recommended.slice(0, 5)
console.log(reviews)
return (
<div>
......@@ -85,11 +84,17 @@ export const Movie = () => {
{recommendedMovies.map((movie: any) => <MovieCard key={movie.id} {...movie} mode={MovieCardMode.Recommend}/>)}
</div>
</div>
<div className={`h-full flex flex-col ${showReviews || 'hidden'}`}>
<div className={`h-full flex flex-col overflow-hidden ${showReviews || 'hidden'}`}>
<p className="text-2xl text-center font-bold">Reviews</p>
<div className="">
<div className="overflow-y-scroll">
{reviews.map((review: any) =>
<Review averageRating={getAverageRating(review)} text={review.text} userName={review.user.name} key={review.id}/>
<Review averageRating={
getAverageRating(review)}
userId={review.user.id}
text={review.text}
userName={review.user.name}
key={review.id}
/>
)}
</div>
{getUser() &&
......
import { getUser } from '../services/auth';
export interface ReviewProps {
userId: number,
text: string,
averageRating: number,
userName: string,
}
export const Review = ({text, averageRating, userName}: ReviewProps) => {
export const Review = ({userId, text, averageRating, userName}: ReviewProps) => {
const user = getUser();
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">
<div className="w-full h-40 p-2">
<div className="border-solid border-4 border-slate-900 bg-slate-300 w-full h-full p-2 ">
<div className="flex justify-between font-bold">
<p>Username: {userName}</p>
<p>Average Rating: {averageRating}</p>
{(user?.role === 'ADMIN' || user?.sub == userId) &&
(<button className="border-solid border-2 rounded-lg border-slate-900 p-1 bg-red-600">
Delete
</button>
)
}
</div>
<p>{text}</p>
</div>
......
......@@ -33,5 +33,5 @@ interface UserAuth {
iss: string,
name: string,
role: string,
sub: string
sub: number
}
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