Changeset - 58e96cb98d3a
[Not reviewed]
0 1 0
x - 15 months ago 2024-01-05 01:43:20
xbr@c3l.lu
feat: add lowestDate
1 file changed with 17 insertions and 1 deletions:
0 comments (0 inline, 0 general)
frontend/script.js
Show inline comments
 
function generateTable(data) {
 
    const tableBody = document.createElement("tbody");
 
    tableBody.classList.add("logs__tbody");
 

	
 
    for (let i = 0; i < data.length; i++) {
 
        const row = document.createElement("tr");
 
        row.classList.add("logs__trow");
 

	
 
        const domain = document.createElement("td");
 
        domain.classList.add("logs__item__name");
 
        const domainText = document.createTextNode(data[i].domain);
 
        domain.appendChild(domainText);
 
        row.appendChild(domain);
 

	
 
        const date = document.createElement("td");
 
        date.classList.add("logs__item__date");
 
        const dateText = document.createTextNode(data[i].date + " days ago");
 
        date.appendChild(dateText);
 
        row.appendChild(date);
 

	
 
        tableBody.appendChild(row);
 
    }
 

	
 
    const table = document.createElement("table");
 
    table.classList.add("logs__table");
 
    table.appendChild(tableBody);
 
    document.getElementById("logs").appendChild(table);
 
}
 

	
 
fetch("data.json").then(res => res.json()).then(data => generateTable(data.incidents));
 
\ No newline at end of file
 
function setLowestDate(data) {
 
    console.log(data);
 
    const lowestDate = data.reduce((minNum, expiredEntry) => {
 
        return Math.min(expiredEntry.date, minNum)
 
    }, Infinity);
 

	
 
    console.log(lowestDate);
 

	
 
    document.getElementById("time__tls").innerHTML = lowestDate;
 
}
 

	
 
fetch("data.json")
 
    .then(res => res.json())
 
    .then(data => {
 
        generateTable(data.incidents);
 
        setLowestDate(data.incidents);
 
    });
 
\ No newline at end of file
0 comments (0 inline, 0 general)