Skip to content

Commit

Permalink
feat: Control different things, when is recipe owner
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmansilla committed Dec 7, 2023
1 parent 7b359e9 commit b48c051
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/RecipeDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ function RecipeDetail() {
<Offcanvas.Title className="fs-2 mt-3">Reviews</Offcanvas.Title>
</Offcanvas.Header>
<Offcanvas.Body style={{ backgroundColor: "#ffb79fe0" }}>
<Reviews id={id} reloadReviews={reloadReviewsFunction} />
<Reviews id={id} reloadReviews={reloadReviewsFunction} owner={username}/>
</Offcanvas.Body>
</Offcanvas>
<Modal
Expand Down
21 changes: 12 additions & 9 deletions src/components/Reviews.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ModifyReview from "./ModifyReview";


function Reviews(props) {
const { id, reloadReviews } = props;
const { id, reloadReviews, owner } = props;
const [reviews, setReviews] = useState(null);
const [showModal, setShowModal] = useState(false);
const [showModalImage, setShowModalImage] = useState(false);
Expand All @@ -17,7 +17,7 @@ function Reviews(props) {
const [selectedReview, setSelectedReview] = useState(null);
const [selectedFunct, setSelectedFunct] = useState(null);
const isLogged = window.localStorage.getItem("logged");
const currentUserUsername = localStorage.getItem('currentUser');
const currentUser = localStorage.getItem('currentUser');


useEffect(() => {
Expand Down Expand Up @@ -64,7 +64,7 @@ function Reviews(props) {
<Container className="flex-column justify-content-between align-items-center">
{isLogged === 'true' ?
<Row className="mt-2">
{reviews && reviews.length > 0 ? (<>
{reviews && reviews.length > 0 && owner === currentUser ? (<>
<Button className="mx-auto fs-6 bg-danger fw-bold border-secondary text-white" onClick={handleOpenModal}>
Post review
</Button>
Expand All @@ -80,7 +80,6 @@ function Reviews(props) {
<Col sm={12} className="mt-4 mx-auto">
<Container>
<ul className="list-unstyled">
{console.log(">>>>>REVIEWS:",reviews)}
{reviews && reviews.length > 0 ? (
reviews.map((review, index) => (
<li key={index} className="mb-3 p-2 fs-6 bg-light box-shadow">
Expand Down Expand Up @@ -135,7 +134,7 @@ function Reviews(props) {
likedBy={review.liked_by}
reloadReviews={reloadReviews}
/>
{currentUserUsername === review.username && (
{currentUser === review.username && (
<>
<PencilSquare
className="ms-2"
Expand All @@ -156,9 +155,9 @@ function Reviews(props) {
</Row>
</li>
))
) : (
<div className="text-center mt-5">
<h4 className="mb-3">There are currently no reviews.</h4>
) : ( owner !== currentUser ?
(<div className="text-center mt-5">
<h4 className="mb-3">There are currently no reviews</h4>
<p>Be the first one to post a review and share your thoughts!</p>
<Button className="mx-auto fs-6 bg-danger fw-bold border-secondary text-white" onClick={handleOpenModal}>
Post review
Expand All @@ -169,7 +168,11 @@ function Reviews(props) {
onHide={handleCloseModal}
reloadReviews={reloadReviews}
/>
</div>
</div>) : <div className="text-center mt-5">
<h4 className="mb-3">There are currently no reviews</h4>
{/* <p>Be the first one to post a review and share your thoughts!</p> */}
<p className="mb-3">You are the owner of the recipe you can't do reviews </p>
</div>
)}
</ul>
</Container>
Expand Down

0 comments on commit b48c051

Please sign in to comment.