muba-posting 5.0.4 → 5.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/Posting.js +7 -2
  2. package/Publish4.js +55 -44
  3. package/package.json +1 -1
package/Posting.js CHANGED
@@ -36,6 +36,7 @@ const MAX_PICTURES = { method: 'GET', url: '/controller/posting/max-pictures' };
36
36
  const COUNTRY_PHONE = { method: 'GET', url: '/controller/countries/{countryCode}/phones' };
37
37
  const LOAD_PENDING_CREATED = { method: 'GET', url: '/controller/ads/pending-created/posting' };
38
38
  const PAYMENT_ONLINE_ACTIVE = { method: 'GET', url: '/controller/payments-online/{countryCode}/active' };
39
+ const UPLOADED_FILES_KEY = 'uploadedFiles';
39
40
 
40
41
  export default class Posting extends React.Component {
41
42
  constructor(props) {
@@ -307,8 +308,12 @@ export default class Posting extends React.Component {
307
308
  }
308
309
  const response = await this.props.request(this, CREATE_AD, ad);
309
310
  if (response.httpStatus === 200) {
311
+ let images = this.state.postingAd.images;
312
+ if (response[UPLOADED_FILES_KEY]) {
313
+ images = response[UPLOADED_FILES_KEY];
314
+ }
310
315
  await this.setState({
311
- postingAd: { ...this.state.postingAd, id: response.id }
316
+ postingAd: { ...this.state.postingAd, images: images, id: response.id }
312
317
  })
313
318
  }
314
319
  }
@@ -402,7 +407,7 @@ export default class Posting extends React.Component {
402
407
  this._goToPage(Views.PREVIEW, null, response);
403
408
 
404
409
  const paymentOnlineActive = await this.props.request(this, PAYMENT_ONLINE_ACTIVE, { regionId: this.state.postingAd.region });
405
- if (!this.businessId && paymentOnlineActive.value === 'true') {
410
+ if (!this.state.businessId && paymentOnlineActive.value === 'true') {
406
411
  this._goToPage(Views.PAYMENT_ONLINE);
407
412
  }
408
413
  }
package/Publish4.js CHANGED
@@ -97,6 +97,10 @@ export default class Publish4 extends React.Component {
97
97
  });
98
98
  }
99
99
 
100
+ async imageExists(imageUrl) {
101
+ return fetch(imageUrl).then(response => response.status === 200);
102
+ }
103
+
100
104
  async deleteImage(itemId, index) {
101
105
  if (itemId) {
102
106
  if (!this.props.postingAd.deletedFiles) {
@@ -106,11 +110,14 @@ export default class Publish4 extends React.Component {
106
110
  }
107
111
 
108
112
  let imagesArray = [...this.state.images];
113
+ let imageSize = [...this.state.imageSize];
109
114
  imagesArray.splice(index, 1)
115
+ imageSize.splice(index, 1)
110
116
 
111
117
  await this.setState({
112
118
  allPhotosSelected: false,
113
- images: imagesArray
119
+ images: imagesArray,
120
+ imageSize: imageSize
114
121
  });
115
122
 
116
123
  if (this.state.images.length >= 1) {
@@ -179,56 +186,60 @@ export default class Publish4 extends React.Component {
179
186
  }, 500);
180
187
  }
181
188
 
182
- calculateImageSize = (image) => {
183
- let imageSize = this.state.imageSize;
184
- Image.getSize(image.uri, (width, height) => {
185
- if (this.state.containerWidth !== 0 && this.state.containerHeight !== 0) {
186
- const containerRatio = this.state.containerWidth / this.state.containerHeight;
187
- const imageRatio = width / height;
189
+ calculateImageSize = async (image) => {
190
+ if (!image.uri.startsWith('https://') || await this.imageExists(image.uri)) {
191
+ let imageSize = this.state.imageSize;
192
+ Image.getSize(image.uri, (width, height) => {
193
+ if (this.state.containerWidth !== 0 && this.state.containerHeight !== 0) {
194
+ const containerRatio = this.state.containerWidth / this.state.containerHeight;
195
+ const imageRatio = width / height;
188
196
 
189
- let finalWidth;
190
- let finalHeight;
191
- if (imageRatio > containerRatio) {
192
- if (width > this.state.containerWidth) {
193
- finalWidth = this.state.containerWidth;
194
- } else {
195
- finalWidth = width;
196
- }
197
- finalHeight = height * (finalWidth / width);
198
- } else if (imageRatio < containerRatio) {
199
- if (height > this.state.containerHeight) {
200
- finalHeight = this.state.containerHeight;
197
+ let finalWidth;
198
+ let finalHeight;
199
+ if (imageRatio > containerRatio) {
200
+ if (width > this.state.containerWidth) {
201
+ finalWidth = this.state.containerWidth;
202
+ } else {
203
+ finalWidth = width;
204
+ }
205
+ finalHeight = height * (finalWidth / width);
206
+ } else if (imageRatio < containerRatio) {
207
+ if (height > this.state.containerHeight) {
208
+ finalHeight = this.state.containerHeight;
209
+ } else {
210
+ finalHeight = height;
211
+ }
212
+ finalWidth = width * (finalHeight / height);
201
213
  } else {
202
- finalHeight = height;
214
+ if (width > this.state.containerWidth) {
215
+ finalWidth = this.state.containerWidth;
216
+ finalHeight = this.state.containerHeight;
217
+ } else {
218
+ finalWidth = width;
219
+ finalHeight = height;
220
+ }
203
221
  }
204
- finalWidth = width * (finalHeight / height);
222
+ imageSize.push({
223
+ width: finalWidth,
224
+ height: finalHeight,
225
+ marginVertical: (this.state.containerHeight - finalHeight) / 2,
226
+ marginHorizontal: (this.state.containerWidth - finalWidth) / 2
227
+ });
205
228
  } else {
206
- if (width > this.state.containerWidth) {
207
- finalWidth = this.state.containerWidth;
208
- finalHeight = this.state.containerHeight;
209
- } else {
210
- finalWidth = width;
211
- finalHeight = height;
212
- }
229
+ imageSize.push({
230
+ width: '100%',
231
+ height: '100%',
232
+ marginVertical: 0,
233
+ marginHorizontal: 0
234
+ })
213
235
  }
214
- imageSize.push({
215
- width: finalWidth,
216
- height: finalHeight,
217
- marginVertical: (this.state.containerHeight - finalHeight) / 2,
218
- marginHorizontal: (this.state.containerWidth - finalWidth) / 2
236
+ this.setState({
237
+ imageSize: imageSize
219
238
  });
220
- } else {
221
- imageSize.push({
222
- width: '100%',
223
- height: '100%',
224
- marginVertical: 0,
225
- marginHorizontal: 0
226
- })
227
- }
228
- this.setState({
229
- imageSize: imageSize
230
239
  });
231
- });
240
+ } else {
241
+ setTimeout(() => this.calculateImageSize(image), 500);
242
+ }
232
243
  }
233
244
 
234
245
  render() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muba-posting",
3
- "version": "5.0.4",
3
+ "version": "5.0.6",
4
4
  "description": "Posting",
5
5
  "main": "Posting.js",
6
6
  "scripts": {