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

fix: Correct spelling of variables #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion 03-task-manager/final/models/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const TaskSchema = new mongoose.Schema({
type: String,
required: [true, 'must provide name'],
trim: true,
maxlength: [20, 'name can not be more than 20 characters'],
max_length: [20, 'name can not be more than 20 characters'],
},
completed: {
type: Boolean,
Expand Down
88 changes: 44 additions & 44 deletions 03-task-manager/final/public/browser-app.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const tasksDOM = document.querySelector('.tasks')
const loadingDOM = document.querySelector('.loading-text')
const formDOM = document.querySelector('.task-form')
const taskInputDOM = document.querySelector('.task-input')
const formAlertDOM = document.querySelector('.form-alert')
const tasksDOM = document.querySelector(".tasks");
const loadingDOM = document.querySelector(".loading-text");
const formDOM = document.querySelector(".task-form");
const taskInputDOM = document.querySelector(".task-input");
const formAlertDOM = document.querySelector(".form-alert");
// Load tasks from /api/tasks
const showTasks = async () => {
loadingDOM.style.visibility = 'visible'
loadingDOM.style.visibility = "visible";
try {
const {
data: { tasks },
} = await axios.get('/api/v1/tasks')
} = await axios.get("/api/v1/tasks");
if (tasks.length < 1) {
tasksDOM.innerHTML = '<h5 class="empty-list">No tasks in your list</h5>'
loadingDOM.style.visibility = 'hidden'
return
tasksDOM.innerHTML = '<h5 class="empty-list">No tasks in your list</h5>';
loadingDOM.style.visibility = "hidden";
return;
}
const allTasks = tasks
.map((task) => {
const { completed, _id: taskID, name } = task
return `<div class="single-task ${completed && 'task-completed'}">
const { completed, _id: taskID, name } = task;
return `<div class="single-task ${completed && "task-completed"}">
<h5><span><i class="far fa-check-circle"></i></span>${name}</h5>
<div class="task-links">

Expand All @@ -33,55 +33,55 @@ const showTasks = async () => {
<i class="fas fa-trash"></i>
</button>
</div>
</div>`
</div>`;
})
.join('')
tasksDOM.innerHTML = allTasks
.join("");
tasksDOM.innerHTML = allTasks;
} catch (error) {
tasksDOM.innerHTML =
'<h5 class="empty-list">There was an error, please try later....</h5>'
'<h5 class="empty-list">There was an error, please try later....</h5>';
}
loadingDOM.style.visibility = 'hidden'
}
loadingDOM.style.visibility = "hidden";
};

showTasks()
showTasks();

// delete task /api/tasks/:id

tasksDOM.addEventListener('click', async (e) => {
const el = e.target
if (el.parentElement.classList.contains('delete-btn')) {
loadingDOM.style.visibility = 'visible'
const id = el.parentElement.dataset.id
tasksDOM.addEventListener("click", async (e) => {
const el = e.target;
if (el.parentElement.classList.contains("delete-btn")) {
loadingDOM.style.visibility = "visible";
const id = el.parentElement.dataset.id;
try {
await axios.delete(`/api/v1/tasks/${id}`)
showTasks()
await axios.delete(`/api/v1/tasks/${id}`);
showTasks();
} catch (error) {
console.log(error)
console.log(error);
}
}
loadingDOM.style.visibility = 'hidden'
})
loadingDOM.style.visibility = "hidden";
});

// form

formDOM.addEventListener('submit', async (e) => {
e.preventDefault()
const name = taskInputDOM.value
formDOM.addEventListener("submit", async (e) => {
e.preventDefault();
const name = taskInputDOM.value;

try {
await axios.post('/api/v1/tasks', { name })
showTasks()
taskInputDOM.value = ''
formAlertDOM.style.display = 'block'
formAlertDOM.textContent = `success, task added`
formAlertDOM.classList.add('text-success')
await axios.post("/api/v1/tasks", { name });
showTasks();
taskInputDOM.value = "";
formAlertDOM.style.display = "block";
formAlertDOM.textContent = `success, task added`;
formAlertDOM.classList.add("text-success");
} catch (error) {
formAlertDOM.style.display = 'block'
formAlertDOM.innerHTML = `error, please try again`
formAlertDOM.style.display = "block";
formAlertDOM.innerHTML = `error, please try again`;
}
setTimeout(() => {
formAlertDOM.style.display = 'none'
formAlertDOM.classList.remove('text-success')
}, 3000)
})
formAlertDOM.style.display = "none";
formAlertDOM.classList.remove("text-success");
}, 3000);
});
6 changes: 3 additions & 3 deletions 03-task-manager/final/public/edit-task.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const taskIDDOM = document.querySelector('.task-edit-id')
const taskIDIOM = document.querySelector('.task-edit-id')
const taskNameDOM = document.querySelector('.task-edit-name')
const taskCompletedDOM = document.querySelector('.task-edit-completed')
const editFormDOM = document.querySelector('.single-task-form')
Expand All @@ -15,7 +15,7 @@ const showTask = async () => {
} = await axios.get(`/api/v1/tasks/${id}`)
const { _id: taskID, completed, name } = task

taskIDDOM.textContent = taskID
taskIDIOM.textContent = taskID
taskNameDOM.value = name
tempName = name
if (completed) {
Expand Down Expand Up @@ -44,7 +44,7 @@ editFormDOM.addEventListener('submit', async (e) => {

const { _id: taskID, completed, name } = task

taskIDDOM.textContent = taskID
taskIDIOM.textContent = taskID
taskNameDOM.value = name
tempName = name
if (completed) {
Expand Down