From 7eacda2ae7c175ba1113ad2de01ae9e9be9f8118 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sat, 8 Oct 2016 00:31:32 +0800 Subject: [PATCH] code style --- .eslintrc.js | 7 ++++++ .../src/Metamaps/GlobalUI/ImportDialog.js | 14 ++++++----- frontend/src/Metamaps/Map/index.js | 3 --- frontend/src/Metamaps/PasteInput.js | 2 +- frontend/src/components/ImportDialogBox.js | 3 ++- frontend/src/components/Maps/Header.js | 24 +++++++++---------- frontend/src/components/Maps/MapCard.js | 10 ++++---- frontend/src/components/Maps/MapperCard.js | 16 ++++++------- frontend/src/components/Maps/index.js | 12 +++++----- 9 files changed, 49 insertions(+), 42 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index aa594fa7..1222f4a1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,6 +1,11 @@ module.exports = { "sourceType": "module", "parser": "babel-eslint", + "parserOptions": { + "ecmaFeatures": { + "jsx": true + } + }, "extends": "standard", "installedESLint": true, "env": { @@ -13,6 +18,8 @@ module.exports = { "react" ], "rules": { + "react/jsx-uses-react": [2], + "react/jsx-uses-vars": [2], "yoda": [2, "never", { "exceptRange": true }] } } diff --git a/frontend/src/Metamaps/GlobalUI/ImportDialog.js b/frontend/src/Metamaps/GlobalUI/ImportDialog.js index 3671cd90..96f9524f 100644 --- a/frontend/src/Metamaps/GlobalUI/ImportDialog.js +++ b/frontend/src/Metamaps/GlobalUI/ImportDialog.js @@ -1,3 +1,5 @@ +/* global $ */ + import React from 'react' import ReactDOM from 'react-dom' import outdent from 'outdent' @@ -10,7 +12,7 @@ const ImportDialog = { openLightbox: null, closeLightbox: null, - init: function(serverData, openLightbox, closeLightbox) { + init: function (serverData, openLightbox, closeLightbox) { const self = ImportDialog self.openLightbox = openLightbox self.closeLightbox = closeLightbox @@ -22,14 +24,14 @@ const ImportDialog = { `)) ReactDOM.render(React.createElement(ImportDialogBox, { onFileAdded: PasteInput.handleFile, - exampleImageUrl: serverData['import-example.png'], + exampleImageUrl: serverData['import-example.png'] }), $('.importDialogWrapper').get(0)) }, - show: function() { - self.openLightbox('import-dialog') + show: function () { + ImportDialog.openLightbox('import-dialog') }, - hide: function() { - self.closeLightbox('import-dialog') + hide: function () { + ImportDialog.closeLightbox('import-dialog') } } diff --git a/frontend/src/Metamaps/Map/index.js b/frontend/src/Metamaps/Map/index.js index 7d7322fc..43f04a30 100644 --- a/frontend/src/Metamaps/Map/index.js +++ b/frontend/src/Metamaps/Map/index.js @@ -1,8 +1,6 @@ /* global Metamaps, $ */ import outdent from 'outdent' -import React from 'react' -import ReactDOM from 'react-dom' import Active from '../Active' import AutoLayout from '../AutoLayout' @@ -47,7 +45,6 @@ const Map = { return false }) - $('.starMap').click(function () { if ($(this).is('.starred')) self.unstar() else self.star() diff --git a/frontend/src/Metamaps/PasteInput.js b/frontend/src/Metamaps/PasteInput.js index 51d4a933..f0425032 100644 --- a/frontend/src/Metamaps/PasteInput.js +++ b/frontend/src/Metamaps/PasteInput.js @@ -45,7 +45,7 @@ const PasteInput = { handleFile: (file, coords = null) => { var self = PasteInput - var fileReader = new FileReader() + var fileReader = new window.FileReader() fileReader.readAsText(file) fileReader.onload = function(e) { var text = e.currentTarget.result diff --git a/frontend/src/components/ImportDialogBox.js b/frontend/src/components/ImportDialogBox.js index 9851fd07..bfb60235 100644 --- a/frontend/src/components/ImportDialogBox.js +++ b/frontend/src/components/ImportDialogBox.js @@ -2,7 +2,7 @@ import React, { PropTypes, Component } from 'react' import Dropzone from 'react-dropzone' class ImportDialogBox extends Component { - constructor(props) { + constructor (props) { super(props) this.state = { @@ -16,6 +16,7 @@ class ImportDialogBox extends Component { handleFile = (files, e) => { // for some reason it uploads twice, so we need this debouncer + // eslint-disable-next-line no-return-assign this.debouncer = this.debouncer || window.setTimeout(() => this.debouncer = null, 10) if (!this.debouncer) { this.props.onFileAdded(files[0]) diff --git a/frontend/src/components/Maps/Header.js b/frontend/src/components/Maps/Header.js index ee4184d5..d323c0d5 100644 --- a/frontend/src/components/Maps/Header.js +++ b/frontend/src/components/Maps/Header.js @@ -21,15 +21,15 @@ class Header extends Component { const { signedIn, section } = this.props const activeClass = (title) => { - let forClass = "exploreMapsButton" - forClass += " " + title + "Maps" - if (title == "my" && section == "mine" || - title == section) forClass += " active" + let forClass = 'exploreMapsButton' + forClass += ' ' + title + 'Maps' + if (title === 'my' && section === 'mine' || + title === section) forClass += ' active' return forClass } - const explore = section == "mine" || section == "active" || section == "starred" || section == "shared" || section == "featured" - const mapper = section == "mapper" + const explore = section === 'mine' || section === 'active' || section === 'starred' || section === 'shared' || section === 'featured' + const mapper = section === 'mapper' return (
@@ -38,31 +38,31 @@ class Header extends Component {
diff --git a/frontend/src/components/Maps/MapCard.js b/frontend/src/components/Maps/MapCard.js index bf1416fc..e31ede18 100644 --- a/frontend/src/components/Maps/MapCard.js +++ b/frontend/src/components/Maps/MapCard.js @@ -3,7 +3,7 @@ import React, { Component, PropTypes } from 'react' class MapCard extends Component { render = () => { const { map, currentUser } = this.props - + function capitalize (string) { return string.charAt(0).toUpperCase() + string.slice(1) } @@ -16,12 +16,12 @@ class MapCard extends Component { const truncatedName = n ? (n.length > maxNameLength ? n.substring(0, maxNameLength) + '...' : n) : '' const truncatedDesc = d ? (d.length > maxDescLength ? d.substring(0, maxDescLength) + '...' : d) : '' const editPermission = map.authorizeToEdit(currentUser) ? 'canEdit' : 'cannotEdit' - + return ( +
diff --git a/frontend/src/components/Maps/MapperCard.js b/frontend/src/components/Maps/MapperCard.js index e2f4cb33..dbb06cbc 100644 --- a/frontend/src/components/Maps/MapperCard.js +++ b/frontend/src/components/Maps/MapperCard.js @@ -3,14 +3,14 @@ import React, { Component, PropTypes } from 'react' class MapperCard extends Component { render = () => { const { user } = this.props - + return (
-
+
-
-
+
+
{ user.name }
@@ -19,10 +19,10 @@ class MapperCard extends Component {
{ user.numMaps }
maps
-
{ user.numTopics }
topics
-
{ user.numSynapses }
synapses
-
-
+
{ user.numTopics }
topics
+
{ user.numSynapses }
synapses
+
+
) diff --git a/frontend/src/components/Maps/index.js b/frontend/src/components/Maps/index.js index 2c3e8ba1..22a41d3e 100644 --- a/frontend/src/components/Maps/index.js +++ b/frontend/src/components/Maps/index.js @@ -9,12 +9,11 @@ class Maps extends Component { const { maps, currentUser, section, displayStyle, user, moreToLoad, loadMore } = this.props let mapElements - if (displayStyle == 'grid') { + if (displayStyle === 'grid') { mapElements = maps.models.map(function (map) { return }) - } - else if (displayStyle == 'list') { + } else if (displayStyle === 'list') { mapElements = maps.models.map(function (map) { return }) @@ -28,9 +27,10 @@ class Maps extends Component { { currentUser && !user ?
Create new map...
: null } { mapElements }
- { moreToLoad ? - [,
] - : null } + {!moreToLoad ? null : [ + , +
+ ]}