From e9c3dd284cd8d5c95acb9808103d37ac916cb047 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Tue, 14 Mar 2017 12:51:48 +0200 Subject: [PATCH] Format JS with updated Prettier --- .../EditListingForm/EditListingForm.js | 36 +++++++---- src/containers/LandingPage/LandingPage.js | 7 +- src/containers/SearchPage/SearchPage.duck.js | 23 +++---- src/sagas.js | 7 +- src/util/googleMaps.js | 64 ++++++++++--------- src/util/sagaHelpers.js | 17 ++--- src/util/validators.js | 14 ++-- 7 files changed, 93 insertions(+), 75 deletions(-) diff --git a/src/containers/EditListingForm/EditListingForm.js b/src/containers/EditListingForm/EditListingForm.js index 33bb443a..6f7aac16 100644 --- a/src/containers/EditListingForm/EditListingForm.js +++ b/src/containers/EditListingForm/EditListingForm.js @@ -11,16 +11,17 @@ const TITLE_MAX_LENGTH = 60; // readImage returns a promise which is resolved // when FileReader has loaded given file as dataURL -const readImage = file => new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onload = e => resolve(e.target.result); - reader.onerror = e => { - // eslint-disable-next-line - console.error(`Error ${e} happened while reading ${file.name}: ${e.target.result}`); - reject(new Error(`Error reading ${file.name}: ${e.target.result}`)); - }; - reader.readAsDataURL(file); -}); +const readImage = file => + new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = e => resolve(e.target.result); + reader.onerror = e => { + // eslint-disable-next-line + console.error(`Error ${e} happened while reading ${file.name}: ${e.target.result}`); + reject(new Error(`Error reading ${file.name}: ${e.target.result}`)); + }; + reader.readAsDataURL(file); + }); // Custom inputs with validator messages const RenderField = ({ input, label, type, meta }) => { @@ -126,9 +127,12 @@ class EditListingForm extends Component { submitting, } = this.props; const requiredStr = intl.formatMessage({ id: 'EditListingForm.required' }); - const maxLengthStr = intl.formatMessage({ id: 'EditListingForm.maxLength' }, { - maxLength: TITLE_MAX_LENGTH, - }); + const maxLengthStr = intl.formatMessage( + { id: 'EditListingForm.maxLength' }, + { + maxLength: TITLE_MAX_LENGTH, + }, + ); const maxLength60 = maxLength(maxLengthStr, TITLE_MAX_LENGTH); return ( @@ -155,7 +159,11 @@ class EditListingForm extends Component { renderFulfilled={dataURL => { return (
- {encodeURIComponent(i.file.name)} + {encodeURIComponent(i.file.name)} {uploadingOverlay}
); diff --git a/src/containers/LandingPage/LandingPage.js b/src/containers/LandingPage/LandingPage.js index 26c02c9e..d951484c 100644 --- a/src/containers/LandingPage/LandingPage.js +++ b/src/containers/LandingPage/LandingPage.js @@ -5,9 +5,10 @@ import { HeroSearchForm } from '../../containers'; import { changeLocationFilter } from '../../ducks/LocationFilter.duck'; import css from './LandingPage.css'; -const createSubmitHandler = onLocationChanged => formData => { - onLocationChanged(formData.location); -}; +const createSubmitHandler = onLocationChanged => + formData => { + onLocationChanged(formData.location); + }; export const LandingPageComponent = props => { const { onLocationChanged, filter } = props; diff --git a/src/containers/SearchPage/SearchPage.duck.js b/src/containers/SearchPage/SearchPage.duck.js index 4c1955fc..76caf833 100644 --- a/src/containers/SearchPage/SearchPage.duck.js +++ b/src/containers/SearchPage/SearchPage.duck.js @@ -80,19 +80,20 @@ export const loadListings = { # { id: 123, type: 'user', attributes: { name: "John" }}, ``` */ -const lookupMap = included => included.reduce( - (memo, resource) => { - const { type, id } = resource; +const lookupMap = included => + included.reduce( + (memo, resource) => { + const { type, id } = resource; - // eslint-disable-next-line no-param-reassign - memo[type] = memo[type] || {}; - // eslint-disable-next-line no-param-reassign - memo[type][id.uuid] = resource; + // eslint-disable-next-line no-param-reassign + memo[type] = memo[type] || {}; + // eslint-disable-next-line no-param-reassign + memo[type][id.uuid] = resource; - return memo; - }, - {}, -); + return memo; + }, + {}, + ); // Format the data as ListingCard component expects it and // add some fake data diff --git a/src/sagas.js b/src/sagas.js index 8dfa8e69..6698de74 100644 --- a/src/sagas.js +++ b/src/sagas.js @@ -2,8 +2,9 @@ import { watchAuthInfo, watchAuth } from './ducks/Auth.duck'; import { watchLoadListings } from './containers/SearchPage/SearchPage.duck'; import { watchSdk } from './ducks/sdk.duck'; -const createRootSaga = sdk => function* rootSaga() { - yield [watchAuthInfo(sdk), watchAuth(sdk), watchLoadListings(sdk), watchSdk(sdk)]; -}; +const createRootSaga = sdk => + function* rootSaga() { + yield [watchAuthInfo(sdk), watchAuth(sdk), watchLoadListings(sdk), watchSdk(sdk)]; + }; export default createRootSaga; diff --git a/src/util/googleMaps.js b/src/util/googleMaps.js index 018b9f6b..532bf50f 100644 --- a/src/util/googleMaps.js +++ b/src/util/googleMaps.js @@ -30,25 +30,28 @@ const placeBounds = place => { * @return {Promise} Promise that * resolves to the detailed place, rejects if the request failed */ -export const getPlaceDetails = placeId => new Promise((resolve, reject) => { - const serviceStatus = window.google.maps.places.PlacesServiceStatus; - const el = document.createElement('div'); - const service = new window.google.maps.places.PlacesService(el); +export const getPlaceDetails = placeId => + new Promise((resolve, reject) => { + const serviceStatus = window.google.maps.places.PlacesServiceStatus; + const el = document.createElement('div'); + const service = new window.google.maps.places.PlacesService(el); - service.getDetails({ placeId }, (place, status) => { - if (status !== serviceStatus.OK) { - reject( - new Error(`Could not get details for place id "${placeId}", error status was "${status}"`), - ); - } else { - resolve({ - address: place.formatted_address, - origin: placeOrigin(place), - bounds: placeBounds(place), - }); - } + service.getDetails({ placeId }, (place, status) => { + if (status !== serviceStatus.OK) { + reject( + new Error( + `Could not get details for place id "${placeId}", error status was "${status}"`, + ), + ); + } else { + resolve({ + address: place.formatted_address, + origin: placeOrigin(place), + bounds: placeBounds(place), + }); + } + }); }); -}); const predictionSuccessful = status => { const { OK, ZERO_RESULTS } = window.google.maps.places.PlacesServiceStatus; @@ -64,18 +67,19 @@ const predictionSuccessful = status => { * with the original search query and an array of * `google.maps.places.AutocompletePrediction` objects */ -export const getPlacePredictions = search => new Promise((resolve, reject) => { - const service = new window.google.maps.places.AutocompleteService(); +export const getPlacePredictions = search => + new Promise((resolve, reject) => { + const service = new window.google.maps.places.AutocompleteService(); - service.getPlacePredictions({ input: search }, (predictions, status) => { - if (!predictionSuccessful(status)) { - reject(new Error(`Prediction service status not OK: ${status}`)); - } else { - const results = { - search, - predictions: predictions || [], - }; - resolve(results); - } + service.getPlacePredictions({ input: search }, (predictions, status) => { + if (!predictionSuccessful(status)) { + reject(new Error(`Prediction service status not OK: ${status}`)); + } else { + const results = { + search, + predictions: predictions || [], + }; + resolve(results); + } + }); }); -}); diff --git a/src/util/sagaHelpers.js b/src/util/sagaHelpers.js index 17c1220a..d9546990 100644 --- a/src/util/sagaHelpers.js +++ b/src/util/sagaHelpers.js @@ -6,12 +6,13 @@ const SUCCESS = 'SUCCESS'; const FAILURE = 'FAILURE'; // response format: { REQUEST: 'baseStr.REQUEST', SUCCESS: 'baseStr.SUCCESS', FAILURE: 'baseStr.FAILURE' } -export const createRequestTypes = base => [REQUEST, SUCCESS, FAILURE].reduce( - (acc, type) => { - // eslint-disable-next-line no-param-reassign - acc[type] = `${base}.${type}`; - return acc; - }, - {}, -); +export const createRequestTypes = base => + [REQUEST, SUCCESS, FAILURE].reduce( + (acc, type) => { + // eslint-disable-next-line no-param-reassign + acc[type] = `${base}.${type}`; + return acc; + }, + {}, + ); /* eslint-enable import/prefer-default-export */ diff --git a/src/util/validators.js b/src/util/validators.js index bd0fd942..bd988b0e 100644 --- a/src/util/validators.js +++ b/src/util/validators.js @@ -5,10 +5,12 @@ // Redux Form expects and undefined value for a successful validation const VALID = undefined; -export const required = message => value => { - return value ? VALID : message; -}; +export const required = message => + value => { + return value ? VALID : message; + }; -export const maxLength = (message, maximumLength) => value => { - return !value || value.length <= maximumLength ? VALID : message; -}; +export const maxLength = (message, maximumLength) => + value => { + return !value || value.length <= maximumLength ? VALID : message; + };