mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 06:47:17 +10:00
Format JS with updated Prettier
This commit is contained in:
parent
bc886f2180
commit
e9c3dd284c
7 changed files with 93 additions and 75 deletions
|
|
@ -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 (
|
||||
<div className={css.thumbnail}>
|
||||
<img src={dataURL} alt={encodeURIComponent(i.file.name)} className={css.thumbnailImage} />
|
||||
<img
|
||||
src={dataURL}
|
||||
alt={encodeURIComponent(i.file.name)}
|
||||
className={css.thumbnailImage}
|
||||
/>
|
||||
{uploadingOverlay}
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -30,25 +30,28 @@ const placeBounds = place => {
|
|||
* @return {Promise<util.propTypes.place>} 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);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue