todoApp revised edition
by shahryar saljoughi
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="styles.css" type="text/css" rel="stylesheet">
<title>Document</title>
</head>
<body>
<p class="title">Todo App</p>
<div class="container">
<div id="rightPanel" >
</div>
<div id="leftPanel">
<input type="text" class="stack-item" id="descriptionInput">
<button class="stack-item createButton" onclick="addItem()">New todo</button>
</div>
</div>
<script src="scripts.js"></script>
</body>
</html>
CSS
* {
box-sizing: border-box;
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
}
body {
padding: 10%;
}
.container {
display: flex;
margin: auto;
width: 80%;
flex-direction: row;
}
div#leftPanel {
flex: 1;
display: flex;
flex-direction: column;
flex-shrink: 1;
}
div#rightPanel {
flex: 3;
flex-shrink: 1;
}
input {
padding: 5px;
}
.stack-item {
margin: 7px 0px 7px 0px;
display: block;
}
.createButton {
background-color: rgb(4, 129, 71);
color: white;
padding: 10px;
font-weight: bold;
border-radius: 10px;
cursor: pointer;
}
.createButton:hover {
background-color: rgb(74, 119, 7);
}
.todo {
padding: 10px;
width: 80%;
position: relative; /*this is because it has a child who wants to be absolutely positioned!. */
margin: 10px auto 10px auto;
border-bottom: grey outset;
}
.todo:first-child {
margin: auto;
}
.close {
color: red;
font-weight: bold;
position: absolute;
top: 0px;
right: 0px;
cursor: pointer;
}
.title {
text-align: center;
display: block;
font-size: 50px;
}
@media screen and (max-width: 992px) {
.container {
flex-direction: column;
}
.todo {
width: 100%;
}
}
JavaScript
/* class Task {
constructor(description, deadline, order) {
this.description = description;
this._deadline = deadline;
this.id = uuidv4();
}
get deadline() { }
set deadline(value) { }
} */
/* function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
*/
let items = [];
function addItem(description=document.getElementById("descriptionInput").value) {
if (!description) {
return;
}
items.push(description);
document.getElementById("descriptionInput").value = "";
renderItemOnPage(description);
}
function renderItemOnPage(item) {
let panel = document.getElementById("rightPanel");
panel.innerHTML += `<div class="todo">
${item}
</div>`;
}