From 7716ba6e77982805256545042197d9925bb26c40 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Thu, 28 Feb 2019 14:28:18 -0800 Subject: [PATCH] added warning page for browsers without streams downloading big files (#1175) * added warning page for browsers without streams downloading big files * fixed illustration size in Edge * updated nostreams style --- app/ui/download.js | 165 ++++++++-------------------------- app/ui/downloadCompleted.js | 24 +++++ app/ui/downloadPassword.js | 83 +++++++++++++++++ app/ui/error.js | 2 +- app/ui/noStreams.js | 100 +++++++++++++++++++++ app/ui/notFound.js | 2 +- public/locales/en-US/send.ftl | 4 + 7 files changed, 251 insertions(+), 129 deletions(-) create mode 100644 app/ui/downloadCompleted.js create mode 100644 app/ui/downloadPassword.js create mode 100644 app/ui/noStreams.js diff --git a/app/ui/download.js b/app/ui/download.js index 63b755fa..b5d8c060 100644 --- a/app/ui/download.js +++ b/app/ui/download.js @@ -1,91 +1,12 @@ /* global downloadMetadata */ const html = require('choo/html'); const archiveTile = require('./archiveTile'); -const assets = require('../../common/assets'); const modal = require('./modal'); +const noStreams = require('./noStreams'); const notFound = require('./notFound'); - -function password(state, emit) { - const fileInfo = state.fileInfo; - const invalid = fileInfo.password === null; - - const div = html` -
-

${state.translate('downloadFilesTitle')}

-

- ${state.translate('downloadMessage')} -

-
- - -
- -
- `; - - if (!(div instanceof String)) { - setTimeout(() => document.getElementById('password-input').focus()); - } - - function inputChanged(event) { - event.stopPropagation(); - event.preventDefault(); - const label = document.getElementById('password-error'); - const input = document.getElementById('password-input'); - const btn = document.getElementById('password-btn'); - label.classList.add('invisible'); - input.classList.remove('border-red'); - btn.classList.remove('bg-red', 'hover:bg-red', 'focus:bg-red'); - } - - function checkPassword(event) { - event.stopPropagation(); - event.preventDefault(); - const el = document.getElementById('password-input'); - const password = el.value; - if (password.length > 0) { - document.getElementById('password-btn').disabled = true; - state.fileInfo.url = window.location.href; - state.fileInfo.password = password; - emit('getMetadata'); - } - return false; - } - - return div; -} +const downloadPassword = require('./downloadPassword'); +const downloadCompleted = require('./downloadCompleted'); +const BIG_SIZE = 1024 * 1024 * 256; function createFileInfo(state) { return { @@ -96,6 +17,36 @@ function createFileInfo(state) { }; } +function downloading(state, emit) { + return html` +
+

${state.translate('downloadingTitle')}

+ ${archiveTile.downloading(state, emit)} +
+ `; +} + +function preview(state, emit) { + if (!state.capabilities.streamDownload && state.fileInfo.size > BIG_SIZE) { + return noStreams(state, emit); + } + return html` +
+

${state.translate('downloadFilesTitle')}

+

+ ${state.translate('downloadMessage')} +

+ ${archiveTile.preview(state, emit)} +
+ `; +} + module.exports = function(state, emit) { let content = ''; if (!state.fileInfo) { @@ -113,56 +64,16 @@ module.exports = function(state, emit) { switch (state.transfer.state) { case 'downloading': case 'decrypting': - content = html` -
-

${state.translate('downloadingTitle')}

- ${archiveTile.downloading(state, emit)} -
- `; + content = downloading(state, emit); break; case 'complete': - content = html` -
-

- ${state.translate('downloadFinish')} -

-

- ${state.translate('downloadFinishText')} -

- -

- ${state.translate('sendYourFilesLink')} -

-
- `; + content = downloadCompleted(state); break; default: - content = html` -
-

${state.translate('downloadFilesTitle')}

-

- ${state.translate('downloadMessage')} -

- ${archiveTile.preview(state, emit)} -
- `; + content = preview(state, emit); } } else if (state.fileInfo.requiresPassword && !state.fileInfo.password) { - content = password(state, emit); + content = downloadPassword(state, emit); } return html`
diff --git a/app/ui/downloadCompleted.js b/app/ui/downloadCompleted.js new file mode 100644 index 00000000..41c46949 --- /dev/null +++ b/app/ui/downloadCompleted.js @@ -0,0 +1,24 @@ +const html = require('choo/html'); +const assets = require('../../common/assets'); + +module.exports = function(state) { + return html` +
+

+ ${state.translate('downloadFinish')} +

+

+ ${state.translate('downloadFinishText')} +

+ +

+ ${state.translate('sendYourFilesLink')} +

+
+ `; +}; diff --git a/app/ui/downloadPassword.js b/app/ui/downloadPassword.js new file mode 100644 index 00000000..795d2662 --- /dev/null +++ b/app/ui/downloadPassword.js @@ -0,0 +1,83 @@ +const html = require('choo/html'); + +module.exports = function(state, emit) { + const fileInfo = state.fileInfo; + const invalid = fileInfo.password === null; + + const div = html` +
+

${state.translate('downloadFilesTitle')}

+

+ ${state.translate('downloadMessage')} +

+
+ + +
+ +
+ `; + + if (!(div instanceof String)) { + setTimeout(() => document.getElementById('password-input').focus()); + } + + function inputChanged(event) { + event.stopPropagation(); + event.preventDefault(); + const label = document.getElementById('password-error'); + const input = document.getElementById('password-input'); + const btn = document.getElementById('password-btn'); + label.classList.add('invisible'); + input.classList.remove('border-red'); + btn.classList.remove('bg-red', 'hover:bg-red', 'focus:bg-red'); + } + + function checkPassword(event) { + event.stopPropagation(); + event.preventDefault(); + const el = document.getElementById('password-input'); + const password = el.value; + if (password.length > 0) { + document.getElementById('password-btn').disabled = true; + state.fileInfo.url = window.location.href; + state.fileInfo.password = password; + emit('getMetadata'); + } + return false; + } + + return div; +}; diff --git a/app/ui/error.js b/app/ui/error.js index 0c3e96b8..048ba405 100644 --- a/app/ui/error.js +++ b/app/ui/error.js @@ -15,7 +15,7 @@ module.exports = function(state, emit) {

${state.translate('uploadPageExplainer')}

- +

+

${state.translate('downloadFilesTitle')}

+

+ ⚠️ ${state.translate('noStreamsWarning')} ⚠️ +

+
+
+
+ +

+

${ + archive.name + }

+
${bytes( + archive.size + )}
+

+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + `; + + function optionChanged(event) { + event.stopPropagation(); + const choice = event.target.value; + const button = event.currentTarget.nextElementSibling; + let title = button.title; + switch (choice) { + case 'copy': + title = state.translate('copyUrlFormButtonText'); + break; + case 'firefox': + title = state.translate('downloadFirefox'); + break; + case 'download': + title = state.translate('downloadButtonLabel'); + break; + } + button.title = title; + button.value = title; + } + + function submit(event) { + const action = document.querySelector('input[type="radio"]:checked').value; + switch (action) { + case 'copy': + emit('copy', { url: window.location.href }); + document.querySelector('input[type="submit"]').value = state.translate( + 'copiedUrl' + ); + break; + case 'firefox': + window.open( + 'https://www.mozilla.org/firefox/new/?utm_campaign=send-acquisition&utm_medium=referral&utm_source=send.firefox.com' + ); + break; + case 'download': + emit('download', archive); + break; + } + return false; + } +}; diff --git a/app/ui/notFound.js b/app/ui/notFound.js index 0cd797e4..75595526 100644 --- a/app/ui/notFound.js +++ b/app/ui/notFound.js @@ -15,7 +15,7 @@ module.exports = function(state, emit) {

${state.translate('downloadFinishText')}

- +