From 77b9ddc400069720723cd32c9e07209eee2f7176 Mon Sep 17 00:00:00 2001 From: Aaron Gonzalez Date: Mon, 24 Jun 2019 19:24:15 -0500 Subject: [PATCH 1/4] test --- public/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/index.js b/public/index.js index 034dbd5e..872213f2 100644 --- a/public/index.js +++ b/public/index.js @@ -1 +1,3 @@ -//stuff \ No newline at end of file +//stuff +yii +yii \ No newline at end of file From 77b39819d94e48a26d27998e8dee1e0e16e7f68b Mon Sep 17 00:00:00 2001 From: Aaron Gonzalez Date: Wed, 10 Jul 2019 13:56:06 -0500 Subject: [PATCH 2/4] first --- public/index.css | 33 +++++++++++++++++++++++++++++++ public/index.html | 14 +++++++++++++- public/index.js | 49 +++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 public/index.css diff --git a/public/index.css b/public/index.css new file mode 100644 index 00000000..7e08b423 --- /dev/null +++ b/public/index.css @@ -0,0 +1,33 @@ +*{ + box-sizing: border-box; +} +body{ + margin: 0; + padding: 0; +} +.searchbox{ + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + height: 40px; + border-radius: 40px; + padding: 10px; + color: black; +} +.search-btn{ + float: right; + width: 40px; + height: 40px; + padding: 10px; + border: 1px; + outline-color:black; +} +.search-txt{ + float: left; + padding: 0; + height: 30px; + outline-color: grey; + font-size: 16px; + width: 240px; +} diff --git a/public/index.html b/public/index.html index 138da963..bc7c136f 100644 --- a/public/index.html +++ b/public/index.html @@ -4,11 +4,23 @@ My Store + - + + + + + +
+ \ No newline at end of file diff --git a/public/index.js b/public/index.js index 872213f2..ffa36469 100644 --- a/public/index.js +++ b/public/index.js @@ -1,3 +1,48 @@ //stuff -yii -yii \ No newline at end of file +//cart is an empty array you push items to +let cart=[]; +//best practice to set this to null? +let addCartBtn = document.getElementById("btnAddToCart").innerHTML; + +function listProducts(products){ + let productDivs = ""; + for(let i=0; i < products.length; i++){ + let product = products[i]; + productDivs +=`
${product.imgUrl}, +
${product.name}, +
Category: ${product.category}, +
Description: ${product.description}, +
Rating: ${product.rating}, +
Price: ${product.price}, +
${addCartBtn}
` + } + + document.getElementById("products").innerHTML = productDivs; + document.getElementById("btnAddToCart").onclick = function() {addToCart()}; +} +//what happens on load +window.onload = function(){ + //products are listed + listProducts(products); +} +//what happens when you return home +function returnHome(){ + listProducts(products); +} +//what happens when you add something to the cart +function addToCart(prod){ + cart.push(prod); +} +//see the cart +function goToCart(){ + listProducts(cart); +} +//what happens when you search +function search(){ + let filteredProducts = products.filter(p=>p.name.indexOf(state.searchText) > -1); + listProducts(filteredProducts); + } + + +//document.body.innerHTML = productDivs; //this will override a text input box + From 7245dbab5f86683ce54dbe932b458341866987ea Mon Sep 17 00:00:00 2001 From: Aaron Gonzalez Date: Sun, 14 Jul 2019 19:41:21 -0500 Subject: [PATCH 3/4] saving --- public/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/public/index.js b/public/index.js index ffa36469..2a3105bd 100644 --- a/public/index.js +++ b/public/index.js @@ -1,4 +1,5 @@ //stuff +//just checking //cart is an empty array you push items to let cart=[]; //best practice to set this to null? From f88c4b1d603c0a734ef43da8b0b50535432eddec Mon Sep 17 00:00:00 2001 From: Aaron Gonzalez Date: Sun, 18 Aug 2019 15:45:58 -0500 Subject: [PATCH 4/4] Jacob Gonz store --- index.js | 21 ++++++++++++++ public/index.css | 4 +++ public/index.html | 33 ++++++++++++++++++++-- public/index.js | 70 +++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 00000000..d3720daa --- /dev/null +++ b/index.js @@ -0,0 +1,21 @@ +let express = require("express"); +const app = express(); + +app.use(express.static('public')) + +app.listen(3000); + +//day 8 express code +// const express = require("express"); +// const bodyParser = require("body-parser"); + +// const app = express(); +// app.use(bodyParser.json()); + +// app.listen(3002, (err) => { +// if (err) { +// return console.log("Error", err); +// } +// console.log("Web server is now listening for messages", err); +// }); + diff --git a/public/index.css b/public/index.css index 7e08b423..a81c53fd 100644 --- a/public/index.css +++ b/public/index.css @@ -31,3 +31,7 @@ body{ font-size: 16px; width: 240px; } + +.item{ + border: solid black 1px; +} \ No newline at end of file diff --git a/public/index.html b/public/index.html index bc7c136f..3347f256 100644 --- a/public/index.html +++ b/public/index.html @@ -9,6 +9,23 @@ + + + + + + + + @@ -18,9 +35,19 @@ Search --> + +
+ -
- - +
+ + + + + \ No newline at end of file diff --git a/public/index.js b/public/index.js index 2a3105bd..6c81d738 100644 --- a/public/index.js +++ b/public/index.js @@ -1,15 +1,19 @@ //stuff //just checking +// let prod=require("products.js"); +let products=[]; + //cart is an empty array you push items to let cart=[]; //best practice to set this to null? let addCartBtn = document.getElementById("btnAddToCart").innerHTML; -function listProducts(products){ +function listProducts(prods){ let productDivs = ""; - for(let i=0; i < products.length; i++){ - let product = products[i]; - productDivs +=`
${product.imgUrl}, + for(let i=0; i < prods.length; i++){ + let product = prods[i]; + productDivs +=`
+ ,
${product.name},
Category: ${product.category},
Description: ${product.description}, @@ -23,12 +27,26 @@ function listProducts(products){ } //what happens on load window.onload = function(){ - //products are listed - listProducts(products); + fetch("https://acastore.herokuapp.com/products") + .then(res => res.json()) + .then(parsedData => listProducts(parsedData)) + + + // listProducts(products); + // mainDiv = document.getElementById("main"); + // register = document.getElementById("register"); + // btnSignUp = document.getElementById("btnSignUp"); + // btnSignUp.onclick = signUp; + // txtEmail = document.getElementById("email"); + // txtPassword = document.getElementById("password"); } //what happens when you return home function returnHome(){ - listProducts(products); + fetch("https://acastore.herokuapp.com/products") + .then(res => res.json()) + .then(parsedData => listProducts(parsedData)) + + listProducts(prod); } //what happens when you add something to the cart function addToCart(prod){ @@ -40,10 +58,44 @@ function goToCart(){ } //what happens when you search function search(){ - let filteredProducts = products.filter(p=>p.name.indexOf(state.searchText) > -1); - listProducts(filteredProducts); + let searchText = document.getElementById("btnSearch").value; + fetch("https://acastore.herokuapp.com/products") + .then(res => res.json()) + .then(parsedData => { + let filteredProducts = parsedData.filter(p=>p.name.toLowerCase().includes(searchText)); + listProducts(filteredProducts); + }) + + } + //user info +class UserInfo { + constructor(email, password, cartId){ + this.email= email; + this.password= password; + this.cartId= cartId; + } +} +//sign up +function signUp(){ + mainDiv.style.display = "block"; + register.style.display = "none"; + let newUser = new UserInfo(txtEmail.value, txtPassword.value, null); + //learn this bs its called fetch and its wild + fetch("https://acastore.herokuapp.com/users", { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify(newUser) + }).then(response => response.json()); + console.log(newUser); + localStorage.setItem('newUser', JSON.stringify(newUser)); + +} + + //document.body.innerHTML = productDivs; //this will override a text input box