Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete #149

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 65 additions & 150 deletions src/CartItem.css
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
/* CartItem.css */
/* CartItem.css */

.cart-item {
display: flex;
border-bottom: 1px solid #ccc;
padding: 10px 0;
background-color: white;
width: 500px;
gap: 30px;
position: relative; /* Ensure relative positioning for inner absolute elements */
}

.cart-item-image {
.cart-item-image-container {
position: relative; /* Allow absolute positioning inside */
width: 200px;
height: 200px;
/* object-fit: contain; */
margin-right: 20px;
}

.cart-item-image {
width: 100%; /* Ensure image takes up the entire container */
height: 100%;
object-fit: cover; /* Ensure image covers the container area */
}

.cart-item-text-overlay {
position: absolute;
top: 50%; /* Center vertically */
left: 50%; /* Center horizontally */
transform: translate(-50%, -50%); /* Adjust to truly center */
color: white; /* Text color */
font-size: 2rem; /* Adjust font size */
font-weight: bold; /* Make the text bold */
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7); /* Add shadow for better contrast */
pointer-events: none; /* Allow clicks to pass through the text */
}

.cart-item-details {
flex-grow: 1;
}
Expand Down Expand Up @@ -73,24 +89,23 @@
.cart-item-delete:hover {
background-color: #cc0000;
}
/* .cart-item-button-dec{
background-color: red;
}
.cart-item-button-inc{
background-color: green;
} */

@media (max-width: 768px) {
.cart-item {
flex-direction: column; /* Change flex direction to stack items vertically */
align-items: flex-start; /* Align items to the start of the container */
width: 100%; /* Set width to full width */
}

.cart-item-image {
width: 100%; /* Set image width to full width */
height: auto; /* Allow image height to adjust proportionally */
.cart-item-image-container {
width: 100%; /* Ensure image container takes up full width */
height: auto; /* Adjust height */
margin-right: 0; /* Remove margin */
margin-bottom: 10px; /* Add margin bottom for spacing */
}

.cart-item-image {
width: 100%; /* Make image take up the full width of the container */
height: auto; /* Adjust image height proportionally */
}

.cart-item-details {
Expand All @@ -101,143 +116,43 @@
margin-top: 10px; /* Add margin top for spacing */
}
}
.cart-item {
display: flex;
border-bottom: 1px solid #ccc;
padding: 10px 0;
background-color: white;
width: 500px;
gap: 30px;
}

.cart-item-image {
width: 200px;
height: 200px;
/* object-fit: contain; */
margin-right: 20px;
}

.cart-item-details {
flex-grow: 1;
}

.cart-item-name {
font-weight: bold;
margin-bottom: 5px;
font-size: 25px;
}

.cart-item-cost {
margin-bottom: 10px;
margin-top: 10px;
}

.cart-item-quantity {
display: flex;
align-items: center;
margin-bottom: 15px;
}

.cart-item-button {
background-color: #f0f0f0;
border: 1px solid lightgrey;
color: #333;
font-size: 18px;
cursor: pointer;
padding: 5px 10px;
margin: 0 5px;
border-radius: 5px;
}

.cart-item-quantity-value {
font-size: 16px;
font-weight: bold;
margin: 0 10px;
}

.cart-item-total {
font-weight: bold;
}

.cart-item-delete {
background-color: #ff6961;
border: none;
color: #fff;
font-size: 14px;
cursor: pointer;
padding: 10px 15px;
margin-top: 10px;
border-radius: 10px;
}

.cart-item-delete:hover {
background-color: #cc0000;
}
/* .cart-item-button-dec{
background-color: red;
}
.cart-item-button-inc{
background-color: green;
} */
@media (max-width: 768px) {
.cart-item {
flex-direction: column; /* Change flex direction to stack items vertically */
align-items: flex-start; /* Align items to the start of the container */
width: 100%; /* Set width to full width */
}

.cart-item-image {
width: 100%; /* Set image width to full width */
height: auto; /* Allow image height to adjust proportionally */
margin-right: 0; /* Remove margin */
margin-bottom: 10px; /* Add margin bottom for spacing */
}

.cart-item-details {
width: 100%; /* Set details width to full width */
}

.cart-item-quantity {
margin-top: 10px; /* Add margin top for spacing */
}
}


.cart-container{
/* text-align: center; */
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
gap: 20px;
margin-top: 20px;
}
.total_cart_amount{
font-size: 20px;
font-weight: 900;
}
.continue_shopping_btn{

.cart-container {
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
gap: 20px;
margin-top: 20px;
}

.total_cart_amount {
font-size: 20px;
font-weight: 900;
}

.continue_shopping_btn {
margin-top: -50px;
}
@media (max-width: 768px) {
.cart-container {
padding: 10px; /* Reduce padding */
}

.total_cart_amount {
font-size: 18px; /* Reduce font size */
}

.get-started-button1 {
padding: 15px 75px;
font-size: 23px;
border: none;
border-radius: 5px;
background-color: #4caf50;
color: white;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 40px;
}

@media (max-width: 768px) {
.cart-container {
padding: 10px; /* Reduce padding */
}

.get-started-button1 {
padding: 15px 75px;
font-size: 23px;
border: none;
border-radius: 5px;
background-color: #4caf50;
color: white;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 40px;
.total_cart_amount {
font-size: 18px; /* Reduce font size */
}
}
16 changes: 12 additions & 4 deletions src/CartItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,46 @@ import React from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { removeItem, updateQuantity } from './CartSlice';
import './CartItem.css';
import { addItem } from './CartSlice';

const CartItem = ({ onContinueShopping }) => {
const cart = useSelector(state => state.cart.items);
const dispatch = useDispatch();

// Calculate total amount for all products in the cart
const calculateTotalAmount = () => {

return cart.reduce((total, item) => total + Number(item.cost.substring(1)) * item.quantity, 0);
};

const handleContinueShopping = (e) => {

onContinueShopping(e);
};



const handleIncrement = (item) => {
dispatch(updateQuantity({ name: item.name, quantity: item.quantity + 1 }));
};

const handleDecrement = (item) => {

if (item.quantity <= 1) {
dispatch(removeItem(item.name));
} else {
dispatch(updateQuantity({ name: item.name, quantity: item.quantity - 1 }));
}
};

const handleRemove = (item) => {
dispatch(removeItem(item.name));
};

// Calculate total cost based on quantity for an item
const calculateTotalCost = (item) => {
return Number(item.cost.substring(1)) * item.quantity;
};

return (
<div className="cart-container">
<h2 style={{ color: 'black' }}>Total Plants : {cart.length}</h2>
<h2 style={{ color: 'black' }}>Total Cart Amount: ${calculateTotalAmount()}</h2>
<div>
{cart.map(item => (
Expand Down
17 changes: 14 additions & 3 deletions src/CartSlice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@ export const CartSlice = createSlice({
},
reducers: {
addItem: (state, action) => {

const { name, image, cost } = action.payload;
const existingItem = state.items.find(item => item.name === name);
if (existingItem) {
existingItem.quantity++;
} else {
state.items.push({ name, image, cost, quantity: 1 });
}
},
removeItem: (state, action) => {
state.items = state.items.filter(item => item.name !== action.payload);
},
updateQuantity: (state, action) => {


updateQuantity: (state, action) => {
const { name, quantity } = action.payload;
const itemToUpdate = state.items.find(item => item.name === name);
if (itemToUpdate) {
itemToUpdate.quantity = quantity;
}
},
},
});
Expand Down
24 changes: 23 additions & 1 deletion src/ProductList.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import React, { useState,useEffect } from 'react';
import './ProductList.css'
import CartItem from './CartItem';
import { addItem } from './CartSlice';
import { useDispatch } from 'react-redux';
function ProductList() {
const dispatch = useDispatch();
const [showCart, setShowCart] = useState(false);
const [showPlants, setShowPlants] = useState(false); // State to control the visibility of the About Us page
const [addedToCart, setAddedToCart] = useState({});
const handleAddToCart = (plant) => {
dispatch(addItem(plant));
console.log('yay'); // Ensure addItem is correctly imported and used
};

const plantsArray = [
{
Expand Down Expand Up @@ -268,7 +276,21 @@ const handlePlantsClick = (e) => {
</div>
{!showCart? (
<div className="product-grid">

{plantsArray.map((category, index) => (
<div key={index}>
<h1><div>{category.category}</div></h1>
<div className="product-list">
{category.plants.map((plant, plantIndex) => (
<div className="product-card" key={plantIndex}>
<img className="product-image" src={plant.image} alt={plant.name} />
<div className="product-title">{plant.name}</div>
{/*Similarly like the above plant.name show other details like description and cost*/}
<button className="product-button" onClick={() => handleAddToCart(plant)}>Add to Cart</button>
</div>
))}
</div>
</div>
))}

</div>
) : (
Expand Down