diff --git a/functions/index.js b/functions/index.js index 9595aa4..953ed9b 100644 --- a/functions/index.js +++ b/functions/index.js @@ -54,6 +54,46 @@ function homePage(request, responce) { }) } +app.get('/search', function(request, responce){ + var dbRef = database.ref("/products") + if (request.query.search) { + let sQuery = request.query.search.toLowerCase() + dbRef.orderByChild("status").equalTo("on-sale").once('value', function(snapshot){ + var data = { + 'x': {desc: '',holder: '',id: 999,img: '',location: '',name: 'Nothing found 😢',owner: '',price: '',public: '',stock: ''}, + } + if (snapshot.val()) { + data = snapshot.val() + var sResults = [{desc: '',holder: '',id: 999,img: '',location: '',name: 'Nothing found 😢',owner: '',price: '',public: '',stock: ''}] + + var keys = Object.keys(data) + + keys.forEach(key => { + if (data[key].name.toLowerCase().includes(sQuery) || data[key].desc.toLowerCase().includes(sQuery)) { + sResults[key] = data[key] + console.log(sResults) + } + }) + if (Object.keys(sResults).length > 1) { + delete sResults[0] + } + console.log(sResults) + responce.render('search.ejs', {products: sResults}) + } + else {responce.render('search.ejs', {products: data})} + }) + } + else { + dbRef.orderByChild("status").equalTo("on-sale").once('value', function(snapshot){ + var data = { + 'x': {desc: '',holder: '',id: 999,img: '',location: '',name: 'Nothing found 😢',owner: '',price: '',public: '',stock: ''}, + } + if (snapshot.val()) {data = snapshot.val()} + responce.render('search.ejs', {products: data}) + }) + } +}) + app.get('/additmpage', function(request, responce){ responce.render('add-item.ejs') }) diff --git a/functions/views/404.ejs b/functions/views/404.ejs index 30390a8..afb9c5f 100644 --- a/functions/views/404.ejs +++ b/functions/views/404.ejs @@ -53,7 +53,7 @@
img - + Extras
diff --git a/functions/views/css/style.css b/functions/views/css/style.css index 552220e..c8c7c7e 100644 --- a/functions/views/css/style.css +++ b/functions/views/css/style.css @@ -249,6 +249,17 @@ footer a { margin-left: 20px; font-size: 20px; font-family: osl; + transition: 0.4s; +} + +.sbar button:hover { + background-color: violet; + transition: 0.2s; +} + +.sbar button:active { + background-color: whitesmoke; + transition: 0.2s; } .sbar a { @@ -484,7 +495,7 @@ footer a { } .product-page-info button:hover { transition: 0.3s; - background-color: #ff7700; + background-color: #ffc04b; } .product-page-info button:active { transition: 0.1s; @@ -510,7 +521,7 @@ footer a { } .my-products-container { - + color: transparent; } .my-product-container { diff --git a/functions/views/home.ejs b/functions/views/home.ejs index 9af1201..f83cdbb 100644 --- a/functions/views/home.ejs +++ b/functions/views/home.ejs @@ -14,7 +14,7 @@ - + @@ -55,7 +55,7 @@
img - + Extras
diff --git a/functions/views/js/fdb.js b/functions/views/js/fdb.js index be99920..16141d6 100644 --- a/functions/views/js/fdb.js +++ b/functions/views/js/fdb.js @@ -343,9 +343,19 @@ try { } catch(error) {console.log(error)} +function bSearch(){ + let searchField = document.getElementById("sfield") + if (searchField.value == ""){ + searchField.blur() + } + else { + search(searchField.value) + } +} + try { - var searchField = document.getElementById("sfield") + let searchField = document.getElementById("sfield") searchField.addEventListener("keyup", function(event) { if (event.keyCode === 13) { event.preventDefault() diff --git a/functions/views/my-product.ejs b/functions/views/my-product.ejs index 51ae691..936230b 100644 --- a/functions/views/my-product.ejs +++ b/functions/views/my-product.ejs @@ -53,7 +53,7 @@
img - + Extras
diff --git a/functions/views/my-products.ejs b/functions/views/my-products.ejs index b235fff..123efbe 100644 --- a/functions/views/my-products.ejs +++ b/functions/views/my-products.ejs @@ -54,7 +54,7 @@
img - + Extras
diff --git a/functions/views/product.ejs b/functions/views/product.ejs index 5817704..2df14ea 100644 --- a/functions/views/product.ejs +++ b/functions/views/product.ejs @@ -53,7 +53,7 @@
img - + Extras
diff --git a/functions/views/search.ejs b/functions/views/search.ejs index 3ee9837..d401357 100644 --- a/functions/views/search.ejs +++ b/functions/views/search.ejs @@ -54,7 +54,7 @@
img - + Extras