diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..01af582 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +/build +/dump diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..8cafca0 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,22 @@ +{ + "root": true, + + "settings": { + "import/resolver": { + "node": { + "extensions": [".js", ".jsx", ".mjs"] + } + } + }, + + "extends": ["standard", "prettier"], + + "rules": { + "import/no-extraneous-dependencies": 2, + "no-console": [2, { "allow": ["info", "error", "warn"] }], + "no-unused-expressions": 0, + "no-unused-vars": 0, + "no-var": 2, + "prefer-const": 2 + } +} diff --git a/assets/less/dragula.less b/assets/less/dragula.less index 28578f4..3af2219 100644 --- a/assets/less/dragula.less +++ b/assets/less/dragula.less @@ -20,6 +20,6 @@ div.item.gu-mirror { .gu-transit { display: none !important; opacity: 0.2; - -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=20)"; + -ms-filter: 'progid:DXImageTransform.Microsoft.Alpha(Opacity=20)'; filter: alpha(opacity=20); } diff --git a/assets/less/main.less b/assets/less/main.less index a2e72cc..0eca8c9 100644 --- a/assets/less/main.less +++ b/assets/less/main.less @@ -1,4 +1,4 @@ -@import "./dragula"; +@import './dragula'; div.container { width: 100%; diff --git a/client/.eslintrc b/client/.eslintrc new file mode 100644 index 0000000..e38330e --- /dev/null +++ b/client/.eslintrc @@ -0,0 +1,7 @@ +{ + "extends": ["../.eslintrc", "standard-jsx", "prettier/react"], + + "env": { + "browser": true + } +} diff --git a/client/actions/results.js b/client/actions/results.js index e2d2532..cacadd0 100644 --- a/client/actions/results.js +++ b/client/actions/results.js @@ -1,51 +1,52 @@ -import { pick } from 'lowline'; +import { pick } from 'lowline' -export const DELETE_RESULT = 'DELETE_RESULT'; +export const DELETE_RESULT = 'DELETE_RESULT' -const baseUrl = '/api/results'; +const baseUrl = '/api/results' const headers = { 'X-Requested-With': 'XMLHttpRequest', accept: 'application/json', -}; +} -export const FETCH_RESULTS = 'FETCH_RESULTS'; +export const FETCH_RESULTS = 'FETCH_RESULTS' // query can be a query string (without ?, ie not a search string) export function fetchResults(query = {}) { - query = typeof query === 'string' ? query : qs.stringify(query); + query = typeof query === 'string' ? query : qs.stringify(query) return (dispatch) => { fetch(`${baseUrl}${query ? `?${query}` : ''}`, { credentials: 'same-origin', headers, - }).then((res) => res.json()) - .then((json) => { - const actions = [receiveResults(json.results || [])]; + }) + .then((res) => res.json()) + .then((json) => { + const actions = [receiveResults(json.results || [])] - if (json.perPage) { - actions.push(setPagination(pick(json, 'perPage', 'totalCount'))); - } + if (json.perPage) { + actions.push(setPagination(pick(json, 'perPage', 'totalCount'))) + } - dispatch(batchActions(actions)); - }); - }; + dispatch(batchActions(actions)) + }) + } } -export const RECEIVE_RESULTS = 'RECEIVE_RESULTS'; +export const RECEIVE_RESULTS = 'RECEIVE_RESULTS' export function receiveResults(json) { return { type: RECEIVE_RESULTS, payload: json, receivedAt: Date.now(), - }; + } } -export const REMOVE_RESULTS = 'REMOVE_RESULTS'; +export const REMOVE_RESULTS = 'REMOVE_RESULTS' export function removeResults() { return { type: REMOVE_RESULTS, - }; + } } diff --git a/client/components/Link.jsx b/client/components/Link.jsx index 800b538..094bfd4 100644 --- a/client/components/Link.jsx +++ b/client/components/Link.jsx @@ -1,13 +1,17 @@ -import { h } from 'preact'; +import { h } from 'preact' -import formatTime from '../util/formatTime'; +import formatTime from '../util/formatTime' export default (props) => (
  • - {props.Line.Name} + {props.Line.Name}
  • -); +) diff --git a/client/components/Result.jsx b/client/components/Result.jsx index 87e1460..5f3ae4a 100644 --- a/client/components/Result.jsx +++ b/client/components/Result.jsx @@ -1,12 +1,12 @@ -import { h, Component } from 'preact'; +import { h, Component } from 'preact' -import Link from './Link'; +import Link from './Link' -import formatTime from '../util/formatTime'; +import formatTime from '../util/formatTime' export default class Result extends Component { toggle() { - console.log('toggle'); + console.log('toggle') this.setState({ expand: !this.state.expand, }) @@ -17,9 +17,11 @@ export default class Result extends Component {
  • this.toggle()}> {formatTime(props.DepDateTime)} - {formatTime(props.ArrDateTime)}
  • - ); + ) } } diff --git a/client/components/ResultList.jsx b/client/components/ResultList.jsx index 39f5f52..c59230c 100644 --- a/client/components/ResultList.jsx +++ b/client/components/ResultList.jsx @@ -1,24 +1,21 @@ -import { h, Component } from 'preact'; +import { h, Component } from 'preact' -import Result from './Result'; -import store from '../store'; +import Result from './Result' +import store from '../store' export default class ResultList extends Component { componentDidMount() { - this.unsubscribe = store.subscribe(() => this.forceUpdate()); + this.unsubscribe = store.subscribe(() => this.forceUpdate()) } componentWillUnmount() { - this.unsubscribe(); + this.unsubscribe() } render() { - const { results } = store.getState(); - console.log(results); + const { results } = store.getState() + console.log(results) - return ( - - ); + return } } - diff --git a/client/index.js b/client/index.js index 4a5b9be..1f6eeca 100644 --- a/client/index.js +++ b/client/index.js @@ -1,13 +1,13 @@ -import { $, $$ } from 'dollr'; -import dragula from 'dragula'; +import { $, $$ } from 'dollr' +import dragula from 'dragula' -import { h, render } from 'preact'; -import ResultList from './components/ResultList'; +import { h, render } from 'preact' +import ResultList from './components/ResultList' -import store from './store'; -import { receiveResults } from './actions/results'; -const result = $('pre'); -const containers = $$('.location'); +import store from './store' +import { receiveResults } from './actions/results' +const result = $('pre') +const containers = $$('.location') const drake = dragula(containers, { revertOnSpill: true, @@ -16,12 +16,12 @@ const drake = dragula(containers, { // // console.log(target); // return true; - ignoreInputTextSelection: false, + ignoreInputTextSelection: false, // } -}); +}) drake.on('drop', (el, target, source) => { - drake.cancel(); + drake.cancel() if (target !== source) { fetch('/api/trip', { @@ -34,37 +34,36 @@ drake.on('drop', (el, target, source) => { from: source.dataset.location, to: target.dataset.location, }), - }).then((res) => { - return res.json(); - }).then((json) => { - console.log(json); - // result.textContent = JSON.stringify(json, null, ' ') - store.dispatch(receiveResults(json)); - }).catch((err) => { - console.log('error'); - console.log(err); - }); + }) + .then((res) => { + return res.json() + }) + .then((json) => { + console.log(json) + // result.textContent = JSON.stringify(json, null, ' ') + store.dispatch(receiveResults(json)) + }) + .catch((err) => { + console.log('error') + console.log(err) + }) } -}); +}) function prevent(e) { - e.preventDefault(); + e.preventDefault() } drake.on('over', (el, target, source) => { if (target !== source) { - target.classList.add('over'); + target.classList.add('over') } -}); +}) drake.on('out', (el, target, source) => { if (target !== source) { - target.classList.remove('over'); + target.classList.remove('over') } -}); - -render( - , - $('#results') -); +}) +render(, $('#results')) diff --git a/client/master.jsx b/client/master.jsx index ee553ca..344dc13 100644 --- a/client/master.jsx +++ b/client/master.jsx @@ -1,26 +1,44 @@ -import { h } from 'jsx-node'; +import { h } from 'jsx-node' export default ({ articleUrl, protocol, hostname, websocketsPort, INITIAL_STATE, js, css, cssFile }) => { - return '' + ( - - - Journey - - - - + return ( + '' + + ( + + + Journey + + + + - - -
    -
    Home
    -
    Office
    -
    Brother
    -
    The Rapist
    -
    -
    -