From 70983f62b35b15b51ee7a4a9d25bb19fa3da5a43 Mon Sep 17 00:00:00 2001 From: Palvit Garg Date: Thu, 11 Nov 2021 17:13:55 -0500 Subject: [PATCH 1/5] Update application name in tab --- public/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/index.html b/public/index.html index aa069f2..d2d789f 100644 --- a/public/index.html +++ b/public/index.html @@ -24,7 +24,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - React App + Feature hunt From 8eb3402bf405ea02209f9e2f8a84fca9f5af9879 Mon Sep 17 00:00:00 2001 From: Palvit Garg Date: Sat, 27 Nov 2021 20:19:49 -0500 Subject: [PATCH 2/5] Moved search logic from frontend to backend and improved search conditions --- backend/products.py | 25 ++++++++++++++++++++++++- src/Components/Home.js | 13 ++++++++----- src/Service.js | 3 ++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/backend/products.py b/backend/products.py index c3008f9..c61a81a 100644 --- a/backend/products.py +++ b/backend/products.py @@ -30,7 +30,30 @@ @app.route('/products', methods=['GET', 'POST', 'DELETE', 'PATCH']) def products(): if request.method == 'GET': - data = product_records.find() + data = product_records.find( + {"$or" : + [{ + "name" : + { + "$regex" : request.args.get("query"), + '$options' : 'i' + } + }, + { + "description" : + { + "$regex" : request.args.get("query"), + '$options' : 'i' + } + }, + { + "tags" : + { + "$regex" : request.args.get("query"), + '$options' : 'i' + } + }] + }) return dumps(data) data = request.get_json() diff --git a/src/Components/Home.js b/src/Components/Home.js index 06b13bf..16e3478 100644 --- a/src/Components/Home.js +++ b/src/Components/Home.js @@ -14,8 +14,9 @@ const Home = ({query}) => { const [sortBy, setSortBy] = useState('timestamp'); const [products, setProducts] = useState([]); useEffect(() => { - Service.get('products').then(products => setProducts(products)); - }, []); + Service.get('products', "query=" + query).then(products => setProducts(products)); + }, [query]); + return (
@@ -36,9 +37,11 @@ const Home = ({query}) => {
- {products.map((p, index) => { p['index'] = index; return p; }).filter(p => query ? p.tags.includes(query.toLowerCase()) || p.name.toLowerCase().includes(query.toLowerCase()) : true).sort((p1, p2) => p2[sortBy] - p1[sortBy]).map( - (product) => - , setProducts)} + {products + .map((p, index) => { p['index'] = index; return p; }) + .sort((p1, p2) => p2[sortBy] - p1[sortBy]) + .map((product) => , setProducts) + } ); }; diff --git a/src/Service.js b/src/Service.js index c5e315a..7517e33 100644 --- a/src/Service.js +++ b/src/Service.js @@ -23,7 +23,8 @@ const postRequestOptionsBuilder = (method, body, headers) => { const get = async (path, params) => { path = sanitizePath(path); - if (params) path += new URLSearchParams(params); + + if (params) path += "?" + new URLSearchParams(params); const response = await fetch(baseUrl + path); const data = await response.json(); if (response.status >= 400 && response.status < 600) { From 36ba0f6848ebfed2c9b87665ce1d398e9a99d6bf Mon Sep 17 00:00:00 2001 From: Palvit Garg Date: Sat, 27 Nov 2021 20:49:20 -0500 Subject: [PATCH 3/5] Corrected the call to enlist small features within major feature --- backend/products.py | 4 ++-- src/Components/ProductTile.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/products.py b/backend/products.py index c61a81a..de2bcf6 100644 --- a/backend/products.py +++ b/backend/products.py @@ -98,9 +98,9 @@ def products(): @app.route('//getFeature', methods=['GET', 'POST']) -def get_feature(product_name): +def get_feature(productname): if request.method == 'GET': - data = product_records.find({"name": product_name}) + data = product_records.find({"name": productname},{"features":1}) return dumps(data) diff --git a/src/Components/ProductTile.js b/src/Components/ProductTile.js index 488c7d2..c2b8514 100644 --- a/src/Components/ProductTile.js +++ b/src/Components/ProductTile.js @@ -31,7 +31,7 @@ const ProductTile = ({ products, index, setProducts }) => { setProducts(products.map((product) => product.id === products[index].id ? updatedProduct : product)); }; const goTo = (product) => () => { - history.push(`/${product}`); + history.push(`/${product}` + "/getFeature"); }; const capitalizeFirstLetter = (string) => { return string.charAt(0).toUpperCase() + string.slice(1); From 7e2d1a21f279415c763a667f5ac075bf0ba45117 Mon Sep 17 00:00:00 2001 From: Palvit Garg Date: Sat, 27 Nov 2021 20:57:40 -0500 Subject: [PATCH 4/5] Corrected compile errors --- src/Components/ProductTile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/ProductTile.js b/src/Components/ProductTile.js index c2b8514..962bfaa 100644 --- a/src/Components/ProductTile.js +++ b/src/Components/ProductTile.js @@ -31,7 +31,7 @@ const ProductTile = ({ products, index, setProducts }) => { setProducts(products.map((product) => product.id === products[index].id ? updatedProduct : product)); }; const goTo = (product) => () => { - history.push(`/${product}` + "/getFeature"); + history.push(`/${product}/getFeature`); }; const capitalizeFirstLetter = (string) => { return string.charAt(0).toUpperCase() + string.slice(1); From bba6a9a8a1d8d2598bb54edde4a36afa362e1119 Mon Sep 17 00:00:00 2001 From: Palvit Garg Date: Sat, 27 Nov 2021 21:08:45 -0500 Subject: [PATCH 5/5] Updating testcase to correct expected path --- src/__tests__/ProductTile.tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/ProductTile.tests.js b/src/__tests__/ProductTile.tests.js index c64ce5a..43515c8 100644 --- a/src/__tests__/ProductTile.tests.js +++ b/src/__tests__/ProductTile.tests.js @@ -178,7 +178,7 @@ describe("Test ProductTile", () => { fireEvent.click(nav); expect(history.length).toBe(3); // after clicking on something, history.length + 1 - expect(history.location.pathname).toBe("/feature-hunt"); + expect(history.location.pathname).toBe("/feature-hunt/getFeature"); fireEvent.click(nav2); expect(history.length).toBe(4); // after clicking on something, history.length + 1