Compare commits
3
Commits
0b69384fb7
...
302419802b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
302419802b | ||
|
|
3f5856c86b | ||
|
|
8c347d124a |
No files matched your search
@@ -1,8 +1,8 @@
|
||||
|
||||
|
||||
|
||||
export async function addList(listName) {
|
||||
return await fetch(`/api/lists`,
|
||||
export function addList(listName) {
|
||||
return fetch(`/api/lists`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({ listName: listName }),
|
||||
@@ -12,14 +12,14 @@ export async function addList(listName) {
|
||||
|
||||
}
|
||||
|
||||
export async function deleteList(id) {
|
||||
return await fetch(`/api/lists/${id}`, { method: "DELETE" });
|
||||
export function deleteList(id) {
|
||||
return fetch(`/api/lists/${id}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function editList(listID, toChange) {
|
||||
return await fetch(`/api/lists/${listID}`,
|
||||
export function editList(listID, toChange) {
|
||||
return fetch(`/api/lists/${listID}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(toChange),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export async function addCategory(listID, categoryName) {
|
||||
return await fetch(`/api/categories`,
|
||||
export function addCategory(listID, categoryName) {
|
||||
return fetch(`/api/categories`,
|
||||
{
|
||||
method: "POST"
|
||||
, body: JSON.stringify({ "categoryName": categoryName, "listID": listID })
|
||||
@@ -7,8 +7,8 @@ export async function addCategory(listID, categoryName) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function editCategory(categoryID, toChange) {
|
||||
return await fetch(`/api/categories/${categoryID}`,
|
||||
export function editCategory(categoryID, toChange) {
|
||||
return fetch(`/api/categories/${categoryID}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(toChange),
|
||||
@@ -16,6 +16,6 @@ export async function editCategory(categoryID, toChange) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteCategory(deleteAllItems, categoryID) {
|
||||
return await fetch(`/api/categories/${categoryID}?deleteAllItems=${deleteAllItems}`, { method: "DELETE" });
|
||||
export function deleteCategory(deleteAllItems, categoryID) {
|
||||
return fetch(`/api/categories/${categoryID}?deleteAllItems=${deleteAllItems}`, { method: "DELETE" });
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
export async function addItem(listID, itemName, itemAmount, categoryID) {
|
||||
return await fetch(`/api/items`,
|
||||
export function addItem(listID, itemName, itemAmount, categoryID) {
|
||||
return fetch(`/api/items`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
@@ -12,14 +12,14 @@ export async function addItem(listID, itemName, itemAmount, categoryID) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteItem(itemID) {
|
||||
export function deleteItem(itemID) {
|
||||
|
||||
return await fetch(`/api/items/${itemID}`, { method: "DELETE" });
|
||||
return fetch(`/api/items/${itemID}`, { method: "DELETE" });
|
||||
|
||||
}
|
||||
|
||||
export async function editItem(itemID, toChange) {
|
||||
return await fetch(`/api/items/${itemID}`,
|
||||
export function editItem(itemID, toChange) {
|
||||
return fetch(`/api/items/${itemID}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(toChange),
|
||||
@@ -28,6 +28,6 @@ export async function editItem(itemID, toChange) {
|
||||
|
||||
}
|
||||
|
||||
export async function deleteAllDoneItems(listID) {
|
||||
return await fetch(`/api/lists/${listID}/items?done=true`, { method: "DELETE" });
|
||||
export function deleteAllDoneItems(listID) {
|
||||
return fetch(`/api/lists/${listID}/items?done=true`, { method: "DELETE" });
|
||||
}
|
||||
@@ -28,8 +28,9 @@ async function addCategory(categoryName) {
|
||||
}
|
||||
|
||||
async function deleteItem(li) {
|
||||
const json = await handleResponse(api.deleteItem(li.dataset.id), `error deleting item`);
|
||||
console.log(`deleting item ${li.dataset.id}`)
|
||||
|
||||
const json = await handleResponse(api.deleteItem(li.dataset.id), `error deleting item`);
|
||||
if (json) ui.deleteItem(li);
|
||||
}
|
||||
|
||||
@@ -131,8 +132,8 @@ function init() {
|
||||
api.editItem(item.dataset.id, { isDone: e.target.checked });
|
||||
}
|
||||
});
|
||||
|
||||
console.log("javascript initialized!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { abortEditing, createEditForm } from "./sharedUI.js";
|
||||
import { handleResponse } from "./helper.js";
|
||||
|
||||
export async function editElement({ element, fields, apiCall, id, onSuccess, errmsg }) {
|
||||
const formElement = sharedUI.createEditForm(fields);
|
||||
const formElement = createEditForm(fields);
|
||||
|
||||
element.replaceWith(formElement);
|
||||
|
||||
@@ -11,16 +14,16 @@ export async function editElement({ element, fields, apiCall, id, onSuccess, err
|
||||
let formData = Object.fromEntries(new FormData(formElement));
|
||||
let result = await handleResponse(apiCall(id, formData), errmsg);
|
||||
|
||||
sharedUI.abortEditing(formElement, element);
|
||||
abortEditing(formElement, element);
|
||||
|
||||
if (result) onSuccess(formData);
|
||||
});
|
||||
|
||||
formElement.addEventListener("click", (e) => {
|
||||
if (e.target.matches(".editForm__buttonAbort")) sharedUI.abortEditing(formElement, element);
|
||||
if (e.target.matches(".editForm__buttonAbort")) abortEditing(formElement, element);
|
||||
})
|
||||
|
||||
formElement.addEventListener("keydown", (e) => {
|
||||
if (e.key == "Escape") sharedUI.abortEditing(formElement, element);
|
||||
if (e.key == "Escape") abortEditing(formElement, element);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user