Skip to content

Commit 24cb747

Browse files
authored
Prod support (#147)
1 parent 43fc9b4 commit 24cb747

File tree

1 file changed

+132
-83
lines changed

1 file changed

+132
-83
lines changed

src/control/content/content.js

Lines changed: 132 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,18 @@ class Content extends React.Component {
274274
if (res.selectedButton.key == "yes") {
275275
let { data } = this.state;
276276
data.categories = data.categories || [];
277-
const mapViewDeeplinkId = data.categories && data.categories[index] && data.categories[index].mapViewDeeplinkId ? data.categories[index].mapViewDeeplinkId : null;
278-
const listViewDeeplinkId = data.categories && data.categories[index] && data.categories[index].listViewDeeplinkId ? data.categories[index].listViewDeeplinkId : null;
277+
const mapViewDeeplinkId =
278+
data.categories &&
279+
data.categories[index] &&
280+
data.categories[index].mapViewDeeplinkId
281+
? data.categories[index].mapViewDeeplinkId
282+
: null;
283+
const listViewDeeplinkId =
284+
data.categories &&
285+
data.categories[index] &&
286+
data.categories[index].listViewDeeplinkId
287+
? data.categories[index].listViewDeeplinkId
288+
: null;
279289
data.categories.splice(index, 1);
280290
this.setState({ data });
281291
this.handleSave();
@@ -294,59 +304,77 @@ class Content extends React.Component {
294304
*/
295305
handleCategoryRename(index, newName) {
296306
let { data } = this.state;
297-
const targetCategory = data && data.categories && data.categories[index] ? data.categories[index] : null;
307+
const targetCategory =
308+
data && data.categories && data.categories[index]
309+
? data.categories[index]
310+
: null;
298311
if (!targetCategory) return;
299312
data.categories[index].name = newName;
300313
this.setState({ data });
301314
this.handleSave();
302315

303316
const proceed = () => {
304-
Deeplink.getById(targetCategory.mapViewDeeplinkId, (err, mapViewDeeplink) => {
305-
if (!err && mapViewDeeplink) {
306-
mapViewDeeplink.name = `${newName} - Map View`;
307-
mapViewDeeplink.save();
308-
} else if (!err && !mapViewDeeplink) {
309-
const newMapViewDeeplink = new Deeplink({
310-
deeplinkId: `${targetCategory.id}-mapView`,
311-
name: `${newName} - Map View`,
317+
Deeplink.getById(
318+
targetCategory.mapViewDeeplinkId,
319+
(err, mapViewDeeplink) => {
320+
if (!err && mapViewDeeplink) {
321+
mapViewDeeplink.name = `${newName} - Map View`;
322+
mapViewDeeplink.save();
323+
} else if (!err && !mapViewDeeplink) {
324+
const newMapViewDeeplink = new Deeplink({
325+
deeplinkId: `${targetCategory.id}-mapView`,
326+
name: `${newName} - Map View`,
327+
deeplinkData: {
328+
id: targetCategory.id,
329+
view: "map",
330+
},
331+
});
332+
newMapViewDeeplink.save((err, newMapViewDeeplinkData) => {
333+
if (
334+
!err &&
335+
newMapViewDeeplinkData &&
336+
newMapViewDeeplinkData.deeplinkId
337+
) {
338+
data.categories[index].mapViewDeeplinkId =
339+
newMapViewDeeplinkData.deeplinkId;
340+
}
341+
this.setState({ data });
342+
this.handleSave();
343+
});
344+
}
345+
}
346+
);
347+
};
348+
349+
Deeplink.getById(
350+
targetCategory.listViewDeeplinkId,
351+
(err, listViewDeeplink) => {
352+
if (!err && listViewDeeplink) {
353+
listViewDeeplink.name = `${newName} - List View`;
354+
listViewDeeplink.save(() => proceed());
355+
} else if (!err && !listViewDeeplink && targetCategory.id) {
356+
const newListViewDeeplink = new Deeplink({
357+
deeplinkId: `${targetCategory.id}-listView`,
358+
name: `${newName} - List View`,
312359
deeplinkData: {
313360
id: targetCategory.id,
314-
view: 'map'
315-
}
361+
view: "list",
362+
},
316363
});
317-
newMapViewDeeplink.save((err, newMapViewDeeplinkData) => {
318-
if (!err && newMapViewDeeplinkData && newMapViewDeeplinkData.deeplinkId) {
319-
data.categories[index].mapViewDeeplinkId = newMapViewDeeplinkData.deeplinkId;
364+
newListViewDeeplink.save((err, newListViewDeeplinkData) => {
365+
if (
366+
!err &&
367+
newListViewDeeplinkData &&
368+
newListViewDeeplinkData.deeplinkId
369+
) {
370+
data.categories[index].listViewDeeplinkId =
371+
newListViewDeeplinkData.deeplinkId;
320372
}
321-
this.setState({ data });
322-
this.handleSave();
373+
proceed();
323374
});
324375
}
325-
});
326-
}
327-
328-
Deeplink.getById(targetCategory.listViewDeeplinkId, (err, listViewDeeplink) => {
329-
if (!err && listViewDeeplink) {
330-
listViewDeeplink.name = `${newName} - List View`;
331-
listViewDeeplink.save(() => proceed());
332-
} else if (!err && !listViewDeeplink && targetCategory.id) {
333-
const newListViewDeeplink = new Deeplink({
334-
deeplinkId: `${targetCategory.id}-listView`,
335-
name: `${newName} - List View`,
336-
deeplinkData: {
337-
id: targetCategory.id,
338-
view: 'list'
339-
}
340-
});
341-
newListViewDeeplink.save((err, newListViewDeeplinkData) => {
342-
if (!err && newListViewDeeplinkData && newListViewDeeplinkData.deeplinkId) {
343-
data.categories[index].listViewDeeplinkId = newListViewDeeplinkData.deeplinkId;
344-
}
345-
proceed();
346-
});
347376
}
348-
});
349-
377+
);
350378
}
351379

352380
/**
@@ -386,11 +414,11 @@ class Content extends React.Component {
386414

387415
const locationDeeplink = new Deeplink({
388416
deeplinkId: result.id,
389-
name: location.title ? location.title : '',
417+
name: location.title ? location.title : "",
390418
deeplinkData: { id: result.id },
391-
imageUrl: location.image ? location.image : null
419+
imageUrl: location.image ? location.image : null,
392420
});
393-
421+
394422
locationDeeplink.save();
395423

396424
this.setState({ data }, () => {
@@ -438,15 +466,15 @@ class Content extends React.Component {
438466

439467
Deeplink.getById(location.id, (err, locationDeeplink) => {
440468
if (!err && locationDeeplink) {
441-
locationDeeplink.name = location.title ? location.title : '';
469+
locationDeeplink.name = location.title ? location.title : "";
442470
locationDeeplink.imageUrl = location.image ? location.image : null;
443471
locationDeeplink.save();
444472
} else if (!err && !locationDeeplink) {
445473
const locationDeeplink = new Deeplink({
446474
deeplinkId: location.id,
447-
name: location.title ? location.title : '',
475+
name: location.title ? location.title : "",
448476
deeplinkData: { id: location.id },
449-
imageUrl: location.image ? location.image : null
477+
imageUrl: location.image ? location.image : null,
450478
});
451479
locationDeeplink.save();
452480
}
@@ -463,8 +491,17 @@ class Content extends React.Component {
463491
*/
464492
onMultipleLocationSubmit(locations) {
465493
locations = locations.filter((location) => typeof location === "object");
466-
let locationsForInsert = locations.filter((location) => !location.id);
467-
let locationsForUpdate = locations.filter((location) => location.id);
494+
let locationsForUpdate = [];
495+
let locationsForInsert = [];
496+
let ids = this.state.data.itemsOrder;
497+
for (let i = 0; i < locations.length; i++) {
498+
let loc = locations[i];
499+
if (ids.some((id) => id == loc.id)) {
500+
locationsForUpdate.push(loc);
501+
} else {
502+
locationsForInsert.push(loc);
503+
}
504+
}
468505

469506
this.setState({
470507
totalInserted: locationsForInsert.length,
@@ -484,26 +521,34 @@ class Content extends React.Component {
484521
} else if (result && result.data && result.data.length) {
485522
const newDataCount = result.data.length;
486523
for (let skip = 0; skip < newDataCount; skip += 50) {
487-
buildfire.datastore.search({filter: {}, skip, limit: 50}, 'places-list', (err, innerResult) => {
488-
if (err) return;
489-
innerResult.forEach(item => {
490-
Deeplink.getById(item.id, (err, locationDeeplink) => {
491-
if (!err && locationDeeplink) {
492-
locationDeeplink.name = item.data.title ? item.data.title : '';
493-
locationDeeplink.imageUrl = item.data.image ? item.data.image : null;
494-
locationDeeplink.save();
495-
} else {
496-
const newLocationDeeplink = new Deeplink({
497-
deeplinkId: item.id,
498-
name: item.data.title ? item.data.title : '',
499-
deeplinkData: { id: item.id },
500-
imageUrl: item.data.image ? item.data.image : null
501-
});
502-
newLocationDeeplink.save();
503-
}
524+
buildfire.datastore.search(
525+
{ filter: {}, skip, limit: 50 },
526+
"places-list",
527+
(err, innerResult) => {
528+
if (err) return;
529+
innerResult.forEach((item) => {
530+
Deeplink.getById(item.id, (err, locationDeeplink) => {
531+
if (!err && locationDeeplink) {
532+
locationDeeplink.name = item.data.title
533+
? item.data.title
534+
: "";
535+
locationDeeplink.imageUrl = item.data.image
536+
? item.data.image
537+
: null;
538+
locationDeeplink.save();
539+
} else {
540+
const newLocationDeeplink = new Deeplink({
541+
deeplinkId: item.id,
542+
name: item.data.title ? item.data.title : "",
543+
deeplinkData: { id: item.id },
544+
imageUrl: item.data.image ? item.data.image : null,
545+
});
546+
newLocationDeeplink.save();
547+
}
548+
});
504549
});
505-
});
506-
});
550+
}
551+
);
507552
}
508553
}
509554
}
@@ -521,8 +566,12 @@ class Content extends React.Component {
521566
});
522567
Deeplink.getById(location.id, (err, locationDeeplink) => {
523568
if (!err && locationDeeplink) {
524-
locationDeeplink.name = location.data.title ? location.data.title : '';
525-
locationDeeplink.imageUrl = location.data.image ? location.data.image : null;
569+
locationDeeplink.name = location.data.title
570+
? location.data.title
571+
: "";
572+
locationDeeplink.imageUrl = location.data.image
573+
? location.data.image
574+
: null;
526575
locationDeeplink.save();
527576
}
528577
});
@@ -559,45 +608,45 @@ class Content extends React.Component {
559608
name: `${categoryName} - List View`,
560609
deeplinkData: {
561610
id,
562-
view: 'list'
563-
}
611+
view: "list",
612+
},
564613
});
565614

566615
const mapViewDeeplink = new Deeplink({
567616
deeplinkId: `${id}-mapView`,
568617
name: `${categoryName} - Map View`,
569618
deeplinkData: {
570619
id,
571-
view: 'map'
572-
}
620+
view: "map",
621+
},
573622
});
574623

575624
listViewDeeplink.save((err, listViewDeeplinkData) => {
576625
const showError = () => {
577626
buildfire.dialog.alert({
578-
message: 'Error while adding category.'
627+
message: "Error while adding category.",
579628
});
580-
}
581-
if (err || !listViewDeeplinkData || !listViewDeeplinkData.deeplinkId) return showError();
629+
};
630+
if (err || !listViewDeeplinkData || !listViewDeeplinkData.deeplinkId)
631+
return showError();
582632
mapViewDeeplink.save((err, mapViewDeeplinkData) => {
583-
if (err || !mapViewDeeplinkData || !mapViewDeeplinkData.deeplinkId) return showError();
633+
if (err || !mapViewDeeplinkData || !mapViewDeeplinkData.deeplinkId)
634+
return showError();
584635

585636
const category = {
586637
id,
587638
name: categoryName,
588639
mapViewDeeplinkId: mapViewDeeplinkData.deeplinkId,
589-
listViewDeeplinkId: listViewDeeplinkData.deeplinkId
640+
listViewDeeplinkId: listViewDeeplinkData.deeplinkId,
590641
};
591-
642+
592643
const { data } = this.state;
593644
data.categories = data.categories || [];
594645
data.categories.push(category);
595646
this.setState({ data });
596647
this.handleSave();
597-
598648
});
599649
});
600-
601650
}
602651

603652
onAddLocation() {

0 commit comments

Comments
 (0)