What's new

Welcome to the forum 👋, Visitor

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

Label New Update appears after i upload new version

malveiro75

New member
Joined
Sep 15, 2024
Messages
1
Reaction score
0
HTML Coins
0
Hello , i'm newbie in this forum and i need some help

I'm trying to insert a New Update Label in my html file , so , i have csv file in a format dd_mm_yyyy , in a shared folder that is uploaded in my page , and when i make an update , the label must appear . Example , In my page it appears the verison that is upload , 14_09_2024 , but if i have a 16_09_2024.csv , the label appears .
My problem , is the label disappear when i upload the new version , but i hit F5 , it appears .
Here is my code :
function checkForNewFile() {
var storedFileName = localStorage.getItem('latestFileName');
var fileNamePattern = /\d{2}_\d{2}_\d{4}/; // Regex for dd_mm_yyyy format
var currentDate = currentFileName.match(fileNamePattern)[0];

// Check if a new update flag exists
var newUpdateFlag = localStorage.getItem('newUpdateFlag');

if (storedFileName && storedFileName !== currentFileName) {
document.getElementById('newUpdateLabel').style.display = 'inline'; // Show new update label
localStorage.setItem('newUpdateFlag', 'true'); // Store that an update is available
} else if (storedFileName === currentFileName) {
document.getElementById('newUpdateLabel').style.display = 'none'; // Hide the label if no update
localStorage.removeItem('newUpdateFlag'); // Ensure the flag is cleared if up to date
}
}
// Load CSV data from localStorage on page load
window.onload = function() {
var storedCSV = localStorage.getItem('csvData');
var storedFileName = localStorage.getItem('csvFileName');
var latestFileName = localStorage.getItem('latestFileName'); // Latest uploaded file name

if (storedCSV && storedFileName) {
parseCSV(storedCSV);
currentFileName = getFileNameWithoutExtension(storedFileName);
displayVersion(currentFileName); // Display CSV version
document.getElementById('status').textContent = "Using stored CSV data.";
document.getElementById('searchSection').style.display = 'block';
document.getElementById('uploadSection').style.display = 'none';
document.getElementById('resetSection').style.display = 'block';

// If no latest file is stored yet, store the current uploaded file as latest
if (!latestFileName) {
localStorage.setItem('latestFileName', storedFileName);
}

// Check for new file
checkForNewFile();
}
};


// Upload CSV and Parse the Data
document.getElementById('uploadButton').addEventListener('click', function() {
var fileInput = document.getElementById('csvFile');
var file = fileInput.files[0];
if (file) {
var reader = new FileReader();
reader.onload = function(e) {
var csvData = e.target.result;
localStorage.setItem('csvData', csvData);
localStorage.setItem('csvFileName', file.name); // Store the filename
localStorage.setItem('latestFileName', file.name); // Update latest file in localStorage
currentFileName = getFileNameWithoutExtension(file.name);
displayVersion(currentFileName); // Display the CSV version
parseCSV(csvData);

// Clear the "New Update Available" label after upload
document.getElementById('newUpdateLabel').style.display = 'none';
localStorage.removeItem('newUpdateFlag'); // Clear the stored flag

document.getElementById('status').textContent = "File uploaded successfully!";
document.getElementById('searchSection').style.display = 'block';
document.getElementById('uploadSection').style.display = 'none';
document.getElementById('resetSection').style.display = 'block';
};
reader.readAsText(file);
} else {
document.getElementById('status').textContent = "Please choose a file.";
}
});

What i'm doing wrong ??
Thanks in advance
 

Theme customization system

You can customize some areas of the forum theme from this menu.

  • Wide/Narrow view

    You can control a structure that you can use to use your theme wide or narrow.

    Grid view forum list

    You can control the layout of the forum list in a grid or ordinary listing style structure.

    Picture grid mode

    You can control the structure where you can open/close images in the grid forum list.

    Close sidebar

    You can get rid of the crowded view in the forum by closing the sidebar.

    Fixed sidebar

    You can make it more useful and easier to access by pinning the sidebar.

    Close radius

    You can use the radius at the corners of the blocks according to your taste by closing/opening it.

  • Choose the color combination that reflects your taste
    Background images
    Color gradient backgrounds
Back