Skip to content

Commit 5a32e72

Browse files
authored
xftp-web: add "Upload your file" link after download completes (#1736)
* xftp-web: add "Upload your file" link after download completes * xftp-web: call initUpload directly instead of hashchange dispatch
1 parent 782cacf commit 5a32e72

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

xftp-web/web/download.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {createCryptoBackend} from './crypto-backend.js'
22
import {createProgressRing} from './progress.js'
3+
import {initUpload} from './upload.js'
34
import {t} from './i18n.js'
45
import {
56
newXFTPAgent, closeXFTPAgent,
@@ -39,6 +40,7 @@ export function initDownload(app: HTMLElement, hash: string) {
3940
<div id="dl-progress" class="stage" hidden>
4041
<div id="dl-progress-container"></div>
4142
<p id="dl-status">${t('downloading', 'Downloading\u2026')}</p>
43+
<a id="dl-upload-link" class="upload-link" hidden href="#">${t('uploadYourFile', 'Upload your file')}</a>
4244
</div>
4345
<div id="dl-error" class="stage" hidden>
4446
<p class="error" id="dl-error-msg"></p>
@@ -54,6 +56,7 @@ export function initDownload(app: HTMLElement, hash: string) {
5456
const dlBtn = document.getElementById('dl-btn')!
5557
const errorMsg = document.getElementById('dl-error-msg')!
5658
const retryBtn = document.getElementById('dl-retry-btn')!
59+
const uploadLink = document.getElementById('dl-upload-link')!
5760

5861
function showStage(stage: HTMLElement) {
5962
for (const s of [readyStage, progressStage, errorStage]) s.hidden = true
@@ -72,6 +75,11 @@ export function initDownload(app: HTMLElement, hash: string) {
7275

7376
dlBtn.addEventListener('click', startDownload)
7477
retryBtn.addEventListener('click', () => showStage(readyStage))
78+
uploadLink.addEventListener('click', (e) => {
79+
e.preventDefault()
80+
history.replaceState(null, '', window.location.pathname)
81+
initUpload(app)
82+
})
7583

7684
async function startDownload() {
7785
showStage(progressStage)
@@ -132,6 +140,7 @@ export function initDownload(app: HTMLElement, hash: string) {
132140

133141
ring.update(1)
134142
statusText.textContent = t('downloadComplete', 'Download complete')
143+
uploadLink.hidden = false
135144
app.dispatchEvent(new CustomEvent('xftp:download-complete', {detail: {fileName}, bubbles: true}))
136145
} catch (err: any) {
137146
const msg = err?.message ?? String(err)

xftp-web/web/style.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@
7777
background: #f9fafb;
7878
}
7979

80+
/* Upload link */
81+
:is(#app, [data-xftp-app]) .upload-link {
82+
margin-top: 12px;
83+
color: #3b82f6;
84+
font-size: .9rem;
85+
text-decoration: none;
86+
cursor: pointer;
87+
}
88+
:is(#app, [data-xftp-app]) .upload-link:not([hidden]) {
89+
display: inline-block;
90+
}
91+
:is(#app, [data-xftp-app]) .upload-link:hover { text-decoration: underline; }
92+
8093
/* Messages */
8194
:is(#app, [data-xftp-app]) .success { color: #16a34a; font-weight: 600; }
8295
:is(#app, [data-xftp-app]) .error { color: #dc2626; font-weight: 500; margin-bottom: 12px; }
@@ -128,4 +141,5 @@
128141
background: rgba(34,197,94,.1);
129142
color: #d1d5db;
130143
}
144+
.dark :is(#app, [data-xftp-app]) .upload-link { color: #60a5fa; }
131145
.dark :is(#app, [data-xftp-app]) .security-note a { color: #60a5fa; }

0 commit comments

Comments
 (0)