Add: js for loading post seen status
This commit is contained in:
parent
5296206c42
commit
1f07549530
1 changed files with 38 additions and 1 deletions
|
@ -3,4 +3,41 @@ import * as bootstrap from 'bootstrap'
|
|||
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);
|
||||
});
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue