updated format and lint scripts and applied them

This commit is contained in:
JJ Kasper
2018-06-01 16:52:12 -05:00
parent 53ac8a6793
commit 017a9993ee
58 changed files with 1711 additions and 1568 deletions

View File

@@ -1,49 +1,49 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import fetch from 'isomorphic-unfetch';
import mapUser from '../util/mapUser';
import getUrl from '../util/getUrl';
import getJwt from '../util/getJwt';
import React, { Component } from 'react'
import { connect } from 'react-redux'
import fetch from 'isomorphic-unfetch'
import mapUser from '../util/mapUser'
import getUrl from '../util/getUrl'
import getJwt from '../util/getJwt'
const getDoc = async (id, req) => {
let found, doc;
const jwt = getJwt(req);
if(!jwt) return { found, doc, id };
let found, doc
const jwt = getJwt(req)
if (!jwt) return { found, doc, id }
const docRes = await fetch(getUrl('docs/' + id, Boolean(req)), {
method: 'GET',
headers: { Authorization: jwt }
});
if(docRes.ok) {
doc = await docRes.json();
found = true;
headers: { Authorization: jwt },
})
if (docRes.ok) {
doc = await docRes.json()
found = true
}
return { found, doc, id };
};
return { found, doc, id }
}
export default ComposedComponent => {
class DocComp extends Component {
state = {
found: false,
id: null,
doc: {}
doc: {},
}
static async getInitialProps({ query, req }) {
return await getDoc(query.id, req);
return await getDoc(query.id, req)
}
static getDerivedStateFromProps(nextProps, state) {
const { found, id, doc } = nextProps;
if(state.found !== found) return { found, id, doc };
return null;
const { found, id, doc } = nextProps
if (state.found !== found) return { found, id, doc }
return null
}
async componentDidUpdate(prevProps) {
const { user, found, id } = this.props;
if(prevProps.user.email === user.email || found) return;
if(!user.email) return;
this.setState(await getDoc(id));
const { user, found, id } = this.props
if (prevProps.user.email === user.email || found) return
if (!user.email) return
this.setState(await getDoc(id))
}
render() {
return <ComposedComponent {...this.state} />;
return <ComposedComponent {...this.state} />
}
}
return connect(mapUser)(DocComp);
};
return connect(mapUser)(DocComp)
}