From 87b6d05e5b289f3e9d1554fe455296ba09655c3a Mon Sep 17 00:00:00 2001 From: jloup Date: Sat, 5 May 2018 12:36:58 +0200 Subject: Factorize Header/Footer code. --- cmd/web/Makefile | 2 +- cmd/web/js/app.js | 7 +++- cmd/web/js/change_password.jsx | 2 +- cmd/web/js/header_footer.jsx | 78 ++++++++++++++++++++++++++++++++++++++++++ cmd/web/js/main.jsx | 37 -------------------- cmd/web/js/password_reset.jsx | 4 +-- cmd/web/js/signin.jsx | 2 +- cmd/web/js/signup.jsx | 2 +- 8 files changed, 90 insertions(+), 44 deletions(-) create mode 100644 cmd/web/js/header_footer.jsx (limited to 'cmd/web') diff --git a/cmd/web/Makefile b/cmd/web/Makefile index c5d5d62..85bba5b 100644 --- a/cmd/web/Makefile +++ b/cmd/web/Makefile @@ -4,7 +4,7 @@ export PATH := $(PATH):./node_modules/.bin SRC_DIR=js BUILD_DIR=build/js -JSX_SRC= main.jsx signup.jsx signin.jsx otp.jsx poloniex.jsx password_reset.jsx change_password.jsx +JSX_SRC= header_footer.jsx main.jsx signup.jsx signin.jsx otp.jsx poloniex.jsx password_reset.jsx change_password.jsx JS_SRC= cookies.js app.js api.js STATIC_FILES= index.html style.css JSX_OBJS=$(addprefix $(BUILD_DIR)/,$(JSX_SRC:.jsx=.js)) diff --git a/cmd/web/js/app.js b/cmd/web/js/app.js index c24a761..878878d 100644 --- a/cmd/web/js/app.js +++ b/cmd/web/js/app.js @@ -4,6 +4,7 @@ import cookies from './cookies.js'; import page from 'page'; import React from 'react'; import ReactDOM from 'react-dom'; +import {Header, Footer} from './header_footer.js'; var App = {}; var cookieExpire = 60 * 60 * 24 * 7; @@ -117,7 +118,11 @@ App.mount = function(app) { var root = React.createElement( 'div', {className: 'container'}, - app + [ + React.createElement(Header, {key: 'header', isLoggedIn: App.isUserSignedIn()}), + React.createElement(React.Fragment, {key: 'app'}, app), + React.createElement(Footer, {key: 'footer', isLoggedIn: App.isUserSignedIn()}) + ], ); ReactDOM.unmountComponentAtNode(document.getElementById('app')); diff --git a/cmd/web/js/change_password.jsx b/cmd/web/js/change_password.jsx index aedf4af..74cde0f 100644 --- a/cmd/web/js/change_password.jsx +++ b/cmd/web/js/change_password.jsx @@ -47,7 +47,7 @@ class ChangePasswordForm extends React.Component { var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk}); return (
-
+
diff --git a/cmd/web/js/header_footer.jsx b/cmd/web/js/header_footer.jsx new file mode 100644 index 0000000..3cb9937 --- /dev/null +++ b/cmd/web/js/header_footer.jsx @@ -0,0 +1,78 @@ +import React from 'react'; + +class Signout extends React.Component { + render = () => { + return Logout; + } +} + +class Logo extends React.Component { + render() { + return ; + } +} + +class Footer extends React.Component { + render = () => { + var elements = this.props.elements; + if (elements === undefined) { + elements = []; + } + + if (this.props.isLoggedIn === true) { + elements = elements.concat(); + } + + if (elements.length > 0) { + elements = [
].concat(elements); + } + + var rows = elements.map(function(element, i) { + return
+
+ {element} +
+
; + }); + return ; + } +} + +class Header extends React.Component { + render = () => { + var elements = this.props.elements; + if (elements === undefined) { + elements = []; + } + + if (this.props.isLoggedIn === true) { + elements = elements.concat(); + } + + elements = elements.map(function(element, i) { + return
+ {element} +
; + }); + + return ; + } +} + +export { + Header, + Footer, +}; diff --git a/cmd/web/js/main.jsx b/cmd/web/js/main.jsx index 909f1bd..8a4fce8 100644 --- a/cmd/web/js/main.jsx +++ b/cmd/web/js/main.jsx @@ -10,35 +10,6 @@ import cookies from './cookies.js'; import React from 'react'; import qs from 'qs'; -class Header extends React.Component { - render = () => { - if (this.props.displayLogout === true) { - return ; - } - return ; - - } -} - -class Logo extends React.Component { - render() { - return ; - } -} - App.page('/signup', false, function(context) { if (App.isUserSignedIn()) { App.go('/me'); @@ -46,7 +17,6 @@ App.page('/signup', false, function(context) { } App.mount(
-
); }); @@ -58,7 +28,6 @@ App.page('/signin', false, function(context) { } App.mount(
-
); }); @@ -70,7 +39,6 @@ App.page('/reset-password', false, function(context) { } App.mount(
-
); }); @@ -89,7 +57,6 @@ App.page('/change-password', false, function(context) { } App.mount(
-
); }); @@ -102,14 +69,12 @@ App.page('/signout', true, function(context) { App.page('/me', true, function(context) { App.mount(
-
); }); App.page('/not_confirmed', true, function(context) { App.mount(
-

Please be patient, you account is being confirmed...

@@ -127,7 +92,6 @@ App.page('/otp/setup', true, function(context) { } App.mount(
-
); @@ -136,7 +100,6 @@ App.page('/otp/setup', true, function(context) { App.page('/otp/validate', true, function(context) { App.mount(
-
); }); diff --git a/cmd/web/js/password_reset.jsx b/cmd/web/js/password_reset.jsx index 8cbdc60..b6a10ec 100644 --- a/cmd/web/js/password_reset.jsx +++ b/cmd/web/js/password_reset.jsx @@ -42,7 +42,7 @@ class PasswordResetForm extends React.Component { var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk}); return (
-
+
@@ -54,4 +54,4 @@ class PasswordResetForm extends React.Component { } } -export default PasswordResetForm; \ No newline at end of file +export default PasswordResetForm; diff --git a/cmd/web/js/signin.jsx b/cmd/web/js/signin.jsx index bff497e..e0e0f1d 100644 --- a/cmd/web/js/signin.jsx +++ b/cmd/web/js/signin.jsx @@ -44,7 +44,7 @@ class SigninForm extends React.Component { var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk}); return (
-
+
diff --git a/cmd/web/js/signup.jsx b/cmd/web/js/signup.jsx index affa18e..b7d9287 100644 --- a/cmd/web/js/signup.jsx +++ b/cmd/web/js/signup.jsx @@ -51,7 +51,7 @@ class SignupForm extends React.Component { var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk}); return (
-
+
-- cgit v1.2.3