From f9da1e2789afe07dd35cc39d5cafa84e1efe29d0 Mon Sep 17 00:00:00 2001 From: Ben <36240171+benkyd@users.noreply.github.com> Date: Fri, 29 Apr 2022 18:30:41 +0100 Subject: [PATCH] i think i'm done? Former-commit-id: 25c3bd71ee177a9926d2aee8b02deadebccc4286 --- README.md | Bin 10180 -> 11440 bytes client/public/basket.mjs | 17 +++ client/public/components/compact-listing.mjs | 59 ++++++++- client/public/components/product-list.mjs | 1 + .../public/components/templates/navbar.html | 25 +++- client/public/featured/new/index.html | 47 +++++++ client/public/search/index.html | 4 +- db/dump.sql | 1 - docs/API.md | 5 +- src/controllers/brick-controller.js | 44 ++++++- src/controllers/set-controller.js | 115 +++++++++++++++++- src/routes/api.js | 2 + src/routes/query-router.js | 92 +++++++++++++- src/routes/sets-router.js | 28 ++++- src/routes/stock-router.js | 6 - 15 files changed, 417 insertions(+), 29 deletions(-) create mode 100644 client/public/featured/new/index.html diff --git a/README.md b/README.md index e274abecf5c51c9edfae7cebe6bddf4ba6d45a77..48496e6b56a64117d07a824401b7954973378fec 100644 GIT binary patch delta 1170 zcmY+D&1w`;5QR(J$bcY(kVO=)2?Ska#Dx#wPeMWnBN7Bxq0>EShxGg~-Q$o|KSVEl zjYys#;3_-cz&G#}JYU`Pq-E&td+S!6bL!NcUxTZ!SATl-t_3@>Z#J~Ko?sKbhn88X zb!Ah%&pe)JReB_~3$0VHiR)84wfDAX`!=x8`m*n4Ol_e`>cOj2nfP9-+QAn(Lcn9| z2{@66U|TLI#=q-y%K?xSNtc2dS>g3S4((DI_p(}2&@!D&R5|tbf^rLI47S(Ook=4A z5vtoOqE>pHZY-d&Ruk`HWK}bGx?ax|E%h78u~ruS=86YJ$!3Maxg(B@#=2ZV88naE z@Pav$vOQ(IpD?Hz44{q0AGZxwuJpX^ZIk4i^Ut|SV0_LUA; zn^THnDCb6Yt|wJK0_0lrbM0A;Jg!8Li+Eq!>$}Rngk;uV;hy*usGSK1u^_=dRwP=| zPJ^q2sZ0WeE6z?`C6$X>l$9Ldb}~kMjPimV+ZX$w-GxUp0R~&@ed&^zD7OxG_=1p# zuJAc0PT5X7RSxr+>q`cgF-ls89zwPZKGR{*{C>DmLqLxVGh>yAx(CCS;}4FO-e3n}V8?Cc; ${this.state.tags - ? this.state.tags.map(tag => ``).join('') + ? this.state.tags.map(tag => ``).join('') : ''} +
+ +
${this.state.discount ? `£${parseFloat(this.state.price).toFixed(2)}£${parseFloat(this.state.discount).toFixed(2)}` : `£${parseFloat(this.state.price).toFixed(2)}`} - + `, style: ` @@ -118,6 +122,35 @@ class CompactProductListing extends Component { max-height: 100%; } } + + .add-to-basket { + width: 100%; + } + + .add-to-basket-button { + width: 100%; + background-color: #F5F6F6; + outline: 2px solid #222; + color: #222; + border: none; + padding: 10px; + fomt-size: 1.2em; + font-weight: bold; + cursor: pointer; + transition: all 250ms ease-in-out; + margin-top: 5px; + margin-bottom: 5px; + } + + .add-to-basket-button:hover { + color: #fff; + background-color: #222; + } + + .button-refresh { + color: #fff; + background-color: #222; + } `, }; } @@ -135,6 +168,28 @@ class CompactProductListing extends Component { name.addEventListener('click', () => { this.OpenProductListing(Object.bind(this)); }); + + const addToBasketButton = this.root.querySelector('.add-to-basket-button'); + + if (parseInt(this.state.stock) - Basket.GetItemAmountBasket(this.state.id) < 1 || parseInt(this.state.stock) === 0) { + addToBasketButton.disabled = true; + addToBasketButton.style.backgroundColor = '#888'; + addToBasketButton.style.color = '#222'; + addToBasketButton.innerText = 'Out of stock'; + } + + addToBasketButton.addEventListener('click', () => { + Basket.AddProductToBasket(this.state.id, this.state.type, 1, 0); + + addToBasketButton.disabled = true; + addToBasketButton.classList.add('button-refresh'); + addToBasketButton.innerText = 'Added to basket'; + setTimeout(() => { + this.setState({ + ...this.getState, + }); + }, 1000); + }); } } diff --git a/client/public/components/product-list.mjs b/client/public/components/product-list.mjs index 489c483..db604fd 100644 --- a/client/public/components/product-list.mjs +++ b/client/public/components/product-list.mjs @@ -86,6 +86,7 @@ class ProductList extends Component { id="${product.id}" listing="${product.listing}" price="${product.price}" + stock="${product.stock}" type="${product.type}" tags="${JSON.stringify(product.tags).replace(/"/g, '"')}" discount="${product.discount || ''}"> diff --git a/client/public/components/templates/navbar.html b/client/public/components/templates/navbar.html index cbd4401..7acbc05 100644 --- a/client/public/components/templates/navbar.html +++ b/client/public/components/templates/navbar.html @@ -11,19 +11,32 @@