diff --git a/archivist/static/js/main.js b/archivist/static/js/main.js index 97eb346..6a8ec6a 100644 --- a/archivist/static/js/main.js +++ b/archivist/static/js/main.js @@ -3,4 +3,41 @@ import * as bootstrap from 'bootstrap' document.querySelectorAll('[data-bs-toggle="popover"]') .forEach(popover => { new bootstrap.Popover(popover) - }) \ No newline at end of file + }) + + +window.addEventListener('load', function() { + + seenPosts = document.querySelectorAll('.seen-overlay'); + + for (let i = 0; i < seenPosts.length; i++) { + let hash = seenPosts[i].getAttribute('data-hash'); + + fetch('/api/profile/seen_posts/' + hash, { + method: 'GET' + }) + .then(response => { + if (response.ok) { + // Handle the response here + return response.json(); // Parse the response JSON if applicable + } else { + throw new Error('Network response was not ok.'); + } + }) + .then(data => { + // Access the JSON data here + if (data.hasOwnProperty('seen')) { + if (data.seen === true) { + seenPosts[i].innerText = 'Viewed'; + seenPosts[i].setAttribute('data-seen', 'true'); + }; + } else { + console.log('No data.seen in response for hash:', hash, data); + } + }) + .catch(error => { + // Handle errors here + console.error('Error:', error); + }); + }; +});