Skip to content

Commit 2dbde77

Browse files
Merge pull request #1858 from vaishnavi-3969/main
Fake Store
2 parents 66bf998 + 3f50d74 commit 2dbde77

11 files changed

Lines changed: 456 additions & 0 deletions
511 KB
Loading
472 KB
Loading
463 KB
Loading
314 KB
Loading
253 KB
Loading
18.4 KB
Loading
51.4 KB
Loading

Projects/Fake Store/index.html

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Clothes Shopping Website</title>
7+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
8+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
9+
<link rel="stylesheet" href="styles.css">
10+
</head>
11+
<body>
12+
<header class="bg-dark text-white py-4">
13+
<div class="container text-center">
14+
<h1>Clothes Shopping Website</h1>
15+
</div>
16+
</header>
17+
<main class="container my-5">
18+
<div id="confetti-container">
19+
<div class="row">
20+
<div class="col-lg-3 mb-4">
21+
<div class="filters bg-light p-4">
22+
<div class="form-group">
23+
<input type="text" class="form-control" id="search-input" placeholder="Search products">
24+
</div>
25+
<div class="form-group">
26+
<label for="category-filter">Category:</label>
27+
<select class="form-control" id="category-filter">
28+
<option value="">All</option>
29+
<option value="men's clothing">Men's Clothing</option>
30+
<option value="women's clothing">Women's Clothing</option>
31+
<option value="jewelery">Jewelery</option>
32+
<option value="electronics">Electronics</option>
33+
</select>
34+
</div>
35+
<div class="form-group">
36+
<label for="price-range">Price Range:</label>
37+
<input type="range" class="form-control-range" id="price-range" min="0" max="1000">
38+
</div>
39+
</div>
40+
</div>
41+
<div class="col-lg-9">
42+
<div class="product-list row">
43+
<!-- Product cards will be dynamically loaded here -->
44+
</div>
45+
</div>
46+
</div>
47+
<div class="cart bg-light p-4 mt-5">
48+
<h2>Shopping Cart</h2>
49+
<ul id="cart-items" class="list-group">
50+
<!-- Card items -->
51+
</ul>
52+
<button id="checkout-btn" class="btn btn-dark btn-block mt-3">Checkout</button>
53+
</div>
54+
</main>
55+
<div id="confetti-container"></div>
56+
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
57+
58+
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.0.7/dist/umd/popper.min.js"></script>
59+
60+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
61+
62+
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/js/all.min.js"></script>
63+
64+
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
65+
66+
<script src="script.js"></script>
67+
</body>
68+
</html>

Projects/Fake Store/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Site
2+
https://clothes-shopping-webapp.netlify.app

Projects/Fake Store/script.js

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
// Constants for API endpoint and cart
2+
const API_ENDPOINT = 'https://fakestoreapi.com/products';
3+
const cartItems = [];
4+
5+
// Fetch product data from FakeStore API
6+
async function fetchProducts() {
7+
try {
8+
const response = await fetch(API_ENDPOINT);
9+
const data = await response.json();
10+
return data;
11+
} catch (error) {
12+
throw new Error('Error fetching data:', error);
13+
}
14+
}
15+
16+
// Create a product card element
17+
function createProductCard(product) {
18+
const productCard = document.createElement('div');
19+
productCard.classList.add('col-md-4', 'mb-4');
20+
21+
const card = document.createElement('div');
22+
card.classList.add('card', 'h-100');
23+
24+
const image = document.createElement('img');
25+
image.src = product.image;
26+
image.alt = product.title;
27+
image.classList.add('card-img-top');
28+
29+
const cardBody = document.createElement('div');
30+
cardBody.classList.add('card-body');
31+
32+
const title = document.createElement('h5');
33+
title.textContent = product.title;
34+
title.classList.add('card-title');
35+
36+
const price = document.createElement('p');
37+
price.textContent = `$${product.price}`;
38+
price.classList.add('card-text');
39+
40+
const addToCartBtn = document.createElement('button');
41+
addToCartBtn.textContent = 'Add to Cart';
42+
addToCartBtn.classList.add('btn', 'btn-primary', 'btn-block');
43+
addToCartBtn.addEventListener('click', () => addToCart(product));
44+
45+
cardBody.appendChild(title);
46+
cardBody.appendChild(price);
47+
cardBody.appendChild(addToCartBtn);
48+
49+
card.appendChild(image);
50+
card.appendChild(cardBody);
51+
52+
productCard.appendChild(card);
53+
54+
return productCard;
55+
}
56+
57+
let products = [];
58+
59+
// Render product cards on the product listing page
60+
function renderProducts(productsToRender) {
61+
const productContainer = document.querySelector('.product-list');
62+
productContainer.innerHTML = ''; // Clear existing products before rendering
63+
64+
productsToRender.forEach(product => {
65+
const productCard = createProductCard(product);
66+
productContainer.appendChild(productCard);
67+
});
68+
}
69+
70+
// Add a product to the shopping cart
71+
function addToCart(product) {
72+
cartItems.push(product);
73+
updateCart();
74+
}
75+
76+
// Update the cart display
77+
function updateCart() {
78+
const cartItemsList = document.getElementById('cart-items');
79+
cartItemsList.innerHTML = '';
80+
81+
cartItems.forEach(item => {
82+
const li = document.createElement('li');
83+
li.textContent = `${item.title} - $${item.price}`;
84+
li.classList.add('list-group-item');
85+
cartItemsList.appendChild(li);
86+
});
87+
}
88+
89+
// Show confetti effect on checkout
90+
function showConfetti() {
91+
particlesJS('confetti-container', {
92+
particles: {
93+
number: {
94+
value: 100,
95+
density: {
96+
enable: true,
97+
value_area: 800
98+
}
99+
},
100+
color: {
101+
value: '#ff6347'
102+
},
103+
shape: {
104+
type: 'circle',
105+
stroke: {
106+
width: 0,
107+
color: '#000000'
108+
},
109+
polygon: {
110+
nb_sides: 5
111+
}
112+
},
113+
opacity: {
114+
value: 0.7,
115+
random: true,
116+
anim: {
117+
enable: true,
118+
speed: 1,
119+
opacity_min: 0.1,
120+
sync: false
121+
}
122+
},
123+
size: {
124+
value: 5,
125+
random: true,
126+
anim: {
127+
enable: true,
128+
speed: 2,
129+
size_min: 0.1,
130+
sync: false
131+
}
132+
},
133+
line_linked: {
134+
enable_auto: true,
135+
distance: 100,
136+
color: '#ff6347',
137+
opacity: 0.4,
138+
width: 1,
139+
condensed_mode: {
140+
enable: false,
141+
rotateX: 600,
142+
rotateY: 600
143+
}
144+
},
145+
move: {
146+
enable: true,
147+
speed: 1,
148+
direction: 'none',
149+
random: false,
150+
straight: false,
151+
out_mode: 'out',
152+
bounce: false,
153+
attract: {
154+
enable: false,
155+
rotateX: 600,
156+
rotateY: 1200
157+
}
158+
}
159+
},
160+
interactivity: {
161+
detect_on: 'canvas',
162+
events: {
163+
onhover: {
164+
enable: true,
165+
mode: 'repulse'
166+
},
167+
onclick: {
168+
enable: true,
169+
mode: 'push'
170+
},
171+
resize: true
172+
},
173+
modes: {
174+
grab: {
175+
distance: 400,
176+
line_linked: {
177+
opacity: 1
178+
}
179+
},
180+
bubble: {
181+
distance: 400,
182+
size: 40,
183+
duration: 2,
184+
opacity: 8,
185+
speed: 3
186+
},
187+
repulse: {
188+
distance: 200
189+
},
190+
push: {
191+
particles_nb: 4
192+
},
193+
remove: {
194+
particles_nb: 2
195+
}
196+
}
197+
},
198+
retina_detect: true
199+
});
200+
}
201+
202+
// Show checkout page with confetti
203+
function showCheckoutPage() {
204+
const main = document.querySelector('main');
205+
main.innerHTML = `
206+
<div class="checkout-page">
207+
<h2>Checkout</h2>
208+
<form>
209+
<!-- Add more fields for shipping and payment info -->
210+
<div class="form-group">
211+
<label for="name">Name</label>
212+
<input type="text" class="form-control" id="name" required>
213+
</div>
214+
<div class="form-group">
215+
<label for="email">Email</label>
216+
<input type="email" class="form-control" id="email" required>
217+
</div>
218+
<button type="submit" class="btn btn-primary btn-block">Place Order</button>
219+
</form>
220+
</div>
221+
`;
222+
223+
showConfetti();
224+
const checkoutForm = document.getElementById('checkout-form');
225+
checkoutForm.addEventListener('submit', handleCheckout);
226+
}
227+
function handleCheckout(event) {
228+
event.preventDefault(); // Prevent form submission and redirect
229+
230+
// Get the form inputs
231+
const name = document.getElementById('name').value;
232+
const email = document.getElementById('email').value;
233+
234+
235+
// Redirect back to the product listing page after a delay
236+
setTimeout(() => {
237+
location.href = 'index.html';
238+
}, 10000);
239+
}
240+
const searchInput = document.getElementById('search-input');
241+
const categoryFilter = document.getElementById('category-filter');
242+
const priceRange = document.getElementById('price-range');
243+
244+
searchInput.addEventListener('input', applyFilters);
245+
categoryFilter.addEventListener('change', applyFilters);
246+
priceRange.addEventListener('input', applyFilters);
247+
248+
// Function to filter products based on search and filters
249+
function applyFilters() {
250+
const searchText = searchInput.value.toLowerCase();
251+
const selectedCategory = categoryFilter.value.toLowerCase();
252+
const maxPrice = priceRange.value;
253+
254+
const filteredProducts = products.filter(product => {
255+
const titleMatch = product.title.toLowerCase().includes(searchText);
256+
const categoryMatch = selectedCategory === '' || product.category.toLowerCase() === selectedCategory;
257+
const priceMatch = parseFloat(product.price) <= parseFloat(maxPrice);
258+
259+
return titleMatch && categoryMatch && priceMatch;
260+
});
261+
262+
renderProducts(filteredProducts);
263+
}
264+
265+
266+
const checkoutBtn = document.getElementById('checkout-btn');
267+
checkoutBtn.addEventListener('click', showCheckoutPage);
268+
269+
// Initialize the website
270+
async function init() {
271+
try {
272+
products = await fetchProducts();
273+
renderProducts(products);
274+
} catch (error) {
275+
console.error('Error fetching data:', error);
276+
}
277+
}
278+
279+
280+
init();

0 commit comments

Comments
 (0)