From 017a9993eeef6e8450ad2a616aed11408026d273 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 1 Jun 2018 16:52:12 -0500 Subject: [PATCH] updated format and lint scripts and applied them --- .eslintignore | 3 + comps/AddDoc.js | 56 ++--- comps/CodeMirror.js | 78 +++---- comps/DocItem.js | 40 ++-- comps/Footer.js | 16 +- comps/Header.js | 114 ++++----- comps/KeyShortcuts.js | 81 +++---- comps/Login.js | 81 ++++--- comps/Markdown.js | 21 +- comps/MngDoc.js | 218 +++++++++-------- comps/PaddedRow.js | 20 +- comps/Page.js | 36 +-- comps/Setup.js | 128 +++++----- comps/Spinner.js | 6 +- genSecret.js | 37 ++- next.config.js | 28 +-- package.json | 4 +- pages/_app.js | 48 ++-- pages/_document.js | 23 +- pages/edit.js | 25 +- pages/index.js | 194 +++++++++------- pages/k.js | 77 +++--- pages/new.js | 4 +- pages/settings.js | 135 ++++++----- redux/actions/userAct.js | 126 +++++----- redux/reducers/userRed.js | 65 +++--- redux/store.js | 28 +-- src/app.hooks.js | 18 +- src/app.js | 195 ++++++++-------- src/authentication.js | 58 ++--- src/channels.js | 37 +-- src/hooks/logger.js | 22 +- src/index.js | 8 +- src/middleware/index.js | 12 +- src/models/users.model.js | 20 +- src/services/docs/docs.class.js | 348 ++++++++++++++-------------- src/services/docs/docs.hooks.js | 131 ++++++----- src/services/docs/docs.service.js | 31 ++- src/services/docs/loadDocs.js | 118 +++++----- src/services/hooksUtil.js | 20 +- src/services/index.js | 12 +- src/services/users/users.hooks.js | 99 ++++---- src/services/users/users.service.js | 28 +-- src/trustIPs.js | 73 +++--- test/app.test.js | 67 +++--- test/services/docs.test.js | 16 +- test/services/users.test.js | 16 +- util/basePath.js | 10 +- util/checkDirParts.js | 76 +++--- util/freezeSSR.js | 30 +-- util/getDocs.js | 57 ++--- util/getJwt.js | 8 +- util/getUrl.js | 16 +- util/keys.js | 4 +- util/mapUser.js | 6 +- util/parseSort.js | 33 +-- util/stripBase.js | 10 +- util/updStateFromId.js | 8 +- 58 files changed, 1711 insertions(+), 1568 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..0eef3d9 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +.next +styles +config \ No newline at end of file diff --git a/comps/AddDoc.js b/comps/AddDoc.js index 1b729a0..9e7815c 100644 --- a/comps/AddDoc.js +++ b/comps/AddDoc.js @@ -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 ; + return } } - return connect(mapUser)(DocComp); -}; \ No newline at end of file + return connect(mapUser)(DocComp) +} diff --git a/comps/CodeMirror.js b/comps/CodeMirror.js index 4f496e7..31d66ec 100644 --- a/comps/CodeMirror.js +++ b/comps/CodeMirror.js @@ -1,65 +1,65 @@ -import React, { Component } from 'react'; -import cm from 'codemirror'; -import { getKey, isCtrlKey } from '../util/keys'; +import React, { Component } from 'react' +import cm from 'codemirror' +import { getKey, isCtrlKey } from '../util/keys' -if(typeof window !== 'undefined') { - require('codemirror/mode/markdown/markdown'); +if (typeof window !== 'undefined') { + require('codemirror/mode/markdown/markdown') } export default class CodeMirror extends Component { handleChange = () => { - if(!this.editor) return; - const value = this.editor.getValue(); - if(value !== this.props.value) { - this.props.onChange && this.props.onChange(value); - if(this.editor.getValue() !== this.props.value) { - if(this.state.isControlled) { - this.editor.setValue(this.props.value); + if (!this.editor) return + const value = this.editor.getValue() + if (value !== this.props.value) { + this.props.onChange && this.props.onChange(value) + if (this.editor.getValue() !== this.props.value) { + if (this.state.isControlled) { + this.editor.setValue(this.props.value) } else { - this.props.value = value; + this.props.value = value } } } } checkSubmit = (cm, e) => { - const key = getKey(e); - if(isCtrlKey(key)) { - this.ctrlKey = true; - } else if(key === 13 && this.ctrlKey) { - this.props.onSubmit(); - } + const key = getKey(e) + if (isCtrlKey(key)) { + this.ctrlKey = true + } else if (key === 13 && this.ctrlKey) { + this.props.onSubmit() + } } handleKeyUp = (cm, e) => { - if(isCtrlKey(getKey(e))) this.ctrlKey = false; + if (isCtrlKey(getKey(e))) this.ctrlKey = false } componentDidMount() { - if(typeof window === 'undefined') return; - this.editor = cm.fromTextArea(this.textarea, this.props.options); - this.editor.on('change', this.handleChange); - if(typeof this.props.onSubmit === 'function') { - this.editor.on('keydown', this.checkSubmit); - this.editor.on('keyup', this.handleKeyUp); - this.setupSubmitKey = true; + if (typeof window === 'undefined') return + this.editor = cm.fromTextArea(this.textarea, this.props.options) + this.editor.on('change', this.handleChange) + if (typeof this.props.onSubmit === 'function') { + this.editor.on('keydown', this.checkSubmit) + this.editor.on('keyup', this.handleKeyUp) + this.setupSubmitKey = true } } componentWillUnmount() { - if(this.setupSubmitKey) { - this.editor.off('keydown', this.checkSubmit); - this.editor.off('keyup', this.handleKeyUp); - this.setupSubmitKey = false; + if (this.setupSubmitKey) { + this.editor.off('keydown', this.checkSubmit) + this.editor.off('keyup', this.handleKeyUp) + this.setupSubmitKey = false } } componentDidUpdate() { - if(!this.editor || !this.props.value) return; - if(this.editor.getValue() !== this.props.value) { - this.editor.setValue(this.props.value); + if (!this.editor || !this.props.value) return + if (this.editor.getValue() !== this.props.value) { + this.editor.setValue(this.props.value) } } render() { - const { value, className, onChange } = this.props; + const { value, className, onChange } = this.props return ( -
-