Skip to content

Commit

Permalink
fixed all lint errors, adjusted rules
Browse files Browse the repository at this point in the history
  • Loading branch information
PiggySpeed committed May 13, 2018
1 parent 635f508 commit df9679b
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 345 deletions.
19 changes: 17 additions & 2 deletions daemon/web/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
{
"extends": "airbnb"
}
"extends": "airbnb",
"rules": {
"prefer-template": 0,
"react/jsx-filename-extension": 0,
"react/require-default-props": 0,
"react/jsx-closing-bracket-location": 0,
"object-curly-newline": 0,
"arrow-body-style": [2, "as-needed"],
"comma-dangle": ["error", "always-multiline", {
"arrays": "always",
"objects": "always",
"imports": "always",
"exports": "always",
"functions": "never"
}]
}
}
55 changes: 32 additions & 23 deletions daemon/web/client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
/* global Request:true, fetch:true */

export default class InertiaClient {
constructor(url) {
Expand All @@ -9,29 +9,29 @@ export default class InertiaClient {
const endpoint = '/user/logout';
const params = {
headers: {
'Accept': 'application/json'
}
Accept: 'application/json',
},
};
return this._post(endpoint, params);
return this.post(endpoint, params);
}

async login(username, password) {
const endpoint = '/user/login';
const params = {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: JSON.stringify({
username: username,
password: password,
})
username,
password,
}),
};
return this._post(endpoint, params);
return this.post(endpoint, params);
}

async validate() {
return this._get('/user/validate', {});
return this.get('/user/validate', {});
}

async getContainerLogs(container = '/inertia-daemon') {
Expand All @@ -42,21 +42,21 @@ export default class InertiaClient {
},
body: JSON.stringify({
stream: true,
container: container,
})
container,
}),
};
return this._post(endpoint, params);
return this.post(endpoint, params);
}

async getRemoteStatus() {
const endpoint = '/status';
const params = {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
Accept: 'application/json',
},
};
return this._get(endpoint, params);
return this.get(endpoint, params);
}

/**
Expand All @@ -65,9 +65,13 @@ export default class InertiaClient {
* @param {Object} params
*/
async _get(endpoint, params) {
params.method = 'GET';
params.credentials = 'include';
const request = new Request(this.url + endpoint, params);
const newParams = {
...params,
method: 'GET',
credentials: 'include',
};

const request = new Request(this.url + endpoint, newParams);

try {
return await fetch(request);
Expand All @@ -82,9 +86,14 @@ export default class InertiaClient {
* @param {Object} params
*/
async _post(endpoint, params) {
params.method = 'POST';
params.credentials = 'include';
const request = new Request(this.url + endpoint, params);
const newParams = {
...params,
method: 'POST',
credentials: 'include',
};

const request = new Request(this.url + endpoint, newParams);

try {
return await fetch(request);
} catch (e) {
Expand Down
110 changes: 62 additions & 48 deletions daemon/web/components/App.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
import React from 'react';
import { Redirect, HashRouter, Route } from 'react-router-dom';
import { HashRouter, Redirect, Route } from 'react-router-dom';
import PropTypes from 'prop-types';
import createHistory from 'history/createBrowserHistory';

import InertiaClient from '../client';
import Login from './Login';
import Home from './Home';

const styles = {
container: {
display: 'flex',
height: '100%',
width: '100%',
},
};

// render a route component that requires authentication
const AuthRoute = ({ authenticated, component: Component, props, ...rest }) => (
<Route {...rest} render={(routeProps) => (
authenticated
? <Component {...Object.assign({}, routeProps, props)} />
: <Redirect to="/login" />
<Route
{...rest}
render={routeProps => (
authenticated
? <Component {...Object.assign({}, routeProps, props)} />
: <Redirect to="/login" />
)} />
);
AuthRoute.propTypes = {
authenticated: PropTypes.bool,
component: PropTypes.node,
props: PropTypes.shape(),
};


// render a route component with props
const PropsRoute = ({ component: Component, props, ...rest }) => (
<Route {...rest} render={(routeProps) => (
<Component {...Object.assign({}, routeProps, props)} />
<Route
{...rest}
render={routeProps => (<Component {...Object.assign({}, routeProps, props)} />
)} />
);
PropsRoute.propTypes = {
component: PropTypes.node,
props: PropTypes.shape(),
};

export default class App extends React.Component {
constructor(props) {
Expand All @@ -34,24 +55,24 @@ export default class App extends React.Component {

this.isAuthenticated = this.isAuthenticated.bind(this);

this.isAuthenticated().then((authenticated) => {
this.setState({
loading: false,
authenticated: authenticated,
this.isAuthenticated()
.then((authenticated) => {
this.setState({
loading: false,
authenticated,
});
});
});

const history = createHistory();
history.listen(() => {
this.setState({
loading: true,
});
this.isAuthenticated().then((authenticated) => {
this.setState({
loading: false,
authenticated: authenticated,
this.setState({ loading: true });
this.isAuthenticated()
.then((authenticated) => {
this.setState({
loading: false,
authenticated,
});
});
});
});
}

Expand All @@ -61,42 +82,35 @@ export default class App extends React.Component {
}

render() {
const { component: Component, ...rest } = this.props;
if (this.state.loading) {
return (
<p align="center" >
<p align="center">
Loading...
</p>
);
} else {
return (
<HashRouter>
<div style={styles.container}>
<Route exact path="/"
component={() => <Redirect to="/login" />} />
<PropsRoute path="/login"
component={Login}
props={this.props} />
<AuthRoute path="/home"
authenticated={this.state.authenticated}
component={Home} props={this.props} />
</div>
</HashRouter>
);
}

return (
<HashRouter>
<div style={styles.container}>
<Route
exact
path="/"
component={() => <Redirect to="/login" />} />
<PropsRoute
path="/login"
component={Login}
props={this.props} />
<AuthRoute
path="/home"
authenticated={this.state.authenticated}
component={Home}
props={this.props} />
</div>
</HashRouter>
);
}
}

App.propTypes = {
client: PropTypes.instanceOf(InertiaClient),
authenticated: PropTypes.instanceOf(Boolean),
loading: PropTypes.instanceOf(Boolean),
};

const styles = {
container: {
display: 'flex',
height: '100%',
width: '100%'
}
};
Loading

0 comments on commit df9679b

Please sign in to comment.