-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductList.jsx
308 lines (299 loc) · 14 KB
/
ProductList.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import React, { useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { addItem } from './CreatSlice';
import './ProductList.css';
function ProductList({ onViewCartClick }) {
const dispatch = useDispatch();
const cartItemsCount = useSelector(state => state.cart.items.reduce((total, item) => total + item.quantity, 0));
const [addedToCart, setAddedToCart] = useState({});
const handleAddToCart = (plant) => {
dispatch(addItem(plant));
setAddedToCart((prevState) => ({
...prevState,
[plant.name]: true
}));
};
const plantsArray = [
{
category: "Air Purifying Plants",
plants: [
{
name: "Snake Plant",
image: "https://cdn.pixabay.com/photo/2021/01/22/06/04/snake-plant-5939187_1280.jpg",
description: "Produces oxygen at night, improving air quality.",
cost: "$15"
},
{
name: "Spider Plant",
image: "https://cdn.pixabay.com/photo/2018/07/11/06/47/chlorophytum-3530413_1280.jpg",
description: "Filters formaldehyde and xylene from the air.",
cost: "$12"
},
{
name: "Peace Lily",
image: "https://cdn.pixabay.com/photo/2019/06/12/14/14/peace-lilies-4269365_1280.jpg",
description: "Removes mold spores and purifies the air.",
cost: "$18"
},
{
name: "Boston Fern",
image: "https://cdn.pixabay.com/photo/2020/04/30/19/52/boston-fern-5114414_1280.jpg",
description: "Adds humidity to the air and removes toxins.",
cost: "$20"
},
{
name: "Rubber Plant",
image: "https://cdn.pixabay.com/photo/2020/02/15/11/49/flower-4850729_1280.jpg",
description: "Easy to care for and effective at removing toxins.",
cost: "$17"
},
{
name: "Aloe Vera",
image: "https://cdn.pixabay.com/photo/2018/04/02/07/42/leaf-3283175_1280.jpg",
description: "Purifies the air and has healing properties for skin.",
cost: "$14"
}
]
},
{
category: "Aromatic Fragrant Plants",
plants: [
{
name: "Lavender",
image: "https://images.unsplash.com/photo-1611909023032-2d6b3134ecba?q=80&w=1074&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
description: "Calming scent, used in aromatherapy.",
cost: "$20"
},
{
name: "Jasmine",
image: "https://images.unsplash.com/photo-1592729645009-b96d1e63d14b?q=80&w=1170&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
description: "Sweet fragrance, promotes relaxation.",
cost: "$18"
},
{
name: "Rosemary",
image: "https://cdn.pixabay.com/photo/2019/10/11/07/12/rosemary-4541241_1280.jpg",
description: "Invigorating scent, often used in cooking.",
cost: "$15"
},
{
name: "Mint",
image: "https://cdn.pixabay.com/photo/2016/01/07/18/16/mint-1126282_1280.jpg",
description: "Refreshing aroma, used in teas and cooking.",
cost: "$12"
},
{
name: "Lemon Balm",
image: "https://cdn.pixabay.com/photo/2019/09/16/07/41/balm-4480134_1280.jpg",
description: "Citrusy scent, relieves stress and promotes sleep.",
cost: "$14"
},
{
name: "Hyacinth",
image: "https://cdn.pixabay.com/photo/2019/04/07/20/20/hyacinth-4110726_1280.jpg",
description: "Hyacinth is a beautiful flowering plant known for its fragrant.",
cost: "$22"
}
]
},
{
category: "Insect Repellent Plants",
plants: [
{
name: "oregano",
image: "https://cdn.pixabay.com/photo/2015/05/30/21/20/oregano-790702_1280.jpg",
description: "The oregano plants contains compounds that can deter certain insects.",
cost: "$10"
},
{
name: "Marigold",
image:"https://cdn.pixabay.com/photo/2022/02/22/05/45/marigold-7028063_1280.jpg",
description: "Natural insect repellent, also adds color to the garden.",
cost: "$8"
},
{
name: "Geraniums",
image: "https://cdn.pixabay.com/photo/2012/04/26/21/51/flowerpot-43270_1280.jpg",
description: "Known for their insect-repelling properties while adding a pleasant scent.",
cost: "$20"
},
{
name: "Basil",
image: "https://cdn.pixabay.com/photo/2016/07/24/20/48/tulsi-1539181_1280.jpg",
description: "Repels flies and mosquitoes, also used in cooking.",
cost: "$9"
},
{
name: "Lavender",
image: "https://images.unsplash.com/photo-1611909023032-2d6b3134ecba?q=80&w=1074&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
description: "Calming scent, used in aromatherapy.",
cost: "$20"
},
{
name: "Catnip",
image: "https://cdn.pixabay.com/photo/2015/07/02/21/55/cat-829681_1280.jpg",
description: "Repels mosquitoes and attracts cats.",
cost: "$13"
}
]
},
{
category: "Medicinal Plants",
plants: [
{
name: "Aloe Vera",
image: "https://cdn.pixabay.com/photo/2018/04/02/07/42/leaf-3283175_1280.jpg",
description: "Soothing gel used for skin ailments.",
cost: "$14"
},
{
name: "Echinacea",
image: "https://cdn.pixabay.com/photo/2014/12/05/03/53/echinacea-557477_1280.jpg",
description: "Boosts immune system, helps fight colds.",
cost: "$16"
},
{
name: "Peppermint",
image: "https://cdn.pixabay.com/photo/2017/07/12/12/23/peppermint-2496773_1280.jpg",
description: "Relieves digestive issues and headaches.",
cost: "$13"
},
{
name: "Lemon Balm",
image: "https://cdn.pixabay.com/photo/2019/09/16/07/41/balm-4480134_1280.jpg",
description: "Calms nerves and promotes relaxation.",
cost: "$14"
},
{
name: "Chamomile",
image: "https://cdn.pixabay.com/photo/2016/08/19/19/48/flowers-1606041_1280.jpg",
description: "Soothes anxiety and promotes sleep.",
cost: "$15"
},
{
name: "Calendula",
image: "https://cdn.pixabay.com/photo/2019/07/15/18/28/flowers-4340127_1280.jpg",
description: "Heals wounds and soothes skin irritations.",
cost: "$12"
}
]
},
{
category: "Low Maintenance Plants",
plants: [
{
name: "ZZ Plant",
image: "https://images.unsplash.com/photo-1632207691143-643e2a9a9361?q=80&w=464&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
description: "Thrives in low light and requires minimal watering.",
cost: "$25"
},
{
name: "Pothos",
image: "https://cdn.pixabay.com/photo/2018/11/15/10/32/plants-3816945_1280.jpg",
description: "Tolerates neglect and can grow in various conditions.",
cost: "$10"
},
{
name: "Snake Plant",
image: "https://cdn.pixabay.com/photo/2021/01/22/06/04/snake-plant-5939187_1280.jpg",
description: "Needs infrequent watering and is resilient to most pests.",
cost: "$15"
},
{
name: "Cast Iron Plant",
image: "https://cdn.pixabay.com/photo/2017/02/16/18/04/cast-iron-plant-2072008_1280.jpg",
description: "Hardy plant that tolerates low light and neglect.",
cost: "$20"
},
{
name: "Succulents",
image: "https://cdn.pixabay.com/photo/2016/11/21/16/05/cacti-1846147_1280.jpg",
description: "Drought-tolerant plants with unique shapes and colors.",
cost: "$18"
},
{
name: "Aglaonema",
image: "https://cdn.pixabay.com/photo/2014/10/10/04/27/aglaonema-482915_1280.jpg",
description: "Requires minimal care and adds color to indoor spaces.",
cost: "$22"
}
]
}
];
const styleObj = {
backgroundColor: '#4CAF50',
color: '#fff!important',
padding: '15px',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
fontSize: '20px',
};
const styleObjUl = {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
width: '1100px',
};
const styleA = {
color: 'white',
fontSize: '30px',
textDecoration: 'none',
};
return (
<div>
<div className="navbar" style={styleObj}>
<div className="tag">
<div className="luxury">
<img src="https://cdn.pixabay.com/photo/2020/08/05/13/12/eco-5465432_1280.png" alt="" />
<a href="https://ioborin22.github.io/coursera-paradise-nursery-shopping-application" style={{ textDecoration: 'none' }}>
<div className="tag_home_link">
<h3 style={{ color: 'white' }}>Paradise Nursery</h3>
<i style={{ color: 'white' }}>Where Green Meets Serenity</i>
</div>
</a>
</div>
</div>
<div style={styleObjUl}>
<div><a href="#" style={styleA}>Plants</a></div>
<div className="cart-container" onClick={onViewCartClick}>
<a href="#" style={styleA}>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" id="IconChangeColor" height="68" width="68">
<rect width="256" height="256" fill="none"></rect>
<circle cx="80" cy="216" r="12"></circle>
<circle cx="184" cy="216" r="12"></circle>
<path d="M42.3,72H221.7l-26.4,92.4A15.9,15.9,0,0,1,179.9,176H84.1a15.9,15.9,0,0,1-15.4-11.6L32.5,37.8A8,8,0,0,0,24.8,32H8" fill="none" stroke="#faf9f9" strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" id="mainIconPathAttribute"></path>
</svg>
<span className="cart-count">{cartItemsCount}</span>
</a>
</div>
</div>
</div>
<div className="product-grid">
{plantsArray.map((category, index) => (
<div key={index}>
<h2 className="plantname_heading">{category.category}</h2>
<div className="product-list">
{category.plants.map((plant, plantIndex) => (
<div key={plantIndex} className="product-card">
<img className="product-image" src={plant.image} alt={plant.name} />
<h3 className="product-title">{plant.name}</h3>
<p className="product-description">{plant.description}</p>
<p className="product-price">{plant.cost}</p>
<button
className={`product-button ${addedToCart[plant.name] ? 'added-to-cart' : ''}`}
onClick={() => handleAddToCart(plant)}
disabled={addedToCart[plant.name]}
>
{addedToCart[plant.name] ? 'Added to Cart' : 'Add to Cart'}
</button>
</div>
))}
</div>
</div>
))}
</div>
</div>
);
}
export default ProductList;