From 1f075495309d55271baaa80dc2ada5306db87130 Mon Sep 17 00:00:00 2001 From: Aroy-Art Date: Tue, 18 Jun 2024 18:47:43 +0200 Subject: [PATCH] Add: js for loading post seen status --- archivist/static/js/main.js | 39 ++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) 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); + }); + }; +});