friendship ended with social-app. php is my new best friend
1if (document.querySelector('main').classList.contains('feed') && document.querySelectorAll('.postsList > .post').length > 0) {
2 const observerCheck = (entry, observer) => {
3 if (entry[0].isIntersecting) {
4 console.log('intersect');
5 const container = document.querySelector('.postsList');
6 const lastPost = document.querySelector('.postsList > .post:last-child');
7 const uri = container.getAttribute('data-uri');
8 const cursor = container.getAttribute('data-cursor');
9 const params = new URLSearchParams();
10 params.append("feed", uri);
11 params.append("cursor", cursor);
12 observer.unobserve(lastPost);
13 fetch(`/api/feedPosts?${params}`)
14 .then((data) => {
15 data.text().then((content) => {
16 const data = JSON.parse(content);
17 container.innerHTML += data.posts;
18 container.setAttribute(data.cursor);
19 const newobserver = new IntersectionObserver(observerCheck);
20 newobserver.observe(document.querySelector('.postsList > .post:last-child'));
21 });
22 }, (err) => {
23 console.error(err);
24 const newobserver = new IntersectionObserver(observerCheck);
25 newobserver.observe(document.querySelector('.postsList > .post:last-child'));
26 });
27 }
28 }
29 const observer = new IntersectionObserver(observerCheck);
30 observer.observe(document.querySelector('.postsList > .post:last-child'));
31}