From eb6dce527743af13abf1dc946f769339f4b6a726 Mon Sep 17 00:00:00 2001 From: Katie Thornhill Date: Tue, 19 Nov 2019 23:22:37 -0500 Subject: [PATCH] chore: loads of lgtm maintainability fixes --- Server/api/servers.js | 1 - Server/index.js | 47 +++++------------------ Server/models/index.js | 1 - UI/src/components/add-server/index.js | 7 ++-- UI/src/components/oauth-bot-flow/index.js | 5 +-- UI/src/components/role-editor/index.js | 17 ++++---- UI/src/components/role-picker/index.js | 12 ++---- UI/src/components/servers/ServerCard.js | 2 - UI/src/components/servers/index.js | 15 ++++---- UI/src/pages/Landing.js | 9 ++--- UI/src/reducers/role-editor.js | 2 +- UI/src/router/index.js | 13 +++---- UI/src/store/configureStore.dev.js | 11 ++---- 13 files changed, 44 insertions(+), 98 deletions(-) diff --git a/Server/api/servers.js b/Server/api/servers.js index 8c2f511..9778d2c 100644 --- a/Server/api/servers.js +++ b/Server/api/servers.js @@ -39,7 +39,6 @@ module.exports = (R, $) => { }) R.get('/api/server/:id/slug', async ctx => { - const { userId } = ctx.session const { id } = ctx.params const srv = $.discord.client.guilds.get(id) diff --git a/Server/index.js b/Server/index.js index d56dd59..f00b35e 100644 --- a/Server/index.js +++ b/Server/index.js @@ -53,10 +53,6 @@ async function start() { const pub = path.resolve(path.join(__dirname, 'public')) log.info('public path', pub) - const staticFiles = require('koa-static') - // app.use(staticFiles(pub, { defer: true, gzip: true, br: true })) - - const send = require('koa-send') app.use(async (ctx, next) => { if (ctx.path.startsWith('/api')) { log.info('api breakout') @@ -85,40 +81,15 @@ async function start() { try { ctx.body = fs.readFileSync(path.join(pub, 'index.html'), { encoding: 'utf-8' }) } catch (e) { - ctx.body = e.stack || e.trace + ctx.body = "A problem occured." ctx.status = 500 + console.error(e) } log.info('index sent') ctx.status = 200 return next() } - - // try { - // await next() - // } catch (e) { - // send(ctx, 'index.html', { root: pub }) - // } }) - // const sendOpts = {root: pub, index: 'index.html'} - // // const sendOpts = {} - // app.use(async (ctx, next) => { - // if (ctx.path.startsWith('/api')) { - // return await next() - // } - - // try { - // log.info('pass 1', ctx.path, __dirname+'/public'+ctx.path) - // await send(ctx, __dirname+'/public'+ctx.path, sendOpts) - // } catch (error) { - // try { - // log.info('pass 2 /', ctx.path, __dirname+'/public/index.html') - // await send(ctx, __dirname+'/public/index.html', sendOpts) - // } catch (error) { - // log.info('exit to next', ctx.path) - // await next() - // } - // } - // }) } // Request logger @@ -129,20 +100,21 @@ async function start() { } catch (e) { log.error(e) ctx.status = ctx.status || 500 + if (DEVEL) { - ctx.body = ctx.body || e.stack - } else { - ctx.body = { - err: 'something terrible happened.', - } + console.error(e) + } + + ctx.body = { + err: 'something terrible happened.', } + } let timeElapsed = new Date() - timeStart log.request( `${ctx.status} ${ctx.method} ${ctx.url} - ${ctx.ip} - took ${timeElapsed}ms` ) - // return null }) const session = require('koa-session') @@ -164,7 +136,6 @@ async function start() { await M.mountRoutes() // SPA server - log.info(`starting HTTP server on ${process.env.APP_PORT || 6769}`) server.listen(process.env.APP_PORT || 6769) } diff --git a/Server/models/index.js b/Server/models/index.js index a492a77..a30ea13 100644 --- a/Server/models/index.js +++ b/Server/models/index.js @@ -1,7 +1,6 @@ const log = new (require('../logger'))('models/index') const glob = require('glob') const path = require('path') -const util = require('../util/model-methods') module.exports = sql => { const models = {} diff --git a/UI/src/components/add-server/index.js b/UI/src/components/add-server/index.js index c529ae7..c8bed09 100644 --- a/UI/src/components/add-server/index.js +++ b/UI/src/components/add-server/index.js @@ -1,10 +1,9 @@ import React, { Component } from 'react' -import { Link } from 'react-router-dom' -import TypingDemo from '../demos/typing' -import RoleypolyDemo from '../demos/roleypoly' import * as Actions from '../../actions' -import './styles.sass' import discordLogo from '../../pages/images/discord-logo.svg' +import RoleypolyDemo from '../demos/roleypoly' +import TypingDemo from '../demos/typing' +import './styles.sass' export default class AddServer extends Component { polling = null diff --git a/UI/src/components/oauth-bot-flow/index.js b/UI/src/components/oauth-bot-flow/index.js index b62d451..6e1a402 100644 --- a/UI/src/components/oauth-bot-flow/index.js +++ b/UI/src/components/oauth-bot-flow/index.js @@ -1,9 +1,6 @@ import React, { Component } from 'react' -import { Redirect } from 'react-router-dom' -import superagent from 'superagent' import { connect } from 'react-redux' -import { push } from 'react-router-redux' -import { fetchServers } from '../../actions' +import superagent from 'superagent' @connect() class OauthCallback extends Component { diff --git a/UI/src/components/role-editor/index.js b/UI/src/components/role-editor/index.js index 1d09677..8a94658 100644 --- a/UI/src/components/role-editor/index.js +++ b/UI/src/components/role-editor/index.js @@ -1,17 +1,14 @@ -import React, { Component } from 'react' import { Set } from 'immutable' -import { connect } from 'react-redux' -import { DropTarget } from 'react-dnd' -import { Link, Prompt, Redirect } from 'react-router-dom' +import React, { Component } from 'react' import { Scrollbars } from 'react-custom-scrollbars' -import * as Actions from './actions' -import * as PickerActions from '../role-picker/actions' +import { DropTarget } from 'react-dnd' +import { connect } from 'react-redux' +import { Link, Prompt, Redirect } from 'react-router-dom' import * as UIActions from '../../actions/ui' -import './RoleEditor.sass' - -import Category from './Category' -import CategoryEditor from './CategoryEditor' import Role from '../role/draggable' +import * as Actions from './actions' +import Category from './Category' +import './RoleEditor.sass' const mapState = ({ rolePicker, roleEditor, servers }, ownProps) => ({ rp: rolePicker, diff --git a/UI/src/components/role-picker/index.js b/UI/src/components/role-picker/index.js index 2c91607..fa2edc5 100644 --- a/UI/src/components/role-picker/index.js +++ b/UI/src/components/role-picker/index.js @@ -1,15 +1,11 @@ -import React, { Component, Fragment } from 'react' +import React, { Component } from 'react' import { connect } from 'react-redux' -import { Prompt } from 'react-router-dom' -import superagent from 'superagent' -import * as Actions from './actions' +import { Link, Prompt } from 'react-router-dom' import * as UIActions from '../../actions/ui' import { msgToReal } from '../../utils' -import './RolePicker.sass' - +import * as Actions from './actions' import Category from './Category' -import { Scrollbars } from 'react-custom-scrollbars' -import { Link } from 'react-router-dom' +import './RolePicker.sass' const mapState = ({ rolePicker, servers }, ownProps) => { return { diff --git a/UI/src/components/servers/ServerCard.js b/UI/src/components/servers/ServerCard.js index fd6e1cd..a5702bc 100644 --- a/UI/src/components/servers/ServerCard.js +++ b/UI/src/components/servers/ServerCard.js @@ -1,9 +1,7 @@ import React, { Component } from 'react' -import { connect } from 'react-redux' import ImmutablePropTypes from 'react-immutable-proptypes' import { NavLink } from 'react-router-dom' import './ServerCard.sass' -import { withRouter } from 'react-router' class ServerCard extends Component { static propTypes = { diff --git a/UI/src/components/servers/index.js b/UI/src/components/servers/index.js index 79e838c..4feffd4 100644 --- a/UI/src/components/servers/index.js +++ b/UI/src/components/servers/index.js @@ -1,15 +1,14 @@ import React, { Component } from 'react' -import { Route, Switch } from 'react-router-dom' import { Scrollbars } from 'react-custom-scrollbars' import { connect } from 'react-redux' -import { withRouter, Redirect } from 'react-router' -import './index.sass' - -import Navigation from './Navigation' -import RolePicker from '../role-picker' -import RoleEditor from '../role-editor' -import AddServer from '../add-server' +import { Redirect } from 'react-router' +import { Route, Switch } from 'react-router-dom' import Error404 from '../../pages/Error404' +import AddServer from '../add-server' +import RoleEditor from '../role-editor' +import RolePicker from '../role-picker' +import './index.sass' +import Navigation from './Navigation' // import mockData from './mockData' diff --git a/UI/src/pages/Landing.js b/UI/src/pages/Landing.js index b3aff27..8f0cb78 100644 --- a/UI/src/pages/Landing.js +++ b/UI/src/pages/Landing.js @@ -1,12 +1,9 @@ -import React, { Component, Fragment } from 'react' +import React from 'react' import { Link } from 'react-router-dom' -import Scrollbars from 'react-custom-scrollbars' -import Typist from 'react-typist' -import moment from 'moment' -import './landing.sass' -import discordLogo from './images/discord-logo.svg' import RoleypolyDemo from '../components/demos/roleypoly' import TypingDemo from '../components/demos/typing' +import discordLogo from './images/discord-logo.svg' +import './landing.sass' const Landing = ({ root = false }) => (
diff --git a/UI/src/reducers/role-editor.js b/UI/src/reducers/role-editor.js index 0a8f772..1e2ef43 100644 --- a/UI/src/reducers/role-editor.js +++ b/UI/src/reducers/role-editor.js @@ -1,4 +1,4 @@ -import { Map, OrderedMap, fromJS } from 'immutable' +import { Map, OrderedMap } from 'immutable' const initialState = Map({ viewMap: OrderedMap({}), diff --git a/UI/src/router/index.js b/UI/src/router/index.js index 1a8d279..398ca38 100644 --- a/UI/src/router/index.js +++ b/UI/src/router/index.js @@ -1,16 +1,13 @@ -import React, { Component, Fragment } from 'react' -import { Route, Switch, Redirect } from 'react-router-dom' +import React, { Component } from 'react' import { connect } from 'react-redux' import { withRouter } from 'react-router' - -import Servers from '../components/servers' +import { Redirect, Route, Switch } from 'react-router-dom' +import OauthBotFlow from '../components/oauth-bot-flow' import OauthCallback from '../components/oauth-callback' import OauthFlow from '../components/oauth-flow' -import OauthBotFlow from '../components/oauth-bot-flow' -import Pages, { Landing, Error404 } from '../pages' +import Servers from '../components/servers' import ServerLanding from '../components/servers/ServerLanding' - -const aaa = props =>
{JSON.stringify(props)}
+import Pages, { Error404, Landing } from '../pages' export default @withRouter diff --git a/UI/src/store/configureStore.dev.js b/UI/src/store/configureStore.dev.js index 87cc6f8..a84607f 100644 --- a/UI/src/store/configureStore.dev.js +++ b/UI/src/store/configureStore.dev.js @@ -1,10 +1,8 @@ -import { createStore, applyMiddleware, compose } from 'redux' -import thunk from 'redux-thunk' -import { createLogger } from 'redux-logger' -// import api from '../middleware/api' -import rootReducer from '../reducers' -import DevTools from '../components/dev-tools' import { routerMiddleware } from 'react-router-redux' +import { applyMiddleware, compose, createStore } from 'redux' +import { createLogger } from 'redux-logger' +import thunk from 'redux-thunk' +import rootReducer from '../reducers' const configureStore = (preloadedState, history) => { const store = createStore( @@ -12,7 +10,6 @@ const configureStore = (preloadedState, history) => { preloadedState, compose( applyMiddleware(thunk, routerMiddleware(history), createLogger()) - // DevTools.instrument() ) )