Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
670030c
update title
epent May 14, 2022
e92d485
add white-box
epent May 14, 2022
5806bb7
add font
epent May 14, 2022
351c776
style input & button
epent May 14, 2022
a774dc2
configure css for tasks
epent May 14, 2022
3a43072
update css for tasks: add <ul>
epent May 14, 2022
ff37ae3
add new task after click "Add task"
epent May 14, 2022
05b73aa
add style for task on hover
epent May 14, 2022
f9205ca
add task when enter key is pressed
epent May 14, 2022
eedc353
clear input when task is added
epent May 14, 2022
bf7cc1a
remove outline from input
epent May 14, 2022
39552cc
add delete button
epent May 14, 2022
4f2ed9d
each task is <div> with <li> and <button>
epent May 14, 2022
5308740
rename variables
epent May 14, 2022
2f427f8
delete each task
epent May 14, 2022
0eaa09b
minor fix
epent May 14, 2022
ca31b8a
add hover to AddTask
epent May 14, 2022
4f4091d
fix: ids written with "-"
epent May 14, 2022
90dc0cd
empty input validation
epent May 14, 2022
2a84b8d
add arrow on the blank list
epent May 14, 2022
26d6c92
animate AddTask button, add welcome sentence
epent May 14, 2022
62ffd1d
add hideWelcomePart
epent May 14, 2022
9dd2373
add showWelcomePart
epent May 14, 2022
fda2fbd
make arrow lighter, bigger
epent May 17, 2022
1e367e3
make white box smaller
epent May 17, 2022
8bc2e99
add ClearAll
epent May 17, 2022
fb28578
add animation when item is added
epent May 17, 2022
b2a23e1
add SortByName
epent May 17, 2022
e828a71
prepare for ex2
epent May 21, 2022
2a27e38
add module type to main.js
epent May 21, 2022
f5c331b
add add/remove/render item to ItemManager
epent May 21, 2022
ab4287b
add init method to Main
epent May 21, 2022
460e2ad
update removeItem method
epent May 21, 2022
5fcd9ce
add delete_icon
epent May 21, 2022
aa7efdc
add hr line under each item
epent May 21, 2022
634b470
add item when press Enter
epent May 21, 2022
1a4280f
add fetching pokemons
epent May 21, 2022
726cf10
retrieve multiple pokemons
epent May 21, 2022
cc0f812
handle 404 error
epent May 22, 2022
1e482c3
add pokemon only once
epent May 22, 2022
6668084
return to prev style
epent May 26, 2022
f2a7158
add ClearAll
epent May 26, 2022
2396dfe
add prev animation
epent May 26, 2022
542f7d1
list-item style fix
epent May 26, 2022
260cbcc
code refactor
epent May 26, 2022
48722f4
manage pokemon names in a Set
epent May 26, 2022
228cc41
minor fix
epent May 26, 2022
72ba01f
add SortByName, footer
epent May 28, 2022
3030f2f
ul has only li direct child
epent May 28, 2022
9cdbdff
fix removeItem
epent May 28, 2022
ecff181
change deleteicon color
epent May 28, 2022
1ddce54
clearInput to separate func
epent May 28, 2022
36ee2f8
add SortByName function
epent May 28, 2022
0fce44f
add pacjage.json
epent May 28, 2022
62372be
add toggleFooter func
epent May 28, 2022
2466257
refactor addItem func
epent May 28, 2022
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
13 changes: 13 additions & 0 deletions package-lock.json

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

20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "monday-u-exercises",
"description": "Welcome to monday-u official github repository! We are very excited to have you here! This is going to be so much fun! Here are a few general details:",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/epent/monday-u-exercises.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/epent/monday-u-exercises/issues"
},
"homepage": "https://github.com/epent/monday-u-exercises#readme"
}
14 changes: 0 additions & 14 deletions src/ex1/index.html

This file was deleted.

38 changes: 38 additions & 0 deletions src/ex1/index_ex1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Task Manager</title>
<link rel="stylesheet" href="style_ex1.css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Dosis:wght@300;400;500;600&display=swap"
rel="stylesheet"
/>
</head>
<body>
<div class="white-box">
<h1 class="main-header">Task Manager</h1>
<div class="task-input-wrapper">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice dom modeling!

<input class="task-input" type="text" placeholder="Add your new task" />
<button id="add-task-button" class="task-button hithere">
Add task
</button>
</div>
<ul class="task-list">
<div id="triangle" class="triangle"></div>
Copy link

@SergeiSafrigin SergeiSafrigin May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "ul" should only have "li" direct children

<div id="box" class="box"></div>
<h2 id="welcome-sentence" class="welcome">
Can't wait when you add your first task!
</h2>
</ul>
<button id="sort-by-name-button" class="task-button hidden">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to wrap the sort & clear all buttons with a footer container to easier positioning

Sort by name
</button>
<button id="clear-all-button" class="task-button hidden">
Clear All
</button>
</div>
</body>
<script src="script_ex1.js"></script>
</html>
Empty file removed src/ex1/script.js
Empty file.
141 changes: 141 additions & 0 deletions src/ex1/script_ex1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
const addButton = document.querySelector("#add-task-button");
const triangle = document.querySelector("#triangle");
const box = document.querySelector("#box");
const welcome = document.querySelector("#welcome-sentence");
const addTaskButton = document.querySelector(".task-button");
const addTaskInput = document.querySelector(".task-input");
const clearAllButton = document.querySelector("#clear-all-button");
const sortByNameButton = document.querySelector("#sort-by-name-button");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having all the elements outside here requires all the dom elements to exist when this file is loaded, which might not be the case in complex web apps that dynamically change the dom depending on the view

const listOfTasks = [];

addTaskButton.addEventListener("click", addTask);
clearAllButton.addEventListener("click", clearAll);
sortByNameButton.addEventListener("click", sortByName);

addTaskInput.addEventListener("keypress", (event) => {
if (event.key === "Enter") {
addTask();
}
});

function addTask() {
const task = document.querySelector(".task-input").value;
const text = capitalize(task);

if (text === "") {
alert("Input cannot be empty");
} else {
if (listOfTasks.length === 0) {
hideWelcomePart();
}
listOfTasks.push(text);
createTask(text);
}
}

function hideWelcomePart() {
addButton.classList.remove("hithere");
clearAllButton.classList.remove("hidden");
Copy link

@SergeiSafrigin SergeiSafrigin May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the welcome page into its own container (maybe with a shared class for some of the styles) will make your life easier here - 1 line of code instead of 6. Also in the current state, every new element you'll add to the task-list container will require you to handle it here as well

sortByNameButton.classList.remove("hidden");

triangle.classList.add("hidden");
box.classList.add("hidden");
welcome.classList.add("hidden");
}

function showWelcomePart() {
addButton.classList.add("hithere");
clearAllButton.classList.add("hidden");
sortByNameButton.classList.add("hidden");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here :)


triangle.classList.remove("hidden");
box.classList.remove("hidden");
welcome.classList.remove("hidden");
}

function createTask(text) {
//create elements

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job on the separation of concerns between the functions!

const divElm = document.createElement("div");
const liElm = document.createElement("li");
const deleteButton = document.createElement("button");

// style elements
divElm.classList.add("task");
divElm.classList.add("grow");
liElm.classList.add("task-item");
deleteButton.classList.add("delete-button");

//add textNodes
liElm.appendChild(document.createTextNode(text));
deleteButton.appendChild(document.createTextNode("X"));

//add ids
const idText = text.split(" ").join("-");
divElm.setAttribute("id", `${idText}`);
deleteButton.setAttribute("id", `${idText}-button`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be dangerous as these ids are not unique.


//append <li> and <button> to <div>
divElm.appendChild(liElm);
divElm.appendChild(deleteButton);

//append <div> to <ul>
const taskList = document.querySelector(".task-list");
taskList.appendChild(divElm);

//add clickListener to button
deleteButton.addEventListener("click", deleteTask);
liElm.addEventListener("click", () => alert(`Task: ${text}`));

//clear input
document.querySelector(".task-input").value = "";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be moved into it's own function

}

function deleteTask({ target }) {
const buttonId = target.id.split("-");
buttonId.pop();

//remove <div> with task
const divElementId = buttonId.join("-");
document.querySelector(`#${divElementId}`).remove();
Copy link

@SergeiSafrigin SergeiSafrigin May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider eaither using unique ids for the tasks. You could use UUID or traverse the dom from the target up until you find the task (target.parentElement)


// remove task from list
const taskText = buttonId.join(" ");
const elementIndex = listOfTasks.findIndex((task) => {
return task === taskText;
});
listOfTasks.splice(elementIndex, 1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: removing a task with a not unique name might not remove the one the user wanted. Consider making each task a complex object with id and text properties.


//show weolcome if list is empty
if (listOfTasks.length === 0) {
showWelcomePart();
}
}

function clearAll() {
listOfTasks.forEach((task) => {
const taskId = task.split(" ").join("-");
document.querySelector(`#${taskId}`).remove();
});
listOfTasks.splice(0);

showWelcomePart();
}

function sortByName() {
listOfTasks.forEach((task) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplication, consider moving it into it's own function

const taskId = task.split(" ").join("-");
document.querySelector(`#${taskId}`).remove();
});

listOfTasks.sort();
console.log(listOfTasks);

listOfTasks.forEach((task) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

createTask(task);
});
}

function capitalize(string) {
const updatedString = string.charAt(0).toUpperCase() + string.slice(1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like!

return updatedString;
}
Empty file removed src/ex1/style.css
Empty file.
Loading