Notes app :)
at main 91 lines 2.5 kB view raw
1import { DeclarativeElement } from "../modules/component-element.js"; 2 3const tomorrow_ul = document.querySelector(".card-body.tomorrow ul"); 4 5 6class TaskItem extends DeclarativeElement { 7 static element_name = "task-item"; 8 9 static attrs = ["task_id", "checked", "day"]; 10 11 start(shadow) { 12 const messageSpan = shadow.querySelector("slot.message"); 13 this.message = messageSpan.textContent; 14 15 messageSpan.addEventListener("click", async () => { 16 messageSpan.classList.add("is-loading"); 17 18 const response = await fetch("/task/complete", { 19 method: "POST", 20 body: new URLSearchParams({ 21 "id": this.task_id 22 }) 23 }); 24 25 messageSpan.classList.remove("is-loading"); 26 27 if (response.ok) { 28 this.toggleAttribute("checked"); 29 } 30 }); 31 32 const btn_delete = shadow.querySelector("button.button-delete"); 33 34 btn_delete.addEventListener("click", async () => { 35 btn_delete.classList.add("is-loading"); 36 37 const response = await fetch("/task/delete", { 38 method: "POST", 39 body: new URLSearchParams({ 40 "id": this.task_id 41 }) 42 }); 43 44 btn_delete.classList.remove("is-loading"); 45 46 if (response.ok) { 47 this.remove(); 48 } 49 }) 50 51 const btn_pushback = shadow.querySelector("button.button-pushback"); 52 53 btn_pushback.addEventListener("click", async () => { 54 btn_pushback.classList.add("is-loading"); 55 56 const response = await fetch("/task/pushback", { 57 method: "POST", 58 body: new URLSearchParams({ 59 "id": this.task_id 60 }) 61 }); 62 63 btn_pushback.classList.remove("is-loading"); 64 65 if (response.ok) { 66 tomorrow_ul.appendChild(this); 67 shadow.querySelectorAll("details").forEach(element => { 68 element.removeAttribute("open"); 69 }); 70 } 71 }) 72 73 } 74 75 attributeSet(property, oldValue, newValue) { 76 if (newValue == null) { 77 this.shadow.querySelector(".list-item").removeAttribute(property); 78 79 } else { 80 this.shadow.querySelector(".list-item").setAttribute(property, newValue); 81 82 } 83 } 84 85 86} 87 88TaskItem.define(); 89 90 91export { TaskItem }