diff --git a/src/main/resources/static/js/pages/list/list.js b/src/main/resources/static/js/pages/list/list.js index 5499d65..950f18f 100644 --- a/src/main/resources/static/js/pages/list/list.js +++ b/src/main/resources/static/js/pages/list/list.js @@ -1,6 +1,5 @@ import { ShoppingCategory } from "../../models/ShoppingCategory.js"; import { ShoppingItem } from "../../models/ShoppingItem.js"; -import { initErrors } from "../../shared/error.js"; import * as api from "./api/listAPI.js" import * as ui from "./frontend/listUI.js" import { handleResponse } from "../../shared/helper.js"; @@ -16,14 +15,14 @@ async function addItem(itemName, itemAmount, categoryID) { console.log(` adding item with id:${currentList.dataset.id}, name: ${itemName}, amount: ${itemAmount}, category: ${categoryID}`) const json = await handleResponse(api.addItem(currentList.dataset.id, itemName, itemAmount, categoryID), `item couldnt be created!`); - if (json) ui.addItem(json); + if (json.ok) ui.addItem(json.json); } async function addCategory(categoryName) { console.log(`adding category ${categoryName}`) const json = await handleResponse(api.addCategory(currentList.dataset.id, categoryName), `category couldnt be added!`); - if (json) ui.addCategory(json); + if (json.ok) ui.addCategory(json.json); } @@ -31,25 +30,24 @@ async function deleteItem(li) { console.log(`deleting item ${li.dataset.id}`) const json = await handleResponse(api.deleteItem(li.dataset.id), `error deleting item`); - if (json) ui.deleteItem(li); + if (json.ok) ui.deleteItem(li); } async function deleteCategory(deleteAllItems, categoryID) { console.log(`deleting category with allItems: ${deleteAllItems} id: ${categoryID}`); const json = await handleResponse(api.deleteCategory(deleteAllItems, categoryID), `error deleting category`); - if (json) ui.deleteCategory(deleteAllItems, categoryID); + if (json.ok) ui.deleteCategory(deleteAllItems, categoryID); } async function deleteAllDoneItems() { console.log(`deleting all done items...`) const json = await handleResponse(api.deleteAllDoneItems(currentList.dataset.id), `error deleting all done items`); - if (json) ui.deleteAllDoneItems(); + if (json.ok) ui.deleteAllDoneItems(); } function init() { - initErrors(document.querySelector(".nav")); customElements.define("shopping-item", ShoppingItem); customElements.define("shopping-category", ShoppingCategory); diff --git a/src/main/resources/static/js/shared/editing.js b/src/main/resources/static/js/shared/editing.js index 7153a36..e632a56 100644 --- a/src/main/resources/static/js/shared/editing.js +++ b/src/main/resources/static/js/shared/editing.js @@ -15,7 +15,7 @@ export async function editElement({ element, fields, apiCall, id, onSuccess, onF let result = await handleResponse(apiCall(id, formData), errmsg); - if (result) { + if (result.ok) { onSuccess(formData); abortEditing(formElement, element); } else {