Add: js for loading post seen status

This commit is contained in:
Aroy-Art 2024-06-18 18:47:43 +02:00
parent 5296206c42
commit 1f07549530
Signed by: Aroy
GPG key ID: DB9689E9391DD156

View file

@ -4,3 +4,40 @@ document.querySelectorAll('[data-bs-toggle="popover"]')
.forEach(popover => {
new bootstrap.Popover(popover)
})
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);
});
};
});