code style

This commit is contained in:
Devin Howard 2016-10-08 00:31:32 +08:00
parent 20da1ef39f
commit 7eacda2ae7
9 changed files with 49 additions and 42 deletions

View file

@ -1,6 +1,11 @@
module.exports = { module.exports = {
"sourceType": "module", "sourceType": "module",
"parser": "babel-eslint", "parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
},
"extends": "standard", "extends": "standard",
"installedESLint": true, "installedESLint": true,
"env": { "env": {
@ -13,6 +18,8 @@ module.exports = {
"react" "react"
], ],
"rules": { "rules": {
"react/jsx-uses-react": [2],
"react/jsx-uses-vars": [2],
"yoda": [2, "never", { "exceptRange": true }] "yoda": [2, "never", { "exceptRange": true }]
} }
} }

View file

@ -1,3 +1,5 @@
/* global $ */
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import outdent from 'outdent' import outdent from 'outdent'
@ -10,7 +12,7 @@ const ImportDialog = {
openLightbox: null, openLightbox: null,
closeLightbox: null, closeLightbox: null,
init: function(serverData, openLightbox, closeLightbox) { init: function (serverData, openLightbox, closeLightbox) {
const self = ImportDialog const self = ImportDialog
self.openLightbox = openLightbox self.openLightbox = openLightbox
self.closeLightbox = closeLightbox self.closeLightbox = closeLightbox
@ -22,14 +24,14 @@ const ImportDialog = {
`)) `))
ReactDOM.render(React.createElement(ImportDialogBox, { ReactDOM.render(React.createElement(ImportDialogBox, {
onFileAdded: PasteInput.handleFile, onFileAdded: PasteInput.handleFile,
exampleImageUrl: serverData['import-example.png'], exampleImageUrl: serverData['import-example.png']
}), $('.importDialogWrapper').get(0)) }), $('.importDialogWrapper').get(0))
}, },
show: function() { show: function () {
self.openLightbox('import-dialog') ImportDialog.openLightbox('import-dialog')
}, },
hide: function() { hide: function () {
self.closeLightbox('import-dialog') ImportDialog.closeLightbox('import-dialog')
} }
} }

View file

@ -1,8 +1,6 @@
/* global Metamaps, $ */ /* global Metamaps, $ */
import outdent from 'outdent' import outdent from 'outdent'
import React from 'react'
import ReactDOM from 'react-dom'
import Active from '../Active' import Active from '../Active'
import AutoLayout from '../AutoLayout' import AutoLayout from '../AutoLayout'
@ -47,7 +45,6 @@ const Map = {
return false return false
}) })
$('.starMap').click(function () { $('.starMap').click(function () {
if ($(this).is('.starred')) self.unstar() if ($(this).is('.starred')) self.unstar()
else self.star() else self.star()

View file

@ -45,7 +45,7 @@ const PasteInput = {
handleFile: (file, coords = null) => { handleFile: (file, coords = null) => {
var self = PasteInput var self = PasteInput
var fileReader = new FileReader() var fileReader = new window.FileReader()
fileReader.readAsText(file) fileReader.readAsText(file)
fileReader.onload = function(e) { fileReader.onload = function(e) {
var text = e.currentTarget.result var text = e.currentTarget.result

View file

@ -2,7 +2,7 @@ import React, { PropTypes, Component } from 'react'
import Dropzone from 'react-dropzone' import Dropzone from 'react-dropzone'
class ImportDialogBox extends Component { class ImportDialogBox extends Component {
constructor(props) { constructor (props) {
super(props) super(props)
this.state = { this.state = {
@ -16,6 +16,7 @@ class ImportDialogBox extends Component {
handleFile = (files, e) => { handleFile = (files, e) => {
// for some reason it uploads twice, so we need this debouncer // 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) this.debouncer = this.debouncer || window.setTimeout(() => this.debouncer = null, 10)
if (!this.debouncer) { if (!this.debouncer) {
this.props.onFileAdded(files[0]) this.props.onFileAdded(files[0])

View file

@ -21,15 +21,15 @@ class Header extends Component {
const { signedIn, section } = this.props const { signedIn, section } = this.props
const activeClass = (title) => { const activeClass = (title) => {
let forClass = "exploreMapsButton" let forClass = 'exploreMapsButton'
forClass += " " + title + "Maps" forClass += ' ' + title + 'Maps'
if (title == "my" && section == "mine" || if (title === 'my' && section === 'mine' ||
title == section) forClass += " active" title === section) forClass += ' active'
return forClass return forClass
} }
const explore = section == "mine" || section == "active" || section == "starred" || section == "shared" || section == "featured" const explore = section === 'mine' || section === 'active' || section === 'starred' || section === 'shared' || section === 'featured'
const mapper = section == "mapper" const mapper = section === 'mapper'
return ( return (
<div id="exploreMapsHeader"> <div id="exploreMapsHeader">
@ -38,31 +38,31 @@ class Header extends Component {
<div className="exploreMapsCenter"> <div className="exploreMapsCenter">
<MapLink show={signedIn && explore} <MapLink show={signedIn && explore}
href="/explore/mine" href="/explore/mine"
linkClass={activeClass("my")} linkClass={activeClass('my')}
data-router="true" data-router="true"
text="My Maps" text="My Maps"
/> />
<MapLink show={signedIn && explore} <MapLink show={signedIn && explore}
href="/explore/shared" href="/explore/shared"
linkClass={activeClass("shared")} linkClass={activeClass('shared')}
data-router="true" data-router="true"
text="Shared With Me" text="Shared With Me"
/> />
<MapLink show={signedIn && explore} <MapLink show={signedIn && explore}
href="/explore/starred" href="/explore/starred"
linkClass={activeClass("starred")} linkClass={activeClass('starred')}
data-router="true" data-router="true"
text="Starred By Me" text="Starred By Me"
/> />
<MapLink show={explore} <MapLink show={explore}
href={signedIn ? "/" : "/explore/active"} href={signedIn ? '/' : '/explore/active'}
linkClass={activeClass("active")} linkClass={activeClass('active')}
data-router="true" data-router="true"
text="Global" text="Global"
/> />
<MapLink show={!signedIn && explore} <MapLink show={!signedIn && explore}
href="/explore/featured" href="/explore/featured"
linkClass={activeClass("featured")} linkClass={activeClass('featured')}
data-router="true" data-router="true"
text="Featured Maps" text="Featured Maps"
/> />

View file

@ -3,7 +3,7 @@ import React, { Component, PropTypes } from 'react'
class MapCard extends Component { class MapCard extends Component {
render = () => { render = () => {
const { map, currentUser } = this.props const { map, currentUser } = this.props
function capitalize (string) { function capitalize (string) {
return string.charAt(0).toUpperCase() + string.slice(1) 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 truncatedName = n ? (n.length > maxNameLength ? n.substring(0, maxNameLength) + '...' : n) : ''
const truncatedDesc = d ? (d.length > maxDescLength ? d.substring(0, maxDescLength) + '...' : d) : '' const truncatedDesc = d ? (d.length > maxDescLength ? d.substring(0, maxDescLength) + '...' : d) : ''
const editPermission = map.authorizeToEdit(currentUser) ? 'canEdit' : 'cannotEdit' const editPermission = map.authorizeToEdit(currentUser) ? 'canEdit' : 'cannotEdit'
return ( return (
<div className="map" id={ map.id }> <div className="map" id={ map.id }>
<a href={ '/maps/' + map.id } data-router="true"> <a href={ '/maps/' + map.id } data-router="true">
<div className={ 'permission ' + editPermission }> <div className={ 'permission ' + editPermission }>
<div className="mapCard"> <div className="mapCard">
<span className="title" title={ map.get('name') }> <span className="title" title={ map.get('name') }>
{ truncatedName } { truncatedName }
</span> </span>
@ -46,7 +46,7 @@ class MapCard extends Component {
{ map.get('topic_count') } { map.get('topic_count') }
</span> </span>
{ map.get('topic_count') === 1 ? ' topic' : ' topics' } { map.get('topic_count') === 1 ? ' topic' : ' topics' }
</div> </div>
<div className="metadataSection mapPermission"> <div className="metadataSection mapPermission">
{ map.get('permission') ? capitalize(map.get('permission')) : 'Commons' } { map.get('permission') ? capitalize(map.get('permission')) : 'Commons' }
</div> </div>
@ -57,7 +57,7 @@ class MapCard extends Component {
{ map.get('synapse_count') === 1 ? ' synapse' : ' synapses' } { map.get('synapse_count') === 1 ? ' synapse' : ' synapses' }
</div> </div>
<div className="clearfloat"></div> <div className="clearfloat"></div>
</div> </div>
</div> </div>
</div> </div>
</a> </a>

View file

@ -3,14 +3,14 @@ import React, { Component, PropTypes } from 'react'
class MapperCard extends Component { class MapperCard extends Component {
render = () => { render = () => {
const { user } = this.props const { user } = this.props
return ( return (
<div className="mapper"> <div className="mapper">
<div className="mapperCard"> <div className="mapperCard">
<div className="mapperImage"> <div className="mapperImage">
<img src={ user.image } width="96" height="96" /> <img src={ user.image } width="96" height="96" />
</div> </div>
<div className="mapperName" title={ user.name }> <div className="mapperName" title={ user.name }>
{ user.name } { user.name }
</div> </div>
<div className="mapperInfo"> <div className="mapperInfo">
@ -19,10 +19,10 @@ class MapperCard extends Component {
</div> </div>
<div className="mapperMetadata"> <div className="mapperMetadata">
<div className="metadataSection metadataMaps"><div>{ user.numMaps }</div>maps</div> <div className="metadataSection metadataMaps"><div>{ user.numMaps }</div>maps</div>
<div className="metadataSection metadataTopics"><div>{ user.numTopics }</div>topics</div> <div className="metadataSection metadataTopics"><div>{ user.numTopics }</div>topics</div>
<div className="metadataSection metadataSynapses"><div>{ user.numSynapses }</div>synapses</div> <div className="metadataSection metadataSynapses"><div>{ user.numSynapses }</div>synapses</div>
<div className="clearfloat"></div> <div className="clearfloat"></div>
</div> </div>
</div> </div>
</div> </div>
) )

View file

@ -9,12 +9,11 @@ class Maps extends Component {
const { maps, currentUser, section, displayStyle, user, moreToLoad, loadMore } = this.props const { maps, currentUser, section, displayStyle, user, moreToLoad, loadMore } = this.props
let mapElements let mapElements
if (displayStyle == 'grid') { if (displayStyle === 'grid') {
mapElements = maps.models.map(function (map) { mapElements = maps.models.map(function (map) {
return <MapCard key={ map.id } map={ map } currentUser={ currentUser } /> return <MapCard key={ map.id } map={ map } currentUser={ currentUser } />
}) })
} } else if (displayStyle === 'list') {
else if (displayStyle == 'list') {
mapElements = maps.models.map(function (map) { mapElements = maps.models.map(function (map) {
return <MapListItem key={ map.id } map={ map } /> return <MapListItem key={ map.id } map={ map } />
}) })
@ -28,9 +27,10 @@ class Maps extends Component {
{ currentUser && !user ? <div className="map newMap"><a href="/maps/new"><div className="newMapImage"></div><span>Create new map...</span></a></div> : null } { currentUser && !user ? <div className="map newMap"><a href="/maps/new"><div className="newMapImage"></div><span>Create new map...</span></a></div> : null }
{ mapElements } { mapElements }
<div className='clearfloat'></div> <div className='clearfloat'></div>
{ moreToLoad ? {!moreToLoad ? null : [
[<button className="button loadMore" onClick={ loadMore }>load more</button>, <div className='clearfloat'></div>] <button className="button loadMore" onClick={ loadMore }>load more</button>,
: null } <div className='clearfloat'></div>
]}
</div> </div>
</div> </div>
<Header signedIn={ !!currentUser } <Header signedIn={ !!currentUser }