Skip to content

Commit

Permalink
add stars
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolaus-B committed Mar 24, 2024
1 parent 16af31b commit f921a20
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/components/Car/Car.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
HeadInfocontainer,
LocationAndRating,
PriceContainer,
ReviewsAndStarContainer,
ShowMoreBtn,
TagsContainer,
} from "./Car.styled";
Expand Down Expand Up @@ -59,9 +60,11 @@ export const Car = ({ car, hidden }) => {
</PriceContainer>
</HeadInfocontainer>
<LocationAndRating>
<p>
{car.rating} <span>{car.reviews.length || 0} Reviews</span>
</p>
<ReviewsAndStarContainer>
<Icon width={16} height={16} iconId={"star-yellow"} />
<p>{car.rating}</p>
<span>{car.reviews.length || 0} Reviews</span>
</ReviewsAndStarContainer>
<p>{car.location}</p>
</LocationAndRating>
<Desctiption>{car.description}</Desctiption>
Expand Down
7 changes: 7 additions & 0 deletions src/components/Car/Car.styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ export const LocationAndRating = styled.div`
gap: 16px;
`;

export const ReviewsAndStarContainer = styled.div`
display: flex;
justify-content: center;
align-items: center;
gap: 4px;
`;

export const Location = styled.p``;

export const Desctiption = styled.p`
Expand Down
3 changes: 3 additions & 0 deletions src/components/FeaturesPopUp/FeaturesPopUp.styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const FeaturedHead = styled.p`

export const InfoContainer = styled.div`
margin-top: 24px;
display: flex;
flex-direction: column;
gap: 14px;
`;

export const InfoWrapper = styled.div`
Expand Down
24 changes: 22 additions & 2 deletions src/components/ReviewsPopUp/ReviewsPopUp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,32 @@ import {
ReviewImageLetter,
ReviewList,
ReviewerName,
StarsContainer,
} from "./ReviewsPopUp.styled";
import { Icon } from "../Icon/Icon";

export const ReviewsPopUp = ({ reviews }) => {
const renderStars = (rating) => {
const yellowStars = Math.floor(rating);
const grayStars = 5 - yellowStars;

const stars = [];
for (let i = 0; i < yellowStars; i++) {
stars.push(
<Icon width={16} height={16} key={`star-${i}`} iconId={"star-yellow"} />
);
}
for (let i = 0; i < grayStars; i++) {
stars.push(
<Icon width={16} height={16} key={`gray-star-${i}`} iconId={"star"} />
);
}
return stars;
};
return (
<div>
<ReviewList>
{reviews.map((review) => {
console.log(review);
return (
<Review key={uid()}>
<ReviewHeader>
Expand All @@ -27,7 +45,9 @@ export const ReviewsPopUp = ({ reviews }) => {
<ReviewerName>
{review.reviewer_name ? review.reviewer_name : "anonim"}
</ReviewerName>
<div></div>
<StarsContainer>
{renderStars(review.reviewer_rating)}
</StarsContainer>
</ReviewHeaderWrapper>
</ReviewHeader>
<ReviewComment>{review.comment}</ReviewComment>
Expand Down
6 changes: 6 additions & 0 deletions src/components/ReviewsPopUp/ReviewsPopUp.styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export const ReviewHeader = styled.div`
margin-bottom: 16px;
`;

export const StarsContainer = styled.div`
display: flex;
gap: 4px;
margin-top: 4px;
`;

export const ReviewImageLetter = styled.p`
display: flex;
justify-content: center;
Expand Down

0 comments on commit f921a20

Please sign in to comment.