Add update on edit on menu
This commit is contained in:
parent
7884295f5d
commit
c471ec6840
1 changed files with 52 additions and 5 deletions
|
@ -5,6 +5,8 @@ const sauce = document.querySelector("#sauce ul");
|
||||||
const drink = document.querySelector("#drink ul");
|
const drink = document.querySelector("#drink ul");
|
||||||
const dessert = document.querySelector("#dessert ul");
|
const dessert = document.querySelector("#dessert ul");
|
||||||
|
|
||||||
|
let db = {dish: {}, ingredient: {}, sauce: {}, drink: {}, dessert: {}};
|
||||||
|
|
||||||
|
|
||||||
if (window.location.href.endsWith("#popup"))
|
if (window.location.href.endsWith("#popup"))
|
||||||
window.location.href = window.location.href.replace("#popup", "#");
|
window.location.href = window.location.href.replace("#popup", "#");
|
||||||
|
@ -69,42 +71,47 @@ function popup(ob, el) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDish(d) {
|
function addDish(d) {
|
||||||
|
db.dish[d.id] = d;
|
||||||
dish.insertAdjacentHTML("beforeend", `<li><a id="dish${d.id}">${d.name}</a></li>`);
|
dish.insertAdjacentHTML("beforeend", `<li><a id="dish${d.id}">${d.name}</a></li>`);
|
||||||
let e = document.getElementById(`dish${d.id}`);
|
let e = document.getElementById(`dish${d.id}`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
popup(d, e);
|
popup(db.dish[d.id], e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addIngredient(i) {
|
function addIngredient(i) {
|
||||||
|
db.ingredient[i.id] = i;
|
||||||
ingredient.insertAdjacentHTML("beforeend", `<li><a id="ingredient${i.id}">${i.name}</a></li>`);
|
ingredient.insertAdjacentHTML("beforeend", `<li><a id="ingredient${i.id}">${i.name}</a></li>`);
|
||||||
let e = document.getElementById(`ingredient${i.id}`);
|
let e = document.getElementById(`ingredient${i.id}`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
popup(i, e);
|
popup(db.ingredient[i.id], e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addSauce(s) {
|
function addSauce(s) {
|
||||||
|
db.sauce[s.id] = s;
|
||||||
sauce.insertAdjacentHTML("beforeend", `<li><a id="sauce${s.id}">${s.name}</a></li>`);
|
sauce.insertAdjacentHTML("beforeend", `<li><a id="sauce${s.id}">${s.name}</a></li>`);
|
||||||
let e = document.getElementById(`sauce${s.id}`);
|
let e = document.getElementById(`sauce${s.id}`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
popup(s, e);
|
popup(db.sauce[s.id], e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDrink(d) {
|
function addDrink(d) {
|
||||||
|
db.drink[d.id] = d;
|
||||||
drink.insertAdjacentHTML("beforeend", `<li><a id="drink${d.id}">${d.name}</a></li>`);
|
drink.insertAdjacentHTML("beforeend", `<li><a id="drink${d.id}">${d.name}</a></li>`);
|
||||||
let e = document.getElementById(`drink${d.id}`);
|
let e = document.getElementById(`drink${d.id}`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
popup(d, e);
|
popup(db.drink[d.id], e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDessert(d) {
|
function addDessert(d) {
|
||||||
|
db.dessert[d.id] = d;
|
||||||
dessert.insertAdjacentHTML("beforeend", `<li><a id="dessert${d.id}">${d.name}</a></li>`);
|
dessert.insertAdjacentHTML("beforeend", `<li><a id="dessert${d.id}">${d.name}</a></li>`);
|
||||||
let e = document.getElementById(`dessert${d.id}`);
|
let e = document.getElementById(`dessert${d.id}`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
popup(d, e);
|
popup(db.dessert[d.id], e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +173,46 @@ socket.on("list dessert", data => {
|
||||||
addDessert(d);
|
addDessert(d);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on("set dish", data => {
|
||||||
|
if (data.available && db.dish[data.id] === undefined) {
|
||||||
|
addDish(data);
|
||||||
|
} else {
|
||||||
|
db.dish[data.id] = data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("set ingredient", data => {
|
||||||
|
if (data.available && db.ingredient[data.id] === undefined) {
|
||||||
|
addIngredient(data);
|
||||||
|
} else {
|
||||||
|
db.ingredient[data.id] = data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("set sauce", data => {
|
||||||
|
if (data.available && db.sauce[data.id] === undefined) {
|
||||||
|
addSauce(data);
|
||||||
|
} else {
|
||||||
|
db.sauce[data.id] = data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("set drink", data => {
|
||||||
|
if (data.available && db.drink[data.id] === undefined) {
|
||||||
|
addDrink(data);
|
||||||
|
} else {
|
||||||
|
db.drink[data.id] = data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("set dessert", data => {
|
||||||
|
if (data.available && db.dessert[data.id] === undefined) {
|
||||||
|
addDessert(data);
|
||||||
|
} else {
|
||||||
|
db.dessert[data.id] = data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
socket.on("internal error", () => {
|
socket.on("internal error", () => {
|
||||||
alert("An error occurred !");
|
alert("An error occurred !");
|
||||||
})
|
})
|
||||||
|
|
Reference in a new issue