The upload bar carries the house's cross for abandoning the flight
Browse files at this commit1ec4a8da93c949c47f73da1839fdc808c51d59dbParent: 627f67b3 changed files +30 -5
- crates/izlek-web/src/detail.rs +1 -1
- crates/izlek-web/src/layout.rs +18 -3
- style/main.scss +11 -1
crates/izlek-web/src/detail.rsmodified+1 -1
| @@ -2181,7 +2181,7 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool, tab: Tab) | ||
| 2181 | 2181 | <span class="detail-count">(detail.files.len())</span> |
| 2182 | 2182 | </div> |
| 2183 | 2183 | if may_comment { |
| 2184 | - <form class="file-upload" method="post" action="/files" enctype="multipart/form-data"> | |
| 2184 | + <form class="file-upload" method="post" action="/files" enctype="multipart/form-data" data-cancel-label=(t(lang, Key::Cancel)) data-empty-label=(t(lang, Key::File))> | |
| 2185 | 2185 | <input type="hidden" name="task_id" value=(detail.id.clone())> |
| 2186 | 2186 | <label class="field-box file-upload-box"> |
| 2187 | 2187 | (glyph::plus(cx).await?) |
crates/izlek-web/src/layout.rsmodified+18 -3
| @@ -535,7 +535,7 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { | ||
| 535 | 535 | var n = navStep(); \ |
| 536 | 536 | var box = form.querySelector('.file-upload-box'); \ |
| 537 | 537 | var input = form.querySelector('.file-upload-input'); \ |
| 538 | - var bar = null; \ | |
| 538 | + var bar = null, drop = null; \ | |
| 539 | 539 | if (box) { \ |
| 540 | 540 | bar = document.createElement('div'); \ |
| 541 | 541 | bar.className = 'upload-progress'; \ |
| @@ -543,19 +543,28 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { | ||
| 543 | 543 | fill.className = 'upload-progress-fill'; \ |
| 544 | 544 | bar.appendChild(fill); \ |
| 545 | 545 | box.appendChild(window.__izlekAdded(bar)); \ |
| 546 | + drop = document.createElement('button'); \ | |
| 547 | + drop.type = 'button'; \ | |
| 548 | + drop.className = 'file-chip-drop upload-progress-drop'; \ | |
| 549 | + var cancelLabel = form.getAttribute('data-cancel-label'); \ | |
| 550 | + if (cancelLabel) { drop.setAttribute('aria-label', cancelLabel); } \ | |
| 551 | + drop.innerHTML = '<svg class=\"glyph\" width=\"13\" height=\"13\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" aria-hidden=\"true\"><path d=\"M4 4l8 8M12 4l-8 8\"></path></svg>'; \ | |
| 552 | + drop.addEventListener('click', function (e) { e.preventDefault(); e.stopPropagation(); x.abort(); }); \ | |
| 553 | + box.appendChild(window.__izlekAdded(drop)); \ | |
| 546 | 554 | } \ |
| 547 | 555 | if (input) { input.disabled = true; window.__izlekOwn(input, [], ['disabled']); } \ |
| 548 | 556 | var settle = function () { \ |
| 549 | 557 | form.__izlekUploading = false; \ |
| 550 | 558 | if (input) { input.disabled = false; } \ |
| 551 | 559 | if (bar && bar.parentNode) { bar.parentNode.removeChild(bar); } \ |
| 560 | + if (drop && drop.parentNode) { drop.parentNode.removeChild(drop); } \ | |
| 552 | 561 | }; \ |
| 553 | 562 | var x = new XMLHttpRequest(); \ |
| 554 | 563 | x.open('POST', form.getAttribute('action') || window.location.href); \ |
| 555 | 564 | x.setRequestHeader('accept', 'text/html'); \ |
| 556 | 565 | x.upload.onprogress = function (ev) { \ |
| 557 | 566 | if (!fill) { return; } \ |
| 558 | - if (!bar.isConnected) { box.appendChild(bar); } \ | |
| 567 | + if (!bar.isConnected) { box.appendChild(bar); if (drop) { box.appendChild(drop); } } \ | |
| 559 | 568 | if (ev.lengthComputable && ev.total > 0) { fill.style.width = Math.min(100, Math.round((ev.loaded / ev.total) * 100)) + '%'; } \ |
| 560 | 569 | }; \ |
| 561 | 570 | x.onload = function () { \ |
| @@ -564,7 +573,13 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { | ||
| 564 | 573 | swap(x.responseText, x.responseURL || form.getAttribute('action') || window.location.href); \ |
| 565 | 574 | }; \ |
| 566 | 575 | x.onerror = function () { settle(); form.submit(); }; \ |
| 567 | - x.onabort = function () { settle(); }; \ | |
| 576 | + x.onabort = function () { \ | |
| 577 | + if (input) { input.value = ''; } \ | |
| 578 | + var name = box ? box.querySelector('.file-upload-name') : null; \ | |
| 579 | + var empty = form.getAttribute('data-empty-label'); \ | |
| 580 | + if (name && empty) { name.textContent = empty; } \ | |
| 581 | + settle(); \ | |
| 582 | + }; \ | |
| 568 | 583 | x.send(data); \ |
| 569 | 584 | return; \ |
| 570 | 585 | } \ |
style/main.scssmodified+11 -1
| @@ -2702,7 +2702,7 @@ img.avatar { | ||
| 2702 | 2702 | .upload-progress { |
| 2703 | 2703 | position: absolute; |
| 2704 | 2704 | left: 1px; |
| 2705 | - right: 1px; | |
| 2705 | + right: 22px; | |
| 2706 | 2706 | bottom: 1px; |
| 2707 | 2707 | height: 2px; |
| 2708 | 2708 | background: var(--border); |
| @@ -2718,6 +2718,16 @@ img.avatar { | ||
| 2718 | 2718 | transition: width var(--dur-fast) var(--ease); |
| 2719 | 2719 | } |
| 2720 | 2720 | |
| 2721 | +// The cancel cross is the chip remove control seconded to the bar: same | |
| 2722 | +// `.file-chip-drop` 20px hit box, glyph and hover-to-danger, only moved to | |
| 2723 | +// the track's right end. It cancels the request and nothing else — never | |
| 2724 | +// the picker the box itself is. | |
| 2725 | +.upload-progress-drop { | |
| 2726 | + position: absolute; | |
| 2727 | + right: 1px; | |
| 2728 | + bottom: 1px; | |
| 2729 | +} | |
| 2730 | + | |
| 2721 | 2731 | // -- comments --------------------------------------------------------------- |
| 2722 | 2732 | |
| 2723 | 2733 | .comment-list { |