Skip to content

Commit

Permalink
Merge pull request #3 from Sanja969/add-Edit-Remove
Browse files Browse the repository at this point in the history
Milestone 2: Add, Edit and Remove functionalities
  • Loading branch information
Sanja969 committed Jun 1, 2022
2 parents 16aae7a + bc05435 commit 2e5d641
Show file tree
Hide file tree
Showing 16 changed files with 1,013 additions and 59 deletions.
Binary file added dist/667a1805229ae33e7d3d.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
265 changes: 265 additions & 0 deletions dist/add.bundle.js

Large diffs are not rendered by default.

229 changes: 229 additions & 0 deletions dist/addTaskUI.bundle.js

Large diffs are not rendered by default.

246 changes: 218 additions & 28 deletions dist/index.bundle.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<meta charset="utf-8">
<title>To Do List</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script defer src="index.bundle.js"></script></head>
<script defer src="index.bundle.js"></script><script defer src="add.bundle.js"></script><script defer src="remove.bundle.js"></script><script defer src="addTaskUI.bundle.js"></script><script defer src="tasks.bundle.js"></script></head>
<body>
<main><div class="listContainer">
<div class="title"><h3>Today's To Do</h3><img class = 'imgRefresh' alt = 'refresh'></div>
<div class="title"><h3>Today's To Do</h3><img class = 'imgRefresh' alt = 'refresh' src = '2a4441e2b7ef51d897cb.png'></div>
<form class = "addTask">
<input type="text" placeholder="Add to your list...">
<input type="submit" value = '' class = "submit"><img class = 'imgSubmit' alt = 'return'>
<input type="text" placeholder="Add to your list..." class = 'add'>
<input type="submit" value = '' class = "submit"><img class = 'imgSubmit' alt = 'return' src = 'e776f112fe439b59d722.png'>
</form>
<ul class="to-do-list"></ul>
<div class="clear">Clear all completed</div>
Expand Down
66 changes: 66 additions & 0 deletions dist/remove.bundle.js

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

54 changes: 54 additions & 0 deletions dist/tasks.bundle.js

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

24 changes: 24 additions & 0 deletions src/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import appendTask from './addTaskUI.js';

const list = [];

class Task {
constructor(description, completed, index) {
this.description = description;
this.completed = completed;
this.index = index;
}
}

const addTask = (description, completed, index) => {
const task = new Task(description, completed, index);
list.push(task);
appendTask(task);
localStorage.setItem('tasks', JSON.stringify(list));
};

export {
addTask,
list,
Task,
};
66 changes: 66 additions & 0 deletions src/addTaskUI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import moveSrc from './move.png';
import trashSrc from './trash.png';
import clearTask from './remove.js';

const toDoListUI = document.querySelector('.to-do-list');
const endCont = document.querySelector('.clear');

const appendTask = (item, list) => {
const taskUI = document.createElement('li');
taskUI.innerHTML = `<div><input type='checkbox' id = task-${item.index} class = 'check' value=${item.index}><p size='12'>${item.description}</p></div>`;
const moveImg = new Image();
moveImg.src = moveSrc;
taskUI.appendChild(moveImg);
moveImg.addEventListener('click', () => {
if (moveImg.src === moveSrc) {
moveImg.src = trashSrc;
moveImg.parentNode.style.background = 'rgba(214, 214, 148, 0.534)';
taskUI.children[0].children[1].setAttribute('contenteditable', 'true');
endCont.textContent = 'Chick here to save changes';
endCont.style.background = 'rgba(136, 209, 133, 0.534)';
endCont.style.fontSize = '24px';
endCont.style.color = 'green';
endCont.addEventListener('click', (e) => {
if (moveImg.src === trashSrc) {
e.target.textContent = 'Clear all completed';
e.target.style.background = 'rgba(168, 157, 157, 0.534)';
e.target.style.fontSize = '16px';
e.target.style.color = 'black';
taskUI.children[0].children[1].setAttribute('contenteditable', 'false');
moveImg.src = moveSrc;
list.forEach((element) => {
if (element.index === item.index) {
element.description = taskUI.children[0].children[1].textContent;
localStorage.setItem('tasks', JSON.stringify(list));
}
});
}
});
} else {
clearTask(item.index, list);
}
});
toDoListUI.appendChild(taskUI);
const check = taskUI.children[0].children[0];

if (item.completed === true) {
check.checked = true;
taskUI.children[0].style.textDecoration = 'line-through';
}

check.style.cursor = 'pointer';
moveImg.style.cursor = 'pointer';
check.addEventListener('click', () => {
if (check.checked === true) {
taskUI.children[0].style.textDecoration = 'line-through';
item.completed = true;
localStorage.setItem('tasks', JSON.stringify(list));
} else {
taskUI.children[0].style.textDecoration = 'none';
item.completed = false;
localStorage.setItem('tasks', JSON.stringify(list));
}
});
};

export default appendTask;
6 changes: 3 additions & 3 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</head>
<body>
<main><div class="listContainer">
<div class="title"><h3>Today's To Do</h3><img class = 'imgRefresh' alt = 'refresh'></div>
<div class="title"><h3>Today's To Do</h3><img class = 'imgRefresh' alt = 'refresh' src = '../src/refresh.png'></div>
<form class = "addTask">
<input type="text" placeholder="Add to your list...">
<input type="submit" value = '' class = "submit"><img class = 'imgSubmit' alt = 'return'>
<input type="text" placeholder="Add to your list..." class = 'add'>
<input type="submit" value = '' class = "submit"><img class = 'imgSubmit' alt = 'return' src = '../src/return.png'>
</form>
<ul class="to-do-list"></ul>
<div class="clear">Clear all completed</div>
Expand Down
56 changes: 32 additions & 24 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
import './style.css';
import moveSrc from './move.png';
import refreshSrc from './refresh.png';
import returnSrc from './return.png';
import {
addTask,
list,
} from './add.js';
import clearTask from './remove.js';
import appendTask from './addTaskUI.js';
import Task from './tasks.js';

const storage = JSON.parse(localStorage.getItem('tasks')) || [];
const addUI = document.querySelector('.add');
const deleteUI = document.querySelector('.clear');
const returnImg = document.querySelector('.imgSubmit');
returnImg.src = returnSrc;

const refreshImg = document.querySelector('.imgRefresh');
refreshImg.src = refreshSrc;

const toDoListUI = document.querySelector('.to-do-list');
storage.forEach((item) => {
const task = new Task(item.description, item.completed, item.index);
list.push(task);
appendTask(task, list);
});

class Task {
constructor(description, completed, index) {
this.description = description;
this.completed = completed;
this.index = index;
}
}
returnImg.src = returnSrc;
refreshImg.src = refreshSrc;

const list = [new Task('Finsh the project', false, 0), new Task('Wash the dishes', false, 1), new Task('Go on zoom meeting', false, 2)];
addUI.addEventListener('change', () => {
addTask(addUI.value, false, list.length + 1);
});

const appendTask = (item) => {
const taskUI = document.createElement('li');
taskUI.innerHTML = `<label><input type='checkbox' id = task-${item.index} class = 'check' value=${item.index}>${item.description}</label>`;
const moveImg = new Image();
moveImg.src = moveSrc;
taskUI.appendChild(moveImg);
toDoListUI.appendChild(taskUI);
};
refreshImg.addEventListener('click', () => {
document.location.href = './index.html';
});

for (let i = 0; i < list.length; i += 1) {
appendTask(list[i]);
}
deleteUI.addEventListener('click', () => {
const checks = document.querySelectorAll('.check');
for (let i = 0; i < checks.length; i += 1) {
if (checks[i].checked) {
clearTask(checks[i].value, list);
}
}
localStorage.setItem('tasks', JSON.stringify(list));
});
20 changes: 20 additions & 0 deletions src/remove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const clearTask = (index, list) => {
if (list.length === 0) return;

list.splice(index - 1, 1);

document.querySelector(`#task-${index}`).parentNode.parentNode.remove();
localStorage.setItem('tasks', JSON.stringify(list));

if (list.length === 0) return;

for (let i = index - 1; i < list.length; i += 1) {
const nextCheck = document.querySelector(`#task-${i + 2}`);
nextCheck.id = `task-${i + 1}`;
nextCheck.value -= 1;
list[i].index -= 1;
localStorage.setItem('tasks', JSON.stringify(list));
}
};

export default clearTask;
20 changes: 20 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ main {
border: none;
}

.addTask > input:focus {
outline: none !important;
}

.submit {
background-color: inherit;
}
Expand All @@ -56,6 +60,20 @@ main {
justify-content: space-between;
}

.to-do-list > * > div {
display: flex;
align-items: center;
}

.to-do-list > * > div > p {
white-space: nowrap;
}

.to-do-list > * > div > p:focus {
outline: none !important;
white-space: nowrap;
}

.check {
margin-right: 10px;
}
Expand All @@ -64,6 +82,7 @@ img {
width: 20px;
height: 20px;
background: inherit;
cursor: pointer;
}

.clear {
Expand All @@ -72,4 +91,5 @@ img {
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
8 changes: 8 additions & 0 deletions src/tasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Task {
constructor(description, completed, index) {
this.description = description;
this.completed = completed;
this.index = index;
}
}
export default Task;
Binary file added src/trash.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2e5d641

Please sign in to comment.