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 ( -
-