Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean code s1e1 #55

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
94bcf82
refactor(basic-1.1): add two spaces for one indentation
VictorREDrudko Jan 3, 2024
4e830ef
refactor(basic-2.2): add types of HTML files
VictorREDrudko Jan 3, 2024
d78768d
refactor(basic-2.1): format index.html file
VictorREDrudko Jan 3, 2024
ea0470e
refactor(basic-1.2): change HTML-tags, attributes, CSS selectors, CSS…
VictorREDrudko Jan 3, 2024
d5e1588
refactor(basic-1.3): change double quotes instead of single quotes in…
VictorREDrudko Jan 3, 2024
b251250
refactor(basic-2.3): change named character references in index.html …
VictorREDrudko Jan 3, 2024
69d1d9a
refactor(basic-2.4): delete type attribute in html file
VictorREDrudko Jan 3, 2024
cbbfc08
refactor(basic-2.5): add break long lines in html file
VictorREDrudko Jan 3, 2024
59b213a
refactor(basic-3.1): single style for selectors naming HTML and CSS file
VictorREDrudko Jan 4, 2024
8686c5b
refactor(basic-3.2): change naming of identifiers and classes
VictorREDrudko Jan 4, 2024
018d81e
refactor(basic-3.1): change single style for selectors and identifier…
VictorREDrudko Jan 4, 2024
dca4bf9
refactor(basic-3.3): change naming of classes concise in index.html file
VictorREDrudko Jan 4, 2024
688d374
refactor(basic-3.4): change tag selectors to class in HTML, css and j…
VictorREDrudko Jan 4, 2024
bdc9aba
refactor(basic-3.5): add indentation in blocks in css file
VictorREDrudko Jan 4, 2024
64c9304
refactor(basic-3.6): add space after property name in css file
VictorREDrudko Jan 4, 2024
3a61849
refactor(basic-3.7): add Semicolon after properties in css file
VictorREDrudko Jan 4, 2024
b42bde4
refactor(basic-3.8): add separate selectors and properties with a lin…
VictorREDrudko Jan 4, 2024
f8107f9
refactor(extended-1.1): add semantics tags (header, main, section, h1…
VictorREDrudko Jan 11, 2024
1ce90c6
refactor(basic-3.2): change naming classes link
VictorREDrudko Jan 11, 2024
8943a67
refactor(extended-1.2): add attribute alt in index.html file
VictorREDrudko Jan 5, 2024
6134f31
refactor(basic-2.1): move title tag in head to new line
VictorREDrudko Jan 5, 2024
52e22c4
refactor(extended-2.1): use BEM notation to form class names
VictorREDrudko Jan 5, 2024
9182a3d
feat: add link
VictorREDrudko Jan 5, 2024
574a872
refactor(basic-1.2): change CSS properties in lowercase
VictorREDrudko Jan 9, 2024
7cb4e60
refactor(extended-2.1): use BEM notation to form class names in HTML …
VictorREDrudko Jan 9, 2024
3d7a5cd
refactor(basic-3.8): change writing selectors
VictorREDrudko Jan 9, 2024
648ae82
refactor(extended-2.1): use BEM notation of the class name img
VictorREDrudko Jan 9, 2024
433afe0
refactor(extended-1.2): add alternative content for js file
VictorREDrudko Jan 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<img width="1199" alt="code-quality-task-screenshot" src="https://user-images.githubusercontent.com/8201843/113413843-4080fb80-93c4-11eb-9f20-15e4b4c1e430.png">
<img width="1199" alt="code-quality-task-screenshot"
src="https://VictorREDrudko.github.io/clean-code-s1e1/index.html"
>

# Application Functionality :

- Adding a new item to the "TODO" task list
- Editing an item in the "TODO" task list
- Deleting an item from the "TODO" task list
- Setting an item to completed status and moving it to the "COMPLETED" list via checkbox
- Adding a new item to the "TODO" task list
- Editing an item in the "TODO" task list
- Deleting an item from the "TODO" task list
- Setting an item to completed status and moving it to the "COMPLETED" list via checkbox

- Deleting an item from the "COMPLETED" list
- Editing an item from the "COMPLETED" list
- Setting an item to "Incomplete" status and moving it to the "TODO" list via checkbox
- Animation on the delete button
- Deleting an item from the "COMPLETED" list
- Editing an item from the "COMPLETED" list
- Setting an item to "Incomplete" status and moving it to the "TODO" list via checkbox
- Animation on the delete button
226 changes: 108 additions & 118 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,191 +5,181 @@
//Solution: Add interactivity so the user can manage daily tasks.
//Break things down into smaller steps and take each step at a time.


// Event handling, user interaction is what starts the code execution.

var taskInput=document.getElementById("new-task");//Add a new task.
var addButton=document.getElementsByTagName("button")[0];//first button
var incompleteTaskHolder=document.getElementById("incompleteTasks");//ul of #incompleteTasks
var completedTasksHolder=document.getElementById("completed-tasks");//completed-tasks
var completedTasksHolder=document.getElementById("completedTasks");//completed-tasks


//New task list item
var createNewTaskElement=function(taskString){

var listItem=document.createElement("li");

//input (checkbox)
var checkBox=document.createElement("input");//checkbx
//label
var label=document.createElement("label");//label
//input (text)
var editInput=document.createElement("input");//text
//button.edit
var editButton=document.createElement("button");//edit button

//button.delete
var deleteButton=document.createElement("button");//delete button
var deleteButtonImg=document.createElement("img");//delete button image

label.innerText=taskString;
label.className='task';

//Each elements, needs appending
checkBox.type="checkbox";
editInput.type="text";
editInput.className="task";

editButton.innerText="Edit"; //innerText encodes special characters, HTML does not.
editButton.className="edit";

deleteButton.className="delete";
deleteButtonImg.src='./remove.svg';
deleteButton.appendChild(deleteButtonImg);


//and appending.
listItem.appendChild(checkBox);
listItem.appendChild(label);
listItem.appendChild(editInput);
listItem.appendChild(editButton);
listItem.appendChild(deleteButton);
return listItem;
var listItem=document.createElement("li");
listItem.className='item';

//input (checkbox)
var checkBox=document.createElement("input");//checkbx
//label
var label=document.createElement("label");//label
//input (text)
var editInput=document.createElement("input");//text
//button.edit
var editButton=document.createElement("button");//edit button

//button.delete
var deleteButton=document.createElement("button");//delete button
var deleteButtonImg=document.createElement("img");//delete button image

label.innerText=taskString;
label.className='item__label';

//Each elements, needs appending
checkBox.type="checkbox";
checkBox.className="item__input_checkbox";
editInput.type="text";
editInput.className="item__input item__input_text";

editButton.innerText="Edit"; //innerText encodes special characters, HTML does not.
editButton.className="item__button item__button_edit";

deleteButton.className="item__button item__button_delete";
deleteButtonImg.className="item__delete-img";
deleteButtonImg.setAttribute('alt', 'cross');
deleteButtonImg.src='./remove.svg';
deleteButton.appendChild(deleteButtonImg);

//and appending.
listItem.appendChild(checkBox);
listItem.appendChild(label);
listItem.appendChild(editInput);
listItem.appendChild(editButton);
listItem.appendChild(deleteButton);
return listItem;
}



var addTask=function(){
console.log("Add Task...");
//Create a new list item with the text from the #new-task:
if (!taskInput.value) return;
var listItem=createNewTaskElement(taskInput.value);

//Append listItem to incompleteTaskHolder
incompleteTaskHolder.appendChild(listItem);
bindTaskEvents(listItem, taskCompleted);
console.log("Add Task...");
//Create a new list item with the text from the #new-task:
if (!taskInput.value) return;
var listItem=createNewTaskElement(taskInput.value);

taskInput.value="";
//Append listItem to incompleteTaskHolder
incompleteTaskHolder.appendChild(listItem);
bindTaskEvents(listItem, taskCompleted);

taskInput.value="";
}

//Edit an existing task.

var editTask=function(){
console.log("Edit Task...");
console.log("Change 'edit' to 'save'");


var listItem=this.parentNode;

var editInput=listItem.querySelector('input[type=text]');
var label=listItem.querySelector("label");
var editBtn=listItem.querySelector(".edit");
var containsClass=listItem.classList.contains("editMode");
//If class of the parent is .editmode
if(containsClass){

//switch to .editmode
//label becomes the inputs value.
label.innerText=editInput.value;
editBtn.innerText="Edit";
}else{
editInput.value=label.innerText;
editBtn.innerText="Save";
console.log("Edit Task...");
console.log("Change 'edit' to 'save'");

var listItem=this.parentNode;
var editInput=listItem.querySelector('input[type=text]');
var label=listItem.querySelector("label");
var editBtn=listItem.querySelector(".item__button_edit");
var containsClass=listItem.classList.contains("edit-mode");
//If class of the parent is .editmode
if(containsClass){
//switch to .editmode
//label becomes the inputs value.
label.innerText=editInput.value;
editBtn.innerText="Edit";
}else{
editInput.value=label.innerText;
editBtn.innerText="Save";
}

//toggle .editmode on the parent.
listItem.classList.toggle("editMode");
//toggle .editmode on the parent.
listItem.classList.toggle("edit-mode");
};


//Delete task.
var deleteTask=function(){
console.log("Delete Task...");

var listItem=this.parentNode;
var ul=listItem.parentNode;
//Remove the parent list item from the ul.
ul.removeChild(listItem);
console.log("Delete Task...");

var listItem=this.parentNode;
var ul=listItem.parentNode;
//Remove the parent list item from the ul.
ul.removeChild(listItem);
}


//Mark task completed
var taskCompleted=function(){
console.log("Complete Task...");

//Append the task list item to the #completed-tasks
var listItem=this.parentNode;
completedTasksHolder.appendChild(listItem);
bindTaskEvents(listItem, taskIncomplete);

console.log("Complete Task...");

//Append the task list item to the #completed-tasks
var listItem=this.parentNode;
const listLabel = listItem.querySelector('.item__label')
listLabel.className = 'item__label item__label_completed';
completedTasksHolder.appendChild(listItem);
bindTaskEvents(listItem, taskIncomplete);
}


var taskIncomplete=function(){
console.log("Incomplete Task...");
//Mark task as incomplete.
//When the checkbox is unchecked
//Append the task list item to the #incompleteTasks.
var listItem=this.parentNode;
incompleteTaskHolder.appendChild(listItem);
bindTaskEvents(listItem,taskCompleted);
console.log("Incomplete Task...");
//Mark task as incomplete.
//When the checkbox is unchecked
//Append the task list item to the #incompleteTasks.
var listItem=this.parentNode;
const listLabel = listItem.querySelector('.item__label_completed');
listLabel.className = 'item__label';
incompleteTaskHolder.appendChild(listItem);
bindTaskEvents(listItem,taskCompleted);
}



var ajaxRequest=function(){
console.log("AJAX Request");
console.log("AJAX Request");
}

//The glue to hold it all together.


//Set the click handler to the addTask function.
addButton.onclick=addTask;
addButton.addEventListener("click",addTask);
addButton.addEventListener("click",ajaxRequest);


var bindTaskEvents=function(taskListItem,checkBoxEventHandler){
console.log("bind list item events");
//select ListItems children
var checkBox=taskListItem.querySelector("input[type=checkbox]");
var editButton=taskListItem.querySelector("button.edit");
var deleteButton=taskListItem.querySelector("button.delete");


//Bind editTask to edit button.
editButton.onclick=editTask;
//Bind deleteTask to delete button.
deleteButton.onclick=deleteTask;
//Bind taskCompleted to checkBoxEventHandler.
checkBox.onchange=checkBoxEventHandler;
console.log("bind list item events");
//select ListItems children
var checkBox=taskListItem.querySelector("input[type=checkbox]");
var editButton=taskListItem.querySelector("button.item__button_edit");
var deleteButton=taskListItem.querySelector("button.item__button_delete");

//Bind editTask to edit button.
editButton.onclick=editTask;
//Bind deleteTask to delete button.
deleteButton.onclick=deleteTask;
//Bind taskCompleted to checkBoxEventHandler.
checkBox.onchange=checkBoxEventHandler;
}

//cycle over incompleteTaskHolder ul list items
//for each list item
for (var i=0; i<incompleteTaskHolder.children.length;i++){

//bind events to list items chldren(tasksCompleted)
bindTaskEvents(incompleteTaskHolder.children[i],taskCompleted);
//bind events to list items chldren(tasksCompleted)
bindTaskEvents(incompleteTaskHolder.children[i],taskCompleted);
}




//cycle over completedTasksHolder ul list items
for (var i=0; i<completedTasksHolder.children.length;i++){
//bind events to list items chldren(tasksIncompleted)
bindTaskEvents(completedTasksHolder.children[i],taskIncomplete);
//bind events to list items chldren(tasksIncompleted)
bindTaskEvents(completedTasksHolder.children[i],taskIncomplete);
}




// Issues with usability don't get seen until they are in front of a human tester.

//prevent creation of empty tasks.

//Change edit to save when you are in edit mode.
Loading