diff --git a/index.html b/index.html
index 37ad826..51af4e6 100644
--- a/index.html
+++ b/index.html
@@ -38,33 +38,11 @@
+
-
- example note
-
-
-
-
-
- -
- one
-
- - two
- - three
- - four
- - five
- - six
- - seven
- - eight
- - nine
- - ten
-
-
-
-
diff --git a/js/components.js b/js/components.js
index bd68660..aa599f3 100644
--- a/js/components.js
+++ b/js/components.js
@@ -451,6 +451,7 @@ class NoteForm extends HTMLElement {
this.tasklistModeButton = this.querySelector(".tasklist-mode");
this.noteModeButton = this.querySelector(".note-mode");
this.removeButton = this.querySelector(".remove");
+ this.addButton = this.querySelector(".add");
this.tasklistModeButton.addEventListener("click", (e) => {
e.preventDefault();
@@ -471,6 +472,17 @@ class NoteForm extends HTMLElement {
this.#reset();
});
+ this.addButton.addEventListener("click", (e) => {
+ e.preventDefault();
+ this.dispatchEvent(
+ new CustomEvent("addNote", {
+ bubbles: true,
+ detail: this.note,
+ }),
+ );
+ this.#reset();
+ });
+
this.addEventListener("contentChange", () => {
this.note.content = this.content.firstChild.value;
});
diff --git a/js/jenot.js b/js/jenot.js
index d5ca8fe..5eec272 100644
--- a/js/jenot.js
+++ b/js/jenot.js
@@ -1,6 +1,6 @@
import { renderText } from "./dom.js";
import { NoteStore } from "./store.js";
-import "./components.js"
+import "./components.js";
const Notes = new NoteStore("jenot-app");
@@ -8,27 +8,18 @@ const newNote = document.querySelector("#new-note");
Notes.addEventListener("save", render.bind(this));
-Notes.reset();
+render();
-Notes.add({
- type: "note",
- content: "This is a test note",
+newNote.addEventListener("addNote", (e) => {
+ Notes.add(e.detail);
+ Notes.saveStorage();
});
-Notes.add({
- type: "tasklist",
- content: [
- { checked: false, content: "First item" },
- { checked: true, content: "Second item" },
- { checked: false, content: "Third item" },
- ],
-});
-
-Notes.saveStorage();
-
function render() {
const notes = Notes.all();
+ console.log(notes)
const notesContainer = document.querySelector("#notes");
+ notesContainer.replaceChildren();
notes.forEach((note) => {
const container = document.createElement("div");
@@ -55,6 +46,6 @@ function render() {
container.appendChild(list);
}
- notesContainer.replaceChildren(container);
+ notesContainer.appendChild(container);
});
}