Progress bar: update right after a donation (LiteSpeed no-cache, more refreshes, visible fill for small amounts)
Test and Release / test (push) Successful in 1m19s
Test and Release / release (push) Successful in 8s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXhhC8xipsBR7e3o76i
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-16 08:34:59 -08:00
1 parent 55d1c34b1f
commit c6520b761a
3 files changed
+5 -3

No files matched your search

+2 -2
View File
@@ -79,7 +79,7 @@
bar.setAttribute('aria-valuenow', String(pct));
bar.setAttribute('aria-valuetext', p.reached ? (PT.reached || '') : of + ' (' + pct + '%)');
bar.setAttribute('aria-label', String(PT.label || '%s').replace('%s', function () { return p.title; }));
bar.firstChild.style.width = pct + '%';
bar.firstChild.style.width = ((pct < 2 && (parseInt(p.raised_minor, 10) || 0) > 0) ? 2 : pct) + '%';
box.querySelector('.sg-progress-amounts').textContent = of;
box.querySelector('.sg-progress-pct').textContent = pct + '%';
var tier = box.querySelector('.sg-progress-tier'), done = box.querySelector('.sg-progress-done');
@@ -110,7 +110,7 @@
refreshAll(true); // a cached page may hold old numbers
}
// After a successful donation: refresh now, and again shortly (a pending capture can finalize a moment later).
function afterDonation() { refreshAll(true); setTimeout(function () { refreshAll(true); }, 5000); }
function afterDonation() { refreshAll(true); [1500, 5000, 12000].forEach(function (ms) { setTimeout(function () { refreshAll(true); }, ms); }); }
function init(root) {
var pinned = parseInt(root.getAttribute('data-goal'), 10) || 0;
+2 -1
View File
@@ -76,13 +76,14 @@ final class Progress {
public static function html( array $p, array $labels ): string {
$e = static fn( string $s ): string => htmlspecialchars( $s, ENT_QUOTES, 'UTF-8' );
$pct = max( 0, min( 100, (int) $p['percent'] ) );
$fill = ( $pct < 2 && (int) ( $p['raised_minor'] ?? 0 ) > 0 ) ? 2 : $pct; // a first small donation still shows
$sub = static fn( string $tpl, array $v ): string => (string) preg_replace_callback( '/%(\d)\$s/', static fn( array $m ): string => $v[ (int) $m[1] - 1 ] ?? '', $tpl );
$of = $sub( $labels['of'] ?? '%1$s / %2$s', array( $p['raised_display'], $p['target_display'] ) );
$out = '<div class="sg-progress' . ( $p['reached'] ? ' sg-progress-reached' : '' ) . '" data-goal="' . (int) $p['goal_id'] . '">';
$out .= '<div class="sg-progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="' . $pct . '"'
. ' aria-valuetext="' . $e( $p['reached'] ? ( $labels['reached'] ?? '' ) : $of . ' (' . $pct . '%)' ) . '"'
. ' aria-label="' . $e( str_replace( '%s', (string) $p['title'], $labels['label'] ?? '%s' ) ) . '">'
. '<span class="sg-progress-fill" style="width:' . $pct . '%"></span></div>';
. '<span class="sg-progress-fill" style="width:' . $fill . '%"></span></div>';
$out .= '<div class="sg-progress-text"><span class="sg-progress-amounts">' . $e( $of ) . '</span> <span class="sg-progress-pct">' . $pct . '%</span></div>';
$out .= '<p class="sg-progress-tier"' . ( $p['tier'] ? '' : ' hidden' ) . '>'
. ( $p['tier'] ? $e( $sub( $labels['tier'] ?? '%1$s (%2$s)', array( $p['tier']['title'], $p['tier']['target_display'] ) ) ) : '' ) . '</p>';
+1
View File
@@ -85,6 +85,7 @@ final class DonateController {
$res = rest_ensure_response( self::progress_for( $goal ) );
// Short shared cache lets a CDN collapse bursts; the page JS adds a cache-busting parameter after a donation.
$res->header( 'Cache-Control', 'public, max-age=10, s-maxage=10' );
$res->header( 'X-LiteSpeed-Cache-Control', 'no-cache' ); // LiteSpeed would otherwise hold REST responses for days
return $res;
}