diff --git a/README.md b/README.md
index de33908..e274abe 100644
Binary files a/README.md and b/README.md differ
diff --git a/client/public/components/checkout.mjs b/client/public/components/checkout.mjs
index 88e1fc3..bb6ebd8 100644
--- a/client/public/components/checkout.mjs
+++ b/client/public/components/checkout.mjs
@@ -73,7 +73,7 @@ class Checkout extends Component {
diff --git a/client/public/components/components.mjs b/client/public/components/components.mjs
index 371ab48..5a6532d 100644
--- a/client/public/components/components.mjs
+++ b/client/public/components/components.mjs
@@ -29,7 +29,7 @@ export class Component extends HTMLElement {
// Override these
OnMount() { }
- Update() { }
+ Update(attributeChanged, newState) { }
Render() { Component.__WARN('Render'); }
OnRender() { }
OnUnMount() { }
@@ -78,9 +78,12 @@ export class Component extends HTMLElement {
attributeChangedCallback(name, newValue) {
console.log(`attribute changed: ${name} ${newValue}`);
- this.setState({ ...this.state, [name]: newValue });
- this.Update();
- this.__INVOKE_RENDER();
+ this.Update(Object.bind(this, name, {
+ ...this.state,
+ [name]: newValue,
+ }));
+ this.setState({ ...this.state, [name]: newValue }, false);
+ this.__INVOKE_RENDER(Object.bind(this));
}
get getState() {
diff --git a/client/public/components/css/stock-audit.css b/client/public/components/css/stock-audit.css
index eb51dca..b90eb25 100644
--- a/client/public/components/css/stock-audit.css
+++ b/client/public/components/css/stock-audit.css
@@ -47,17 +47,11 @@
.menu-content {
max-width: fit-content;
- display: none;
+ display: flex;
flex-direction: column;
align-items: flex-start;
- min-width: 0;
- margin-top: 1em;
-}
-
-.details-open {
- display: flex;
- position: static;
width: auto;
+ margin-top: 1em;
}
.product-details-content-item {
@@ -67,4 +61,4 @@
.menu-content-item {
width: 100%;
margin-bottom: 1em;
-}
\ No newline at end of file
+}
diff --git a/client/public/components/navbar.mjs b/client/public/components/navbar.mjs
index 8a2152c..480fddb 100644
--- a/client/public/components/navbar.mjs
+++ b/client/public/components/navbar.mjs
@@ -93,6 +93,12 @@ class NavBar extends Component {
const admin = e.value;
if (admin) {
this.root.querySelector('.stock-mode').style.display = 'flex';
+
+ if (localStorage.getItem('stock-mode') === 'true') {
+ this.root.querySelector('.stock-slider').checked = true;
+ } else {
+ this.root.querySelector('.stock-slider').checked = false;
+ }
} else {
this.root.querySelector('.stock-mode').style.display = 'none';
}
diff --git a/client/public/components/product-list.mjs b/client/public/components/product-list.mjs
index b889747..489c483 100644
--- a/client/public/components/product-list.mjs
+++ b/client/public/components/product-list.mjs
@@ -38,20 +38,22 @@ class ProductList extends Component {
if (!augmentable) {
return '';
}
- return /* html */`
-
- `;
+ // next time :(
+ // return /* html */`
+ //
+ //
+ //
+ //
+ // Weight
+ // Tag
+ //
+ //
+ //
+ //
+ // `;
+ return '';
}
Render() {
diff --git a/client/public/components/product-listing.mjs b/client/public/components/product-listing.mjs
index 60e8da6..1975705 100644
--- a/client/public/components/product-listing.mjs
+++ b/client/public/components/product-listing.mjs
@@ -1,5 +1,7 @@
import { RegisterComponent, Component, SideLoad } from './components.mjs';
import { AddProductToBasket } from '../basket.mjs';
+import * as LocalStorageListener from '../localstorage-listener.mjs';
+import * as Auth from '../auth.mjs';
class ProductListing extends Component {
static __IDENTIFY() { return 'product-listing'; }
@@ -142,11 +144,22 @@ class ProductListing extends Component {
-
+
{this.state.stock} in stock
+ ${localStorage.getItem('stock-mode') === 'true'
+ ? /* html */`
+
+ Change Stock
+
+
+
+ `
+ : ''
+ }
+
@@ -178,6 +191,37 @@ class ProductListing extends Component {
}
OnRender() {
+ LocalStorageListener.ListenOnKey('stock-mode', () => {
+ this.__INVOKE_RENDER();
+ });
+
+ if (localStorage.getItem('stock-mode') === 'true') {
+ const updateStockButton = this.root.querySelector('.product-stock-mode-button');
+ updateStockButton.addEventListener('click', async () => {
+ const input = this.root.querySelector('.product-stock-mode-input');
+ const stock = parseInt(input.value);
+ this.state.stock = stock;
+ this.__INVOKE_RENDER();
+
+ // tell the server to update the stock
+ const productId = this.state.id;
+ const productType = this.state.type;
+
+ const params = {
+ method: 'PUT',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${await Auth.GetToken()}`,
+ },
+ body: JSON.stringify({
+ new_stock_level: stock,
+ }),
+ };
+
+ fetch(`/api/auth/staff/stock/${productType}/${productId}`, params).then(response => response.json()).then(data => console.log(data));
+ });
+ }
+
const backButton = this.root.querySelector('.back-button-svg');
backButton.addEventListener('click', () => {
@@ -188,8 +232,16 @@ class ProductListing extends Component {
const quantityInput = this.root.querySelector('.quantity-input');
const increaseQuantityButton = this.root.querySelector('.increase-quantity');
const reduceQuantityButton = this.root.querySelector('.reduce-quantity');
+ const addToBasket = this.root.querySelector('.add-to-basket-button');
quantityInput.value = 1;
+ if (this.state.stock === 0) {
+ quantityInput.value = 0;
+ increaseQuantityButton.disabled = true;
+ reduceQuantityButton.disabled = true;
+ addToBasket.disabled = true;
+ addToBasket.innerText = 'Out of Stock';
+ }
quantityInput.addEventListener('change', () => {
quantityInput.value = parseInt(quantityInput.value);
@@ -225,8 +277,6 @@ class ProductListing extends Component {
}));
// add quantity to basket and then update the basket count
- const addToBasket = this.root.querySelector('.add-to-basket-button');
-
addToBasket.addEventListener('click', () => {
// if it is a brick, get potential modifier from the drop down menu
const brick = this.state.type === 'brick';
diff --git a/client/public/components/stock-audit.mjs b/client/public/components/stock-audit.mjs
index d212b7c..8736664 100644
--- a/client/public/components/stock-audit.mjs
+++ b/client/public/components/stock-audit.mjs
@@ -12,14 +12,12 @@ class StockEditor extends Component {
template: /* html */`
-