Skip to content

Commit

Permalink
resolving merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
PiggySpeed committed May 19, 2018
2 parents e2b5508 + 33d9601 commit b957a90
Show file tree
Hide file tree
Showing 16 changed files with 1,244 additions and 1,031 deletions.
38 changes: 0 additions & 38 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @bobheadxi
* @bobheadxi @PiggySpeed
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ inertia-tagged:
# Remove Inertia binaries
.PHONY: clean
clean:
rm -f ./inertia
rm -f ./inertia
find . -type f -name inertia.\* -exec rm {} \;

.PHONY: lint
lint:
PATH=$(PATH):./bin bash -c './bin/gometalinter --vendor --deadline=60s ./...'
(cd ./daemon/web; npm run lint)

# Run unit test suite
.PHONY: test
Expand Down
22 changes: 22 additions & 0 deletions daemon/web/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"env": {
"browser": true,
"node": true
},
"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"
}]
}
}
58 changes: 32 additions & 26 deletions daemon/web/client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import encodeURL from './common/encodeURL';

export default class InertiaClient {
Expand All @@ -10,55 +9,55 @@ 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') {
const endpoint = '/logs';
const queryParams = {
stream: 'true',
container: container,
container,
};
const params = {
headers: {
'Content-Type': 'application/json',
}
},
};

return this._post(endpoint, params, queryParams);
return this.post(endpoint, params, queryParams);
}

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 @@ -67,14 +66,16 @@ export default class InertiaClient {
* @param {Object} params
* @param {{[key]: string}} queryParams
*/
async _get(endpoint, params, queryParams) {
async get(endpoint, params, queryParams) {
const newParams = {
...params,
method: 'GET',
credentials: 'include',
};
const queryString = queryParams ? encodeURL(queryParams) : '';
const url = this.url + endpoint + queryString;

params.method = 'GET';
params.credentials = 'include';

const request = new Request(url, params);
const request = new Request(url, newParams);

try {
return await fetch(request);
Expand All @@ -88,10 +89,15 @@ export default class InertiaClient {
* @param {String} endpoint
* @param {Object} params
*/
async _post(endpoint, params) {
params.method = 'POST';
params.credentials = 'include';
const request = new Request(this.url + endpoint, params);
async post(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
6 changes: 3 additions & 3 deletions daemon/web/common/encodeURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
*/
function encodeURL(params) {
const result = [];

const keys = Object.keys(params);
for (const k of keys) {

keys.forEach((k) => {
const v = params[k];

if (typeof v !== 'string') {
throw new Error(`Arguments must be of type string, received [${k}, ${typeof v}]`);
}

result.push(encodeURIComponent(k) + '=' + encodeURIComponent(v));
}
});

return result.join('&');
}
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 b957a90

Please sign in to comment.