Thread viewer for Bluesky

refactoring in post component

+52 -23
post_component.js
··· 121 121 let content = $tag('div.content'); 122 122 123 123 if (this.context == 'thread' && !this.isRoot) { 124 - let edge = $tag('div.edge'); 125 - let line = $tag('div.line'); 126 - edge.appendChild(line); 127 - div.appendChild(edge); 128 - 129 - let plus = $tag('img.plus', { src: 'icons/subtract-square.png' }); 130 - div.appendChild(plus); 131 - 132 - [edge, plus].forEach(x => { 133 - x.addEventListener('click', (e) => { 134 - e.preventDefault(); 135 - this.toggleSectionFold(); 136 - }); 137 - }); 124 + let edgeMargin = this.buildEdgeMargin(); 125 + div.appendChild(edgeMargin); 138 126 } 139 127 140 128 let wrapper; ··· 240 228 return h; 241 229 } 242 230 231 + buildEdgeMargin() { 232 + let div = $tag('div.margin'); 233 + 234 + let edge = $tag('div.edge'); 235 + let line = $tag('div.line'); 236 + edge.appendChild(line); 237 + div.appendChild(edge); 238 + 239 + let plus = $tag('img.plus', { src: 'icons/subtract-square.png' }); 240 + div.appendChild(plus); 241 + 242 + [edge, plus].forEach(x => { 243 + x.addEventListener('click', (e) => { 244 + e.preventDefault(); 245 + this.toggleSectionFold(); 246 + }); 247 + }); 248 + 249 + return div; 250 + } 251 + 243 252 /** @param {string} url, @returns {HTMLImageElement} */ 244 253 245 254 buildUserAvatar(url) { ··· 324 333 } 325 334 326 335 if (!this.isRoot && this.context != 'quote' && this.post.quoteCount) { 327 - let q = new URL(getLocation()); 328 - q.searchParams.set('quotes', this.linkToPost); 336 + let quotesLink = this.buildQuotesIconLink(this.post.quoteCount, false); 337 + stats.append(quotesLink); 338 + } 329 339 330 - let quotes = $tag('a', { 331 - html: `<i class="fa-regular ${this.post.quoteCount > 1 ? 'fa-comments' : 'fa-comment'}"></i> ${this.post.quoteCount}`, 332 - href: q.toString() 333 - }); 340 + return stats; 341 + } 342 + 343 + /** @param {number} count, @param {boolean} expanded, @returns {AnyElement} */ 344 + 345 + buildQuotesIconLink(count, expanded) { 346 + let q = new URL(getLocation()); 347 + q.searchParams.set('quotes', this.linkToPost); 348 + 349 + let url = q.toString(); 350 + let icon = `<i class="fa-regular ${count > 1 ? 'fa-comments' : 'fa-comment'}"></i>`; 334 351 335 - stats.append(quotes); 352 + if (expanded) { 353 + let span = $tag('span', { html: `${icon} ` }); 354 + let link = $tag('a', { text: (count > 1) ? `${count} quotes` : '1 quote', href: url }); 355 + span.append(link); 356 + return span; 357 + } else { 358 + return $tag('a', { html: `${icon} ${count}`, href: url }); 336 359 } 360 + } 337 361 338 - return stats; 362 + /** @param {number} quoteCount, @param {boolean} expanded */ 363 + 364 + appendQuotesIconLink(quoteCount, expanded) { 365 + let stats = this.rootElement.querySelector(':scope > .content > p.stats'); 366 + let quotesLink = this.buildQuotesIconLink(quoteCount, expanded); 367 + stats.append(quotesLink); 339 368 } 340 369 341 370 /** @returns {AnyElement} */ ··· 554 583 } 555 584 556 585 toggleSectionFold() { 557 - let plus = this.rootElement.querySelector('.plus'); 586 + let plus = this.rootElement.querySelector(':scope > .margin .plus'); 558 587 559 588 if (this.isCollapsed()) { 560 589 this.rootElement.classList.remove('collapsed');
+1 -10
skythread.js
··· 672 672 673 673 loadQuoteCount?.then(count => { 674 674 if (count > 0) { 675 - let stats = view.querySelector(':scope > .content > p.stats'); 676 - let q = new URL(getLocation()); 677 - q.searchParams.set('quotes', component.linkToPost); 678 - stats.append($tag('i', { className: count > 1 ? 'fa-regular fa-comments' : 'fa-regular fa-comment' })); 679 - stats.append(" "); 680 - let quotes = $tag('a', { 681 - text: count > 1 ? `${count} quotes` : '1 quote', 682 - href: q.toString() 683 - }); 684 - stats.append(quotes); 675 + component.appendQuotesIconLink(count, true); 685 676 } 686 677 }).catch(error => { 687 678 console.warn("Couldn't load quote count: " + error);
+8 -12
style.css
··· 389 389 border-left: 2px solid #888; 390 390 } 391 391 392 + .post .plus { 393 + position: absolute; 394 + top: 8px; 395 + left: -6px; 396 + width: 14px; 397 + } 398 + 392 399 .post.collapsed .line { 393 400 display: none; 394 401 } ··· 402 409 margin-top: 25px; 403 410 } 404 411 405 - .post.flat > .edge { 412 + .post.flat > .margin { 406 413 display: none; 407 414 } 408 415 ··· 425 432 426 433 .post.muted .missing { 427 434 color: #bbb; 428 - } 429 - 430 - .post .plus { 431 - position: absolute; 432 - top: 8px; 433 - left: -6px; 434 - width: 14px; 435 - } 436 - 437 - .post.flat > .plus { 438 - display: none; 439 435 } 440 436 441 437 .post h2 {