Browse Source

added password setting error UI

Danny Coates 7 years ago
parent
commit
14b40d820b

+ 8 - 0
app/base.css

@@ -106,6 +106,10 @@ a {
   padding-right: 10px;
 }
 
+.input--error {
+  border-color: var(--errorColor);
+}
+
 .input--noBtn {
   border-radius: 6px;
 }
@@ -215,6 +219,10 @@ a {
   }
 }
 
+.error {
+  color: var(--errorColor);
+}
+
 .title {
   font-size: 33px;
   line-height: 40px;

+ 3 - 1
app/fileManager.js

@@ -136,9 +136,11 @@ export default function(state, emitter) {
       state.storage.writeFile(file);
       metrics.addedPassword({ size: file.size });
       await delay(1000);
-      state.settingPassword = false;
     } catch (err) {
       console.error(err);
+      state.passwordSetError = err;
+    } finally {
+      state.settingPassword = false;
     }
     render();
   });

+ 11 - 5
app/ownedFile.js

@@ -21,11 +21,17 @@ export default class OwnedFile {
   }
 
   async setPassword(password) {
-    this.password = password;
-    this._hasPassword = true;
-    this.keychain.setPassword(password, this.url);
-    const result = await setPassword(this.id, this.ownerToken, this.keychain);
-    return result;
+    try {
+      this.password = password;
+      this._hasPassword = true;
+      this.keychain.setPassword(password, this.url);
+      const result = await setPassword(this.id, this.ownerToken, this.keychain);
+      return result;
+    } catch (e) {
+      this.password = null;
+      this._hasPassword = false;
+      throw e;
+    }
   }
 
   del() {

+ 3 - 5
app/pages/welcome/index.js

@@ -21,11 +21,9 @@ module.exports = function(state, emit) {
     <div class="uploadArea"
       ondragover=${dragover}
       ondragleave=${dragleave}>
-      <div id="upload-img">
-        <img
-          src="${assets.get('upload.svg')}"
-          title="${state.translate('uploadSvgAlt')}"/>
-      </div>
+      <img
+        src="${assets.get('upload.svg')}"
+        title="${state.translate('uploadSvgAlt')}"/>
       <div class="uploadArea__msg">
         ${state.translate('uploadPageDropMessage')}
       </div>

+ 0 - 8
app/templates/downloadPassword/downloadPassword.css

@@ -11,14 +11,6 @@
   padding: 10px 0;
 }
 
-.error {
-  color: var(--errorColor);
-}
-
-.input--error {
-  border-color: var(--errorColor);
-}
-
 @media (max-device-width: 520px), (max-width: 520px) {
   .passwordSection {
     width: 100%;

+ 18 - 16
app/templates/passwordInput/index.js

@@ -4,9 +4,10 @@ const MAX_LENGTH = 32;
 module.exports = function(file, state, emit) {
   const loading = state.settingPassword;
   const pwd = file.hasPassword;
-  const formClass = pwd
-    ? 'passwordInput'
-    : 'passwordInput passwordInput--hidden';
+  const sectionClass =
+    pwd || state.passwordSetError
+      ? 'passwordInput'
+      : 'passwordInput passwordInput--hidden';
   const inputClass = loading || pwd ? 'input' : 'input input--noBtn';
   let btnClass = 'inputBtn inputBtn--password inputBtn--hidden';
   if (loading) {
@@ -14,14 +15,13 @@ module.exports = function(file, state, emit) {
   } else if (pwd) {
     btnClass = 'inputBtn inputBtn--password';
   }
-
   const action = pwd
     ? state.translate('changePasswordButton')
     : state.translate('addPasswordButton');
   return html`
-  <div>
+  <div class="${sectionClass}">
     <form
-      class="${formClass}"
+      class="passwordInput__form"
       onsubmit=${setPassword}
       data-no-csrf>
       <input id="password-input"
@@ -33,7 +33,7 @@ module.exports = function(file, state, emit) {
         oninput=${inputChanged}
         onfocus=${focused}
         placeholder="${
-          pwd
+          pwd && !state.passwordSetError
             ? passwordPlaceholder(file.password)
             : state.translate('unlockInputPlaceholder')
         }">
@@ -44,15 +44,14 @@ module.exports = function(file, state, emit) {
         value="${loading ? '' : action}">
     </form>
     <label
-      class="passwordInput__msg"
-      for="password-input">${message(
-        loading,
-        pwd,
-        state.translate('passwordIsSet')
-      )}</label>
+      class="passwordInput__msg ${
+        state.passwordSetError ? 'passwordInput__msg--error' : ''
+      }"
+      for="password-input">${message(state, pwd)}</label>
   </div>`;
 
   function inputChanged() {
+    state.passwordSetError = null;
     const resetInput = document.getElementById('password-input');
     const resetBtn = document.getElementById('password-btn');
     const pwdmsg = document.querySelector('.passwordInput__msg');
@@ -99,9 +98,12 @@ function passwordPlaceholder(password) {
   return password ? password.replace(/./g, '●') : '●●●●●●●●●●●●';
 }
 
-function message(loading, pwd, deflt) {
-  if (loading || !pwd) {
+function message(state, pwd) {
+  if (state.passwordSetError) {
+    return state.translate('passwordSetError');
+  }
+  if (state.settingPassword || !pwd) {
     return '';
   }
-  return deflt;
+  return state.translate('passwordIsSet');
 }

+ 13 - 6
app/templates/passwordInput/passwordInput.css

@@ -1,19 +1,26 @@
 .passwordInput {
+  width: 90%;
+  height: 100px;
+  padding: 10px 5px 5px;
+}
+
+.passwordInput--hidden {
+  visibility: hidden;
+}
+
+.passwordInput__form {
   display: flex;
   flex-wrap: nowrap;
-  width: 80%;
-  padding: 10px 5px 5px;
+  padding-bottom: 5px;
 }
 
 .passwordInput__msg {
-  height: 100px;
-  margin: 0 5px;
   font-size: 15px;
   color: var(--lightTextColor);
 }
 
-.passwordInput--hidden {
-  visibility: hidden;
+.passwordInput__msg--error {
+  color: var(--errorColor);
 }
 
 .inputBtn--loading {

+ 2 - 2
app/templates/setPasswordSection/index.js

@@ -9,7 +9,7 @@ module.exports = function(state, emit) {
     <div class="checkbox">
       <input
         ${file.hasPassword ? 'disabled' : ''}
-        ${file.hasPassword ? 'checked' : ''}
+        ${file.hasPassword || state.passwordSetError ? 'checked' : ''}
         class="checkbox__input"
         id="add-password"
         type="checkbox"
@@ -26,7 +26,7 @@ module.exports = function(state, emit) {
     const unlockInput = document.getElementById('password-input');
     const boxChecked = e.target.checked;
     document
-      .querySelector('form.passwordInput')
+      .querySelector('.passwordInput')
       .classList.toggle('passwordInput--hidden', !boxChecked);
     if (boxChecked) {
       unlockInput.focus();

+ 1 - 1
public/locales/en-US/send.ftl

@@ -116,4 +116,4 @@ passwordIsSet = Password set
 # A short status message shown when the user enters a long password
 maxPasswordLength = Maximum password length: { $length }
 # A short status message shown when there was an error setting the password
-passwordError = The password could not be set
+passwordSetError = This password could not be set