Skip to content

Commit

Permalink
Merge pull request #131 from thasup/dev
Browse files Browse the repository at this point in the history
Change side product image styles
  • Loading branch information
thasup committed Apr 21, 2023
2 parents c3121c3 + 6e807b3 commit d2b1dca
Show file tree
Hide file tree
Showing 5 changed files with 304 additions and 276 deletions.
184 changes: 92 additions & 92 deletions client/components/account/UserReviewList.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
import { faInfoCircle } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import Link from "next/link";
import React from "react";
import { Button, Col, Row, Table } from "react-bootstrap";

import CustomTooltip from "../common/CustomTooltip";
import Rating from "../common/Rating";

const UserReviewList = ({ myReviews, products }) => {
return (
<Row className="align-items-center">
<Col>
<Table striped bordered hover responsive className="table-sm">
<thead>
<tr>
<th>ID</th>
<th>PRODUCT</th>
<th>MY RATING</th>
<th>OVERALL RATING</th>
<th>TITLE</th>
<th>DATE</th>
<th>TIME</th>
<th>DETAILS</th>
</tr>
</thead>
<tbody>
{myReviews.map((review, index) => (
<tr key={review.id}>
<td>
<CustomTooltip index={index} mongoId={review.id} />{" "}
</td>
<td>
<Link
href={`/products/[productId]`}
as={`/products/${review.productId}`}
>
<a>
{review.productTitle
? review.productTitle
: products.find(
(product) => product.id === review.productId
)?.title}
</a>
</Link>
</td>
<td>
<Rating value={review.rating} mobile={false} /> (
{review.rating})
</td>
<td>
<Rating
value={
products.find(
(product) => product.id === review.productId
)?.rating
}
mobile={false}
/>
(
{
products.find((product) => product.id === review.productId)
?.rating
}
)
</td>
<td>{review.title}</td>
<td>{review.createdAt.substring(0, 10)}</td>
<td>
{new Date(`${review.createdAt}`).toString().substring(16, 21)}
</td>
<td>
<Link
href={"/products/[productId]"}
as={`/products/${review.productId}`}
passHref
>
<Button className="btn-sm" variant="light">
<FontAwesomeIcon icon={faInfoCircle} /> Details
</Button>
</Link>
</td>
</tr>
))}
</tbody>
</Table>
</Col>
</Row>
);
};

export default UserReviewList;
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import Link from 'next/link';
import React from 'react';
import { Button, Col, Row, Table } from 'react-bootstrap';

import CustomTooltip from '../common/CustomTooltip';
import Rating from '../common/Rating';

const UserReviewList = ({ myReviews, products }) => {
return (
<Row className="align-items-center">
<Col>
<Table striped bordered hover responsive className="table-sm">
<thead>
<tr>
<th>ID</th>
<th>PRODUCT</th>
<th>MY RATING</th>
<th>OVERALL RATING</th>
<th>TITLE</th>
<th>DATE</th>
<th>TIME</th>
<th>DETAILS</th>
</tr>
</thead>
<tbody>
{myReviews.map((review, index) => (
<tr key={review.id}>
<td>
<CustomTooltip index={index} mongoId={review.id} />{' '}
</td>
<td>
<Link
href={'/products/[productId]'}
as={`/products/${review.productId}`}
>
<a>
{review.productTitle
? review.productTitle
: products.find(
(product) => product.id === review.productId
)?.title}
</a>
</Link>
</td>
<td>
<Rating value={review.rating} mobile={false} /> (
{review.rating})
</td>
<td>
<Rating
value={
products.find(
(product) => product.id === review.productId
)?.rating
}
mobile={false}
/>
(
{
products.find((product) => product.id === review.productId)
?.rating
}
)
</td>
<td>{review.title}</td>
<td>{review.createdAt.substring(0, 10)}</td>
<td>
{new Date(`${review.createdAt}`).toString().substring(16, 21)}
</td>
<td>
<Link
href={'/products/[productId]'}
as={`/products/${review.productId}`}
passHref
>
<Button className="btn-sm" variant="light">
<FontAwesomeIcon icon={faInfoCircle} /> Details
</Button>
</Link>
</td>
</tr>
))}
</tbody>
</Table>
</Col>
</Row>
);
};

export default UserReviewList;
22 changes: 17 additions & 5 deletions client/components/common/Rating.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import React from 'react';
import PropTypes from 'prop-types';
import { OverlayTrigger, Tooltip } from 'react-bootstrap';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faStar, faStarHalfAlt } from '@fortawesome/free-solid-svg-icons';
import { faStar as farfaStar } from '@fortawesome/free-regular-svg-icons';

const Rating = ({ value, text, color, mobile = false }) => {
const Rating = ({ value, numReviews, color, mobile = false }) => {
const renderTooltip = (props) => (
<Tooltip id="button-tooltip" {...props}>
{numReviews} {numReviews < 2 ? 'review' : 'reviews'}
</Tooltip>
);
return mobile
? (
<div className="rating">
<div className="rating unselectable">
<span style={{ color }}>
{value >= 5
? (
Expand All @@ -25,7 +31,7 @@ const Rating = ({ value, text, color, mobile = false }) => {
</div>
)
: (
<div className="rating">
<div className="rating unselectable">
<span>
{[1, 2, 3, 4, 5].map((index) => (
<span key={index} style={{ color }}>
Expand All @@ -44,7 +50,13 @@ const Rating = ({ value, text, color, mobile = false }) => {
))}
</span>

<span> {text && text}</span>
<OverlayTrigger
placement="top"
delay={{ show: 50, hide: 0 }}
overlay={renderTooltip}
>
<span> {numReviews && `(${numReviews})`}</span>
</OverlayTrigger>
</div>
);
};
Expand All @@ -55,7 +67,7 @@ Rating.defaultProps = {

Rating.propTypes = {
value: PropTypes.number.isRequired,
text: PropTypes.string,
numReviews: PropTypes.number,
color: PropTypes.string
};

Expand Down
2 changes: 1 addition & 1 deletion client/components/home/Product.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const Product = ({
<Col xs={5} className="card-product-reviews" as="div">
<Rating
value={product.rating}
text={`(${product.numReviews})`}
numReviews={product.numReviews}
mobile={!!onMobile}
/>
</Col>
Expand Down
Loading

0 comments on commit d2b1dca

Please sign in to comment.