mirror of
https://github.com/zoldar/jenot.git
synced 2026-01-05 07:02:55 +00:00
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
import { renderText } from "./dom.js";
|
|
import { NoteStore } from "./store.js";
|
|
import "./components.js"
|
|
|
|
const Notes = new NoteStore("jenot-app");
|
|
|
|
const newNote = document.querySelector("#new-note");
|
|
|
|
Notes.addEventListener("save", render.bind(this));
|
|
|
|
Notes.reset();
|
|
|
|
Notes.add({
|
|
type: "note",
|
|
content: "This is a test note",
|
|
});
|
|
|
|
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();
|
|
const notesContainer = document.querySelector("#notes");
|
|
|
|
notes.forEach((note) => {
|
|
const container = document.createElement("div");
|
|
container.id = note.id;
|
|
container.classList.add("note");
|
|
container.classList.add("readonly");
|
|
|
|
if (note.type === "note") {
|
|
container.replaceChildren(...renderText(note.content));
|
|
} else if (note.type === "tasklist") {
|
|
const list = document.createElement("ul");
|
|
|
|
note.content.forEach((task) => {
|
|
const item = document.createElement("li");
|
|
const check = document.createElement("p");
|
|
check.textContent = task.checked ? "☑" : "☐";
|
|
item.appendChild(check);
|
|
const itemContent = document.createElement("p");
|
|
itemContent.replaceChildren(...renderText(task.content));
|
|
item.appendChild(itemContent);
|
|
list.append(item);
|
|
});
|
|
|
|
container.appendChild(list);
|
|
}
|
|
|
|
notesContainer.replaceChildren(container);
|
|
});
|
|
}
|