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

Status update #5

Merged
merged 9 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
1 change: 0 additions & 1 deletion dist/bundle55df76a2dc1d3425b0a3.js.map

This file was deleted.

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

1 change: 1 addition & 0 deletions dist/bundlea93a76c53fd4b8a66377.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>

<title>%= htmlWebpackPlugin.options.title %</title>
<script defer src="bundle55df76a2dc1d3425b0a3.js"></script></head>
<script defer src="bundlea93a76c53fd4b8a66377.js"></script></head>
<body>
<main class="container">
<div>
Expand Down
29 changes: 13 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import { addTask, taskarr } from './modules/addTask.js';
import renderList from './modules/displayList.js';
import './assets/three-dots.png';
import removeItems from './modules/removeItems.js';
import TaskStatus from './modules/updateStatus.js';
import { saveData } from './modules/userInput.js';

const userInput = document.querySelector('#userInput');
const addBtn = document.querySelector('#addBtn');
const clearAllBtn = document.querySelector('#clearAllBtn');

// to reload the page this should fix the double rendering issue
renderList(taskarr);
const reloading = () => {
setInterval(document.location.reload());
};

TaskStatus.updateStatus();
TaskStatus.clearCompleted();
// add tasks
addBtn.addEventListener('click', (event) => {
const description = userInput.value;
Expand All @@ -38,35 +41,29 @@ userInput.addEventListener('keypress', (event) => {
addTask(description, index);
reloading();
event.preventDefault();
localStorage.setItem('taskarr', JSON.stringify(taskarr));
saveData(taskarr);

return taskarr;
}
return taskarr;
});
renderList(taskarr);

// remove tasks
document.addEventListener('click', (event) => {
const dotsTrash = document.querySelectorAll('.dotsImg');
const dotsTrash = document.querySelectorAll('.trash');

dotsTrash.forEach((icon, index) => {
if (event.target === icon) {
removeItems(taskarr, index);
localStorage.setItem('taskarr', JSON.stringify(taskarr));
saveData(taskarr);

// this will sort out the index when removing Items
const sortedArr = [...taskarr];
index = taskarr.length;
index = taskarr.length + 1;
sortedArr.sort((a, b) => a.index - b.index);

reloading(sortedArr);
localStorage.setItem('taskarr', JSON.stringify(sortedArr));
reloading(taskarr);
saveData(sortedArr);
}
});
// return event.preventDefault();
});

// // this will clear all localstorage elements too, just temproary
clearAllBtn.addEventListener('click', () => {
window.localStorage.clear();
reloading();
});
7 changes: 3 additions & 4 deletions src/modules/addTask.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import TaskObject from './userInput.js';
// import { renderList } from './displayList.js';
import { TaskObject, saveData } from './userInput.js';

export const taskarr = JSON.parse(localStorage.getItem('taskarr')) || [];

export const addTask = (description, index) => {
index = taskarr.length;
const newTask = new TaskObject(description, index);
taskarr.push(newTask);
// this will sort out the user input index
// // this will sort out the user input index
const sortedArr = [...taskarr];
sortedArr.sort((a, b) => a.index - b.index);

localStorage.setItem('taskarr', JSON.stringify(sortedArr));
saveData(taskarr);
return taskarr;
};
16 changes: 10 additions & 6 deletions src/modules/displayList.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { taskarr } from './addTask.js';
// import update from './update.js';
// export const dots = '../assets/three-dots.png';
import '../assets/trash-can.png';
// const trashCan = './assets/trash-can.png';
import { saveData } from './userInput.js';

export const tasksList = document.querySelector('#tasksList');

Expand All @@ -13,10 +11,10 @@ export default (task) => {

if (taskarr[i].description !== '') {
task.innerHTML = `
<input type="checkbox" id="checkB" ${taskarr[i].completed} />
<input type="checkbox" class="checkB" ${taskarr[i].completed} />
<input class="newTasks" type="text" id="addItem" value="${taskarr[i].description}" />
<img class="trash" id="trash" src='./assets/trash-can.png' alt="" />

<img class="dotsImg" id="dotsImg" src='./assets/three-dots.png' alt="" />
`;
}
if (taskarr[i].description === '') {
Expand All @@ -26,7 +24,13 @@ export default (task) => {
tasksList.appendChild(task);
}

// const lis = document.querySelectorAll('.newTask');
const taskDescription = document.querySelectorAll('#addItem');
const dots = document.querySelectorAll('.dotsImg');

dots.forEach((dot) => {
dot.classList.add('hide');
});

taskDescription.forEach((task, index) => {
task.addEventListener('click', (event) => {
Expand All @@ -43,7 +47,7 @@ export default (task) => {
// the trick is with input
task.addEventListener('input', () => {
taskarr[index].description = task.value;
localStorage.setItem('taskarr', JSON.stringify(taskarr));
saveData(taskarr);
});
});
};
6 changes: 6 additions & 0 deletions src/modules/sortingFunction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const sortArray = (array) => {
// this will sort out the index when removing Items
const sortedArr = [...array];
sortedArr.sort((a, b) => a.index - b.index);
};
export default { sortArray };
34 changes: 34 additions & 0 deletions src/modules/updateStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { taskarr } from './addTask.js';
import { saveData } from './userInput.js';

export default class TaskStatus {
static updateStatus = () => {
const checkB = document.querySelectorAll('.checkB');

checkB.forEach((checkbox, i) => {
checkbox.addEventListener('change', () => {
if (!taskarr[i].completed) {
taskarr[i].completed = true;
saveData(taskarr);
checkbox.nextElementSibling.classList.add('completed');
} else {
taskarr[i].completed = false;
saveData(taskarr);
checkbox.nextElementSibling.classList.remove('completed');
}
});
});
};

static clearCompleted = () => {
const clearAllBtn = document.querySelector('#clearAllBtn');
clearAllBtn.addEventListener('click', () => {
const notCompleted = taskarr.filter((task) => task.completed !== true);
notCompleted.forEach((e, i) => {
e.index = i + 1;
});
saveData(notCompleted);
window.location.reload();
});
};
}
6 changes: 5 additions & 1 deletion src/modules/userInput.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export default class TaskObject {
export class TaskObject {
constructor(description, index) {
this.description = description;
this.completed = false;
this.index = index;
}
}

export const saveData = (data) => {
localStorage.setItem('taskarr', JSON.stringify(data));
};
8 changes: 4 additions & 4 deletions src/styles/sass/global.sass
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ $box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1), 0 6px 6px rgba(0, 0, 0, 0.1)
border-radius: 2px
font-family: $InterFont
font-weight: 500
font-size: 1rem
font-size: .8rem
letter-spacing: 0.001em
word-spacing: normal
background-color: $primary-color
color: $secondary-color
border: 0
box-shadow: $box-shadow
padding: 10px
padding: 5px
cursor: pointer
text-align: center

Expand All @@ -55,12 +55,12 @@ $box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1), 0 6px 6px rgba(0, 0, 0, 0.1)
letter-spacing: -0.0225rem
@mixin smlInterH3
color: black
font-size: 1.2rem
font-size: .8rem
font-family: $InterFont
font-weight: 600
letter-spacing: 0.0025rem
@mixin smlInterP
color: black
font-size: .9rem
font-size: .6rem
font-family: $InterFont
letter-spacing: 0.0125rem
Loading