Upload progress while the photo crosses
Browse files at this commit04fdaa934e691f3ea85cd0db30ecc270c1ffacdbParent: f0995593 changed files +98 -1
- crates/im-web/assets/main.css +26 -0
- crates/im-web/src/layout.rs +44 -1
- style/main.scss +28 -0
crates/im-web/assets/main.cssmodified+26 -0
| @@ -477,6 +477,32 @@ body:has(.auth-stage) > .auth-stage::-webkit-scrollbar { | ||
| 477 | 477 | border-radius: var(--radius); |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | +.profile-upload-row { | |
| 481 | + display: flex; | |
| 482 | + gap: 8px; | |
| 483 | + align-items: center; | |
| 484 | +} | |
| 485 | + | |
| 486 | +.upload-progress { | |
| 487 | + flex: 1; | |
| 488 | + height: 2px; | |
| 489 | + background: var(--panel-sunken); | |
| 490 | + border-radius: 1px; | |
| 491 | + overflow: hidden; | |
| 492 | +} | |
| 493 | + | |
| 494 | +.upload-progress-fill { | |
| 495 | + height: 100%; | |
| 496 | + width: 0; | |
| 497 | + background: var(--accent); | |
| 498 | + transition: width var(--dur-fast) var(--ease); | |
| 499 | +} | |
| 500 | + | |
| 501 | +.upload-cancel { | |
| 502 | + height: 24px; | |
| 503 | + padding: 0 8px; | |
| 504 | +} | |
| 505 | + | |
| 480 | 506 | .profile-stats { |
| 481 | 507 | margin: 0; |
| 482 | 508 | display: flex; |
crates/im-web/src/layout.rsmodified+44 -1
| @@ -95,7 +95,50 @@ pub async fn avatar_script(cx: &Cx) -> Result { | ||
| 95 | 95 | }); \ |
| 96 | 96 | document.addEventListener('change', function (e) { \ |
| 97 | 97 | var input = e.target.closest ? e.target.closest('[data-autosubmit]') : null; \ |
| 98 | - if (input && input.form) { input.form.submit(); } \ | |
| 98 | + if (!input || !input.form || input.form.__imUploading) { return; } \ | |
| 99 | + var form = input.form; \ | |
| 100 | + var head = input.closest('.profile-head'); \ | |
| 101 | + if (!head) { form.submit(); return; } \ | |
| 102 | + /* Captured before the input is disabled — a disabled control \ | |
| 103 | + is no longer listed, and the post would carry no file. */ \ | |
| 104 | + var data = new FormData(form); \ | |
| 105 | + form.__imUploading = true; \ | |
| 106 | + input.disabled = true; \ | |
| 107 | + var row = document.createElement('div'); \ | |
| 108 | + row.className = 'profile-upload-row'; \ | |
| 109 | + var bar = document.createElement('div'); \ | |
| 110 | + bar.className = 'upload-progress'; \ | |
| 111 | + var fill = document.createElement('div'); \ | |
| 112 | + fill.className = 'upload-progress-fill'; \ | |
| 113 | + bar.appendChild(fill); \ | |
| 114 | + row.appendChild(bar); \ | |
| 115 | + var cancel = document.createElement('button'); \ | |
| 116 | + cancel.type = 'button'; \ | |
| 117 | + cancel.className = 'admin-action upload-cancel'; \ | |
| 118 | + cancel.textContent = '\\u00d7'; \ | |
| 119 | + cancel.setAttribute('aria-label', 'Cancel upload'); \ | |
| 120 | + row.appendChild(cancel); \ | |
| 121 | + head.insertAdjacentElement('afterend', row); \ | |
| 122 | + var settle = function () { \ | |
| 123 | + form.__imUploading = false; \ | |
| 124 | + input.disabled = false; \ | |
| 125 | + if (row.parentNode) { row.parentNode.removeChild(row); } \ | |
| 126 | + }; \ | |
| 127 | + var x = new XMLHttpRequest(); \ | |
| 128 | + x.open('POST', form.getAttribute('action')); \ | |
| 129 | + x.upload.onprogress = function (ev) { \ | |
| 130 | + if (ev.lengthComputable && ev.total > 0) { \ | |
| 131 | + fill.style.width = Math.min(100, Math.round((ev.loaded / ev.total) * 100)) + '%'; \ | |
| 132 | + } \ | |
| 133 | + }; \ | |
| 134 | + x.onload = function () { \ | |
| 135 | + settle(); \ | |
| 136 | + window.location.href = x.responseURL || form.getAttribute('action'); \ | |
| 137 | + }; \ | |
| 138 | + x.onerror = function () { settle(); form.submit(); }; \ | |
| 139 | + x.onabort = function () { input.value = ''; settle(); }; \ | |
| 140 | + cancel.addEventListener('click', function () { x.abort(); }); \ | |
| 141 | + x.send(data); \ | |
| 99 | 142 | }); \ |
| 100 | 143 | })();"; |
| 101 | 144 | view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } |
style/main.scssmodified+28 -0
| @@ -538,6 +538,34 @@ body:has(.auth-stage) { | ||
| 538 | 538 | border-radius: var(--radius); |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | +// Upload progress: a client-made hairline under the profile head while the | |
| 542 | +// photo crosses, a quiet cancel beside it — no native <progress> chrome. | |
| 543 | +.profile-upload-row { | |
| 544 | + display: flex; | |
| 545 | + gap: 8px; | |
| 546 | + align-items: center; | |
| 547 | +} | |
| 548 | + | |
| 549 | +.upload-progress { | |
| 550 | + flex: 1; | |
| 551 | + height: 2px; | |
| 552 | + background: var(--panel-sunken); | |
| 553 | + border-radius: 1px; | |
| 554 | + overflow: hidden; | |
| 555 | +} | |
| 556 | + | |
| 557 | +.upload-progress-fill { | |
| 558 | + height: 100%; | |
| 559 | + width: 0; | |
| 560 | + background: var(--accent); | |
| 561 | + transition: width var(--dur-fast) var(--ease); | |
| 562 | +} | |
| 563 | + | |
| 564 | +.upload-cancel { | |
| 565 | + height: 24px; | |
| 566 | + padding: 0 8px; | |
| 567 | +} | |
| 568 | + | |
| 541 | 569 | .profile-stats { |
| 542 | 570 | margin: 0; |
| 543 | 571 | display: flex; |