more code

This commit is contained in:
Smigz 2025-01-17 22:45:33 -05:00
parent 17d664eaeb
commit 6fb88b315a
10 changed files with 130 additions and 14 deletions

View file

@ -0,0 +1,14 @@
function addForm() {
let buttonClicked = true;
const addForm = document.querySelector(".add-form");
const button = document.querySelector(".add-btn");
button.addEventListener("click", () => {
buttonClicked
? (addForm.style.display = " block")
: (addForm.style.display = "none");
buttonClicked = !buttonClicked;
});
}
export { addForm };

View file

@ -1,8 +1,7 @@
import { modal } from "./components/modal.js";
import { addForm } from "./components/addForm.js";
const newItemLink = document.querySelector("a[href='/add']");
//
//if (newItemLink && window.location !== "/item/") {
const modalElement = await modal();
let modalToggle = false;
async function handleDelete(e) {
@ -25,7 +24,7 @@ document.querySelectorAll(".delete-button").forEach((button) =>
document.querySelectorAll(".edit-button").forEach((button) => {
button.addEventListener("click", async (e) => {
const itemId = e.target.parentNode.dataset.itemId;
const itemId = e.target.parentNode.parentNode.dataset.itemId;
window.location.href = `/item/${itemId}`;
});
@ -37,7 +36,8 @@ document.querySelectorAll(".delete-btn").forEach((button) => {
const data = new URLSearchParams(new FormData());
data.append("id", itemId);
const res = await fetch("/category", {
const path = window.location.pathname;
const res = await fetch(`${path}`, {
method: "DELETE",
body: data,
});
@ -46,7 +46,7 @@ document.querySelectorAll(".delete-btn").forEach((button) => {
if (message.includes("error")) {
alert("unable to delete as item is using category");
} else {
window.location.href = "/category";
window.location.href = `${path}`;
}
});
});
@ -60,4 +60,4 @@ newItemLink.addEventListener("click", (e) => {
});
document.body.append(modalElement);
//}
addForm();