Skip to content

Commit

Permalink
Add new items as tr to table
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Re committed Apr 13, 2022
1 parent 8e5d39d commit 56cb73f
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 21 deletions.
16 changes: 15 additions & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,23 @@
<aside>
Projects
</aside>
<main class="content">
<main>
<input type="text" name="todoInputField" id="todoInputField">
<button>+</button>
<div class="content">
<table>
<thead>
<tr>
<th>Title</th>
<th>Due date</th>
<th>Prio</th>
</tr>
</thead>
<tbody>

</tbody>
</table>
</div>
</main>
<footer>Made by Benjamin-Re</footer>
</body>
Expand Down
46 changes: 44 additions & 2 deletions dist/main.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@fortawesome/fontawesome-free": "^6.1.1",
"css-loader": "^6.7.1",
"html-webpack-plugin": "^5.5.0",
"style-loader": "^3.3.1",
Expand Down
46 changes: 46 additions & 0 deletions src/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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 = `
<td>
<i class="fa-solid fa-circle-check"></i>
<span contenteditable="true" class="task">${text}</span>
</td>
<td>
<span class="fa-stack fa-2x">
<i class="fa-solid fa-square fa-stack-2x"></i>
<i class="fa-solid fa-pen fa-stack-1x fa-inverse"></i>
</span>
</td>
<td>
<span class="fa-stack fa-2x">
<i class="fa-solid fa-square fa-stack-2x"></i>
<i class="fa-solid fa-trash fa-stack-1x fa-inverse"></i>
</span>
</td>
`;
return newRow;
};

export {createTodo};
16 changes: 15 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,23 @@
<aside>
Projects
</aside>
<main class="content">
<main>
<input type="text" name="todoInputField" id="todoInputField">
<button>+</button>
<div class="content">
<table>
<thead>
<tr>
<th>Title</th>
<th>Due date</th>
<th>Prio</th>
</tr>
</thead>
<tbody>

</tbody>
</table>
</div>
</main>
<footer>Made by Benjamin-Re</footer>
</body>
Expand Down
47 changes: 31 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
import Todo from "./todo.js";
import {createTodo} from "./create.js";
// import {} from "./project";
import css from './style.css';
import css from "./style.css";
import '@fortawesome/fontawesome-free/js/fontawesome'
import '@fortawesome/fontawesome-free/js/solid'


// Create Todo module


const addButton = document.querySelector(".content > button");
const contentContainer = document.querySelector(".content");
const inputField = document.querySelector("#todoInputField");

addButton.addEventListener("click", (e) => {
const newTodo = new Todo(inputField.value);
const newItem = document.createElement("div");
newItem.textContent = newTodo.title;
contentContainer.appendChild(newItem);
window.addEventListener("load", () => {
createTodo();
});




// Set todo status to complete module
// // 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("<del>")) {
// task.parentNode.parentNode.setAttribute("data-complete", "false");
// text = task.firstElementChild.textContent;
// task.innerHTML = text;
// } else {
// task.innerHTML = `<del>${text}</del>`;
// task.parentNode.parentNode.setAttribute("data-complete", "true");
// }
// };

// Changing todo priority module

// Dom manipulation module
// Dom manipulation module

// Popup form https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_popup_form
1 change: 0 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports = {
},
],
},

mode: "development",
devServer: {
static: "./dist",
Expand Down

0 comments on commit 56cb73f

Please sign in to comment.