-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateHistory.js
More file actions
42 lines (35 loc) · 1.41 KB
/
updateHistory.js
File metadata and controls
42 lines (35 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import weightChart from './weightChart.js';
import {sortWeightHistory, sortNames} from './sortData.js';
export default function updateHistory(user) {
let table = document.querySelector('table');
table.innerHTML = '';
sortWeightHistory(user);
user.weightHistory.forEach((weightInfo, index) => {
let tableRow = document.createElement('tr');
table.appendChild(tableRow);
let date = document.createElement('td');
date.textContent = weightInfo.date;
tableRow.appendChild(date);
let weight = document.createElement('td');
weight.textContent = weightInfo.weight + ' kg'
tableRow.appendChild(weight);
let iconDiv = document.createElement('td');
iconDiv.classList.add ('text-danger');
tableRow.appendChild(iconDiv);
let icon = document.createElement('i');
icon.classList.add('far', 'fa-trash-alt');
iconDiv.appendChild(icon);
icon.addEventListener('click', () => {
if(confirm('Are you sure?')){
user.weightHistory.splice(index, 1);
axios.patch(`https://myrestapi01.herokuapp.com/users/${user.id}`, user)
.then((response) =>{
user=response.data;
updateHistory(user);
})
.catch((err) => console.log(err));
}
})
})
weightChart(user.weightHistory);
}