From 5db0d9b6836987213badea9e1199f6ca37e2a609 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 23 Apr 2016 02:17:40 +0200 Subject: [PATCH] Extract Authenticate --- public/components/authenticate.js | 68 +++++++++++++++++++++++ public/components/duplicate-finder-box.js | 1 + public/script.jsx | 62 +-------------------- 3 files changed, 70 insertions(+), 61 deletions(-) create mode 100644 public/components/authenticate.js diff --git a/public/components/authenticate.js b/public/components/authenticate.js new file mode 100644 index 0000000..623e494 --- /dev/null +++ b/public/components/authenticate.js @@ -0,0 +1,68 @@ +'use strict'; +var React = require('react'); +var ReactBootstrap = require('react-bootstrap'); +var $ = require('jquery'); + +var Authenticate = React.createClass({ + logout: function () { + this.props.refreshAuth(null, null); + window.location.href = "/"; + }, + refreshToken: function (event) { + event.preventDefault(); + var self = this; + $.ajax({ + url: '/refresh_token', + data: { + 'refresh_token': self.props.auth.refresh_token + }, + success: function (data) { + self.props.refreshAuth(data.access_token, self.props.auth.refresh_token); + }, + error: function (xhr, status, err) { + console.error(status, err); + } + }); + }, + render: function () { + var auth; + var Nav = ReactBootstrap.Nav, + NavItem = ReactBootstrap.NavItem, + Navbar = ReactBootstrap.Navbar; + + if (this.props.auth.access_token == null) { + auth = ( + + ); + } + else { + auth = ( + + ); + } + + return ( + + + + Duplicate Finder + + + + + + {auth} + + + ); + } +}); + +module.exports = Authenticate; diff --git a/public/components/duplicate-finder-box.js b/public/components/duplicate-finder-box.js index c7d8677..7daa80d 100644 --- a/public/components/duplicate-finder-box.js +++ b/public/components/duplicate-finder-box.js @@ -1,6 +1,7 @@ 'use strict'; var React = require('react'); var ReactBootstrap = require('react-bootstrap'); +var $ = require('jquery'); var DuplicatesBox = require('./duplicates-box'); var PlaylistBox = require('./playlist-box'); diff --git a/public/script.jsx b/public/script.jsx index 2ca4c32..e8282c4 100644 --- a/public/script.jsx +++ b/public/script.jsx @@ -22,67 +22,7 @@ function getHashParams() { var DuplicateFinderBox = require('./components/duplicate-finder-box'); -var Authenticate = React.createClass({ - logout: function () { - this.props.refreshAuth(null, null); - window.location.href = "/"; - }, - refreshToken: function (event) { - event.preventDefault(); - var self = this; - $.ajax({ - url: '/refresh_token', - data: { - 'refresh_token': self.props.auth.refresh_token - }, - success: function (data) { - self.props.refreshAuth(data.access_token, self.props.auth.refresh_token); - }, - error: function (xhr, status, err) { - console.error(status, err); - } - }); - }, - render: function () { - var auth; - var Nav = ReactBootstrap.Nav, - NavItem = ReactBootstrap.NavItem, - Navbar = ReactBootstrap.Navbar; - - if (this.props.auth.access_token == null) { - auth = ( - - ); - } - else { - auth = ( - - ); - } - - return ( - - - - Duplicate Finder - - - - - - {auth} - - - ); - } -}); +var Authenticate = require('./components/authenticate'); var App = React.createClass({ getInitialState: function () {