Thread viewer for Bluesky

extracted notifications page to a class

+1
index.html
··· 165 165 <script src="thread_page.js"></script> 166 166 <script src="posting_stats_page.js"></script> 167 167 <script src="like_stats_page.js"></script> 168 + <script src="notifications_page.js"></script> 168 169 <script src="embed_component.js"></script> 169 170 <script src="post_component.js"></script> 170 171 <script src="skythread.js"></script>
+78
notifications_page.js
··· 1 + class NotificationsPage { 2 + 3 + constructor() { 4 + this.pageElement = $id('thread'); 5 + } 6 + 7 + show() { 8 + document.title = `Notifications - Skythread`; 9 + showLoader(); 10 + 11 + let isLoading = false; 12 + let firstPageLoaded = false; 13 + let finished = false; 14 + let cursor; 15 + 16 + loadInPages((next) => { 17 + if (isLoading || finished) { return; } 18 + isLoading = true; 19 + 20 + accountAPI.loadMentions(cursor).then(data => { 21 + let posts = data.posts.map(x => new Post(x)); 22 + 23 + if (posts.length > 0) { 24 + if (!firstPageLoaded) { 25 + hideLoader(); 26 + firstPageLoaded = true; 27 + 28 + let header = $tag('header'); 29 + let h2 = $tag('h2', { text: "Replies & Mentions:" }); 30 + header.append(h2); 31 + 32 + this.pageElement.appendChild(header); 33 + this.pageElement.classList.add('notifications'); 34 + } 35 + 36 + for (let post of posts) { 37 + if (post.parentReference) { 38 + let p = $tag('p.back'); 39 + p.innerHTML = `<i class="fa-solid fa-reply"></i> `; 40 + 41 + let { repo, rkey } = atURI(post.parentReference.uri); 42 + let url = linkToPostById(repo, rkey); 43 + let parentLink = $tag('a', { href: url }); 44 + p.append(parentLink); 45 + 46 + if (repo == accountAPI.user.did) { 47 + parentLink.innerText = 'Reply to you'; 48 + } else { 49 + parentLink.innerText = 'Reply'; 50 + api.fetchHandleForDid(repo).then(handle => { 51 + parentLink.innerText = `Reply to @${handle}`; 52 + }); 53 + } 54 + 55 + this.pageElement.appendChild(p); 56 + } 57 + 58 + let postView = new PostComponent(post, 'feed').buildElement(); 59 + this.pageElement.appendChild(postView); 60 + } 61 + } 62 + 63 + isLoading = false; 64 + cursor = data.cursor; 65 + 66 + if (!cursor) { 67 + finished = true; 68 + } else if (posts.length == 0) { 69 + next(); 70 + } 71 + }).catch(error => { 72 + hideLoader(); 73 + console.log(error); 74 + isLoading = false; 75 + }); 76 + }); 77 + } 78 + }
+2 -72
skythread.js
··· 11 11 window.threadPage = new ThreadPage(); 12 12 window.postingStatsPage = new PostingStatsPage(); 13 13 window.likeStatsPage = new LikeStatsPage(); 14 + window.notificationsPage = new NotificationsPage(); 14 15 15 16 $(document.querySelector('#search form')).addEventListener('submit', (e) => { 16 17 e.preventDefault(); ··· 307 308 } 308 309 309 310 if (page == 'notif') { 310 - showLoader(); 311 - showNotificationsPage(); 311 + window.notificationsPage.show(); 312 312 } else if (page == 'posting_stats') { 313 313 window.postingStatsPage.show(); 314 314 } else if (page == 'like_stats') { 315 315 window.likeStatsPage.show(); 316 316 } 317 - } 318 - 319 - function showNotificationsPage() { 320 - document.title = `Notifications - Skythread`; 321 - 322 - let isLoading = false; 323 - let firstPageLoaded = false; 324 - let finished = false; 325 - let cursor; 326 - 327 - loadInPages((next) => { 328 - if (isLoading || finished) { return; } 329 - isLoading = true; 330 - 331 - accountAPI.loadMentions(cursor).then(data => { 332 - let posts = data.posts.map(x => new Post(x)); 333 - 334 - if (posts.length > 0) { 335 - if (!firstPageLoaded) { 336 - hideLoader(); 337 - firstPageLoaded = true; 338 - 339 - let header = $tag('header'); 340 - let h2 = $tag('h2', { text: "Replies & Mentions:" }); 341 - header.append(h2); 342 - $id('thread').appendChild(header); 343 - $id('thread').classList.add('notifications'); 344 - } 345 - 346 - for (let post of posts) { 347 - if (post.parentReference) { 348 - let p = $tag('p.back'); 349 - p.innerHTML = `<i class="fa-solid fa-reply"></i> `; 350 - 351 - let { repo, rkey } = atURI(post.parentReference.uri); 352 - let url = linkToPostById(repo, rkey); 353 - let parentLink = $tag('a', { href: url }); 354 - p.append(parentLink); 355 - 356 - if (repo == accountAPI.user.did) { 357 - parentLink.innerText = 'Reply to you'; 358 - } else { 359 - parentLink.innerText = 'Reply'; 360 - api.fetchHandleForDid(repo).then(handle => { 361 - parentLink.innerText = `Reply to @${handle}`; 362 - }); 363 - } 364 - 365 - $id('thread').appendChild(p); 366 - } 367 - 368 - let postView = new PostComponent(post, 'feed').buildElement(); 369 - $id('thread').appendChild(postView); 370 - } 371 - } 372 - 373 - isLoading = false; 374 - cursor = data.cursor; 375 - 376 - if (!cursor) { 377 - finished = true; 378 - } else if (posts.length == 0) { 379 - next(); 380 - } 381 - }).catch(error => { 382 - hideLoader(); 383 - console.log(error); 384 - isLoading = false; 385 - }); 386 - }); 387 317 } 388 318 389 319 /** @param {Post} post */
+1
types.d.ts
··· 17 17 declare var threadPage: ThreadPage; 18 18 declare var postingStatsPage: PostingStatsPage; 19 19 declare var likeStatsPage: LikeStatsPage; 20 + declare var notificationsPage: NotificationsPage; 20 21 21 22 type json = Record<string, any>; 22 23