`;\r\n return newRow;\r\n}\r\n\r\n\n\n//# sourceURL=webpack://todo/./src/modules/view.js?");
/***/ })
diff --git a/src/create.js b/src/create.js
deleted file mode 100644
index 0697300..0000000
--- a/src/create.js
+++ /dev/null
@@ -1,46 +0,0 @@
-import Todo from "./todo.js";
-
-const createTodo = () => {
- // Get the basic elements on the page - the add button, the content container and the input field
- const addButton = document.querySelector("main > button");
- const tableBody = document.querySelector("tbody");
- const inputField = document.querySelector("#todoInputField");
-
- // Add new row to content table
- addButton.addEventListener("click", (e) => {
- const newTodo = new Todo(inputField.value);
- // Look for the last rows id and increment it for the next one, or if none exists, then it should return undefined = falsy and therefore assign 0
- let id = parseInt (
- document.querySelector("tbody")?.lastElementChild?.getAttribute("id")
- ) + 1 || 0;
- const newItem = generateRow(id, newTodo.getTitle());
- tableBody.appendChild(newItem);
- });
-}
-
-//function to create new row
-const generateRow = (id, text) => {
-let newRow = document.createElement("tr");
-newRow.setAttribute("id", id);
-newRow.innerHTML = `
-
-
- ${text}
-
-
-
-
-
-
-
-
-
-
-
-
-
- `;
- return newRow;
-};
-
-export {createTodo};
\ No newline at end of file
diff --git a/src/index.html b/src/index.html
index 9fe9f24..735e040 100644
--- a/src/index.html
+++ b/src/index.html
@@ -12,7 +12,7 @@
-
+
diff --git a/src/index.js b/src/index.js
index a0e42c8..20b778e 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,42 +1,8 @@
-import {createTodo} from "./create.js";
-// import {} from "./project";
import css from "./style.css";
import '@fortawesome/fontawesome-free/js/fontawesome'
import '@fortawesome/fontawesome-free/js/solid'
-
+import {listenForAdd} from "./modules/controller";
window.addEventListener("load", () => {
- createTodo();
+ listenForAdd();
});
-
-
-
-
-// // Set todo status to complete module
-// // Get all check icons and add event listeners to them
-// let done = document.querySelectorAll(".fa-circle-check");
-// done.forEach((item) => {
-// item.addEventListener("click", (event) => {
-// completeTask(event);
-// });
-// });
-
-// // Mark task complete
-// const completeTask = (event) => {
-// let task = event.target.nextElementSibling;
-// let text = task.innerHTML;
-// if (text.includes("")) {
-// task.parentNode.parentNode.setAttribute("data-complete", "false");
-// text = task.firstElementChild.textContent;
-// task.innerHTML = text;
-// } else {
-// task.innerHTML = `${text}`;
-// task.parentNode.parentNode.setAttribute("data-complete", "true");
-// }
-// };
-
-// Changing todo priority module
-
-// Dom manipulation module
-
-// Popup form https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_popup_form
diff --git a/src/modules/controller.js b/src/modules/controller.js
new file mode 100644
index 0000000..597a1c3
--- /dev/null
+++ b/src/modules/controller.js
@@ -0,0 +1,15 @@
+import {addTodo} from "./model.js";
+import {display} from "./view.js";
+
+let todoInputField = document.querySelector("#todoInputField");
+const addButton = document.querySelector(".addTodoButton");
+
+function listenForAdd() {
+ console.log(addButton);
+ addButton.addEventListener("click", () => {
+ let todoTitle = todoInputField.value;
+ display(addTodo(todoTitle));
+ });
+}
+
+export {listenForAdd};
\ No newline at end of file
diff --git a/src/todo.js b/src/modules/entities.js
similarity index 83%
rename from src/todo.js
rename to src/modules/entities.js
index a542b96..6a31b30 100644
--- a/src/todo.js
+++ b/src/modules/entities.js
@@ -1,11 +1,4 @@
-/* Todo objects
-- Title
-- Description
-- DueDate
-- Priority
-*/
-
-export default class Todo {
+class Todo {
title;
description;
dueDate;
@@ -49,6 +42,6 @@ export default class Todo {
getPriority() {
return this.priority;
}
-
}
+export {Todo};
\ No newline at end of file
diff --git a/src/modules/model.js b/src/modules/model.js
new file mode 100644
index 0000000..b578353
--- /dev/null
+++ b/src/modules/model.js
@@ -0,0 +1,11 @@
+import {Todo} from "./entities";
+
+const todoList = [];
+
+function addTodo(title, due, prio){
+ let newTodo = new Todo(title, due, prio);
+ todoList.push(newTodo);
+ return todoList;
+}
+
+export {addTodo};
\ No newline at end of file
diff --git a/src/modules/view.js b/src/modules/view.js
new file mode 100644
index 0000000..805ae9d
--- /dev/null
+++ b/src/modules/view.js
@@ -0,0 +1,20 @@
+const todoTable = document.querySelector("table");
+
+function display(currentTodoArray){
+ // Wipeout current list
+ todoTable.innerHTML = "";
+ // loop through list
+ currentTodoArray.forEach((todo)=>{
+ // Create and add a new row to the table
+ todoTable.appendChild(createRow(todo.title));
+ })
+}
+
+function createRow(title) {
+ console.log(title);
+ const newRow = document.createElement("tr");
+ newRow.innerHTML=`
${title}
`;
+ return newRow;
+}
+
+export {display};
\ No newline at end of file
diff --git a/src/project.js b/src/project.js
deleted file mode 100644
index 51687e3..0000000
--- a/src/project.js
+++ /dev/null
@@ -1,4 +0,0 @@
-/*
-A project is a container in which several todos live.
-A project should have a theme like private, work, ...
-*/
\ No newline at end of file