From a67468fc02731210dfcb3c475bf984ffcf3fd007 Mon Sep 17 00:00:00 2001 From: Gabriel Andretta Date: Wed, 19 Aug 2015 13:50:38 -0300 Subject: [PATCH] Let each mode render the Lock --- src/lock/lock.jsx | 4 ++-- src/lock/renderer.js | 3 +-- src/passwordless-email/render.js | 35 ++++++++++++++++---------------- src/passwordless-sms/render.js | 20 ++++++++++++------ 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/lock/lock.jsx b/src/lock/lock.jsx index 84598b9f0..df6bcda31 100644 --- a/src/lock/lock.jsx +++ b/src/lock/lock.jsx @@ -17,7 +17,7 @@ export default class Lock extends React.Component { } render() { - const { backHandler, closeHandler, mainPane, mainPaneKey, lock, submitHandler, disallowClose } = this.props; + const { backHandler, children, closeHandler, lock, submitHandler, disallowClose } = this.props; const overlay = l.ui.appendContainer(lock) ?
: null; @@ -46,7 +46,7 @@ export default class Lock extends React.Component { {backHandler && }
- + {children}
diff --git a/src/lock/renderer.js b/src/lock/renderer.js index 41e95c80b..16d16b40c 100644 --- a/src/lock/renderer.js +++ b/src/lock/renderer.js @@ -19,8 +19,7 @@ export default class Renderer { lock = lock.set("gravatar", gravatar && g.loaded(gravatar) ? gravatar : null); const container = this.containerManager.ensure(l.ui.containerID(lock), l.ui.appendContainer(lock)); const renderFn = fns.get(l.mode(lock)); - const spec = renderFn(lock) - React.render(, container); + React.render(renderFn(lock), container); }); } } diff --git a/src/passwordless-email/render.js b/src/passwordless-email/render.js index fb8c101c2..503934e31 100644 --- a/src/passwordless-email/render.js +++ b/src/passwordless-email/render.js @@ -3,7 +3,8 @@ import AskVcode from './ask_vcode'; import { close, reset, requestPasswordlessEmail, signIn } from './actions'; import * as l from '../lock/index'; import * as m from './index'; - +import Lock from '../lock/lock'; +import React from 'react'; function askEmailSubmitHandler(lock) { requestPasswordlessEmail(l.id(lock)); @@ -18,20 +19,20 @@ function backHandler(lock) { } export default function render(lock) { - if (m.isSendLink(lock)) { - return { - closeHandler: close, - mainPane: AskEmail, - mainPaneKey: "ask-email", - submitHandler: !m.emailSent(lock) && askEmailSubmitHandler - }; - } else { - return { - backHandler: m.emailSent(lock) ? backHandler : null, - closeHandler: close, - mainPane: m.emailSent(lock) ? AskVcode : AskEmail, - mainPaneKey: m.emailSent(lock) ? "ask-vcode" : "ask-email", - submitHandler: m.emailSent(lock) ? askVcodeSubmitHandler : askEmailSubmitHandler - }; - } + const children = m.isSendLink(lock) || !m.emailSent(lock) ? + : + ; + + const submitHandler = !m.emailSent(lock) ? + askEmailSubmitHandler : !m.isSendLink(lock) && askVcodeSubmitHandler; + + const props = { + backHandler: !m.isSendLink(lock) && m.emailSent(lock) ? backHandler : null, + children: children, + closeHandler: close, + lock: lock, + submitHandler: submitHandler + }; + + return ; } diff --git a/src/passwordless-sms/render.js b/src/passwordless-sms/render.js index 2938ccf6b..016376c31 100644 --- a/src/passwordless-sms/render.js +++ b/src/passwordless-sms/render.js @@ -1,8 +1,10 @@ -import askPhoneNumber from './ask_phone_number'; -import askVcode from './ask_vcode'; +import AskPhoneNumber from './ask_phone_number'; +import AskVcode from './ask_vcode'; import { close, reset, sendSMS, signIn } from './actions'; import * as l from '../lock/index'; import * as m from './index'; +import Lock from '../lock/lock'; +import React from 'react'; function askPhoneNumberSubmitHandler(lock) { sendSMS(l.id(lock)); @@ -17,12 +19,18 @@ function backHandler(lock) { } export default function render(lock) { - return { + const children = m.smsSent(lock) ? + : + ; + + const props = { backHandler: m.smsSent(lock) ? backHandler : undefined, closeHandler: close, - mainPane: m.smsSent(lock) ? askVcode : askPhoneNumber, - mainPaneKey: m.smsSent(lock) ? "ask-vcode" : "ask-phone-number", + children: children, disallowClose: m.selectingLocation(lock), + lock: lock, submitHandler: m.smsSent(lock) ? askVcodeSubmitHandler : askPhoneNumberSubmitHandler - } + }; + + return ; }