@mjhls/mjh-framework 1.0.939-segment-test-v6 → 1.0.939-segment-test-v8

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.
package/dist/cjs/View.js CHANGED
@@ -461,9 +461,7 @@ var Recommended = function Recommended(props) {
461
461
  client = props.client,
462
462
  _props$index = props.index,
463
463
  index = _props$index === undefined ? 0 : _props$index,
464
- cpModificationRequired = props.cpModificationRequired,
465
- segmentData = props.segmentData,
466
- setSegmentData = props.setSegmentData;
464
+ cpModificationRequired = props.cpModificationRequired;
467
465
 
468
466
  var _useState = React.useState(false),
469
467
  _useState2 = slicedToArray._slicedToArray(_useState, 2),
@@ -509,48 +507,29 @@ var Recommended = function Recommended(props) {
509
507
  // get users traits
510
508
  var getSegmentProfile = function () {
511
509
  var _ref = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee() {
512
- var data, anonymousId, response, addTaxonomyName, favoriteCategories, articlesQuery, videosQuery, podcastQuery, params, _ref2, _ref3, _articles, videos, podcasts;
510
+ var anonymousId, response, data, addTaxonomyName, fetchWithTimeout, favoriteCategories, articlesQuery, videosQuery, podcastQuery, params, _ref2, _ref3, _articles, videos, podcasts;
513
511
 
514
512
  return asyncToGenerator.regenerator.wrap(function _callee$(_context) {
515
513
  while (1) {
516
514
  switch (_context.prev = _context.next) {
517
515
  case 0:
518
- data = void 0;
519
-
520
- if (segmentData) {
521
- _context.next = 12;
522
- break;
523
- }
524
-
525
516
  anonymousId = analytics.user().anonymousId();
526
- _context.next = 5;
517
+ _context.next = 3;
527
518
  return fetch('/api/getSegmentProfile', {
528
519
  method: 'POST',
529
520
  body: stringify._JSON$stringify({ anonymousId: anonymousId })
530
521
  });
531
522
 
532
- case 5:
523
+ case 3:
533
524
  response = _context.sent;
534
- _context.next = 8;
525
+ _context.next = 6;
535
526
  return response.json();
536
527
 
537
- case 8:
528
+ case 6:
538
529
  data = _context.sent;
539
530
 
540
- if (data && data.traits && data.traits.favorite_article_category) {
541
- setSegmentData(data);
542
- } else {
543
- setLoaded('failed');
544
- }
545
- _context.next = 13;
546
- break;
547
-
548
- case 12:
549
- data = segmentData;
550
-
551
- case 13:
552
531
  if (!(data && data.traits && data.traits.favorite_article_category)) {
553
- _context.next = 28;
532
+ _context.next = 26;
554
533
  break;
555
534
  }
556
535
 
@@ -572,6 +551,21 @@ var Recommended = function Recommended(props) {
572
551
  return query;
573
552
  };
574
553
 
554
+ fetchWithTimeout = function fetchWithTimeout(timeout, fn) {
555
+
556
+ return new asyncToGenerator._Promise(function (resolve, reject) {
557
+ // start timeout
558
+ var timeoutID = setTimeout(function () {
559
+ return resolve([]);
560
+ }, timeout);
561
+ // start calculation
562
+ fn().then(function (result) {
563
+ clearTimeout(timeoutID);
564
+ resolve(result);
565
+ });
566
+ });
567
+ };
568
+
575
569
  favoriteCategories = JSON.parse(data.traits.favorite_article_category);
576
570
  // grab 3 articles from sanity different from the one currently being read
577
571
 
@@ -581,16 +575,23 @@ var Recommended = function Recommended(props) {
581
575
  params = {
582
576
  id: article._id
583
577
  };
584
- _context.next = 22;
585
- return asyncToGenerator._Promise.all([client.fetch(articlesQuery, params), client.fetch(videosQuery, params), client.fetch(podcastQuery, params)]);
586
-
587
- case 22:
578
+ _context.next = 17;
579
+ return asyncToGenerator._Promise.all([fetchWithTimeout(1000, function () {
580
+ return client.fetch(articlesQuery, params);
581
+ }), fetchWithTimeout(600, function () {
582
+ return client.fetch(videosQuery, params);
583
+ }), fetchWithTimeout(600, function () {
584
+ return client.fetch(podcastQuery, params);
585
+ })]);
586
+
587
+ case 17:
588
588
  _ref2 = _context.sent;
589
589
  _ref3 = slicedToArray._slicedToArray(_ref2, 3);
590
590
  _articles = _ref3[0];
591
591
  videos = _ref3[1];
592
592
  podcasts = _ref3[2];
593
593
 
594
+ if (_articles.length === 0) setLoaded('failed');
594
595
  if (_articles) {
595
596
  if (videos[0] && _articles[2]) {
596
597
  _articles[2] = videos[0];
@@ -603,8 +604,13 @@ var Recommended = function Recommended(props) {
603
604
  }
604
605
  setArticles(_articles);
605
606
  }
607
+ _context.next = 27;
608
+ break;
609
+
610
+ case 26:
611
+ setLoaded('failed');
606
612
 
607
- case 28:
613
+ case 27:
608
614
  case 'end':
609
615
  return _context.stop();
610
616
  }
@@ -931,11 +937,7 @@ var Article = React__default['default'].memo(React.forwardRef(function (props, r
931
937
  _props$downloadCitati = props.downloadCitation,
932
938
  downloadCitation = _props$downloadCitati === undefined ? false : _props$downloadCitati,
933
939
  _props$useSegmentReco = props.useSegmentRecommendedArticles,
934
- useSegmentRecommendedArticles = _props$useSegmentReco === undefined ? false : _props$useSegmentReco,
935
- _props$segmentData = props.segmentData,
936
- segmentData = _props$segmentData === undefined ? null : _props$segmentData,
937
- _props$setSegmentData = props.setSegmentData,
938
- setSegmentData = _props$setSegmentData === undefined ? function () {} : _props$setSegmentData;
940
+ useSegmentRecommendedArticles = _props$useSegmentReco === undefined ? false : _props$useSegmentReco;
939
941
  var sliderData = props.sliderData;
940
942
 
941
943
 
@@ -1170,7 +1172,7 @@ var Article = React__default['default'].memo(React.forwardRef(function (props, r
1170
1172
  return React__default['default'].createElement(
1171
1173
  'div',
1172
1174
  null,
1173
- useSegmentRecommendedArticles ? React__default['default'].createElement(Recommended, { segmentData: segmentData, setSegmentData: setSegmentData, client: client, article: article, index: props.index, Settings: props.Settings, showRelatedArticleFallbackImage: props.showRelatedArticleFallbackImage, cpModificationRequired: cpModificationRequired }) : React__default['default'].createElement(
1175
+ useSegmentRecommendedArticles ? React__default['default'].createElement(Recommended, { client: client, article: article, index: props.index, Settings: props.Settings, showRelatedArticleFallbackImage: props.showRelatedArticleFallbackImage, cpModificationRequired: cpModificationRequired }) : React__default['default'].createElement(
1174
1176
  'section',
1175
1177
  { id: 'related-content-section', className: 'my-1' },
1176
1178
  (article.relatedArticle || RelevantTopics()) && React__default['default'].createElement(
@@ -1869,11 +1871,6 @@ var ArticleQueue = function ArticleQueue(props) {
1869
1871
  active = _useState6[0],
1870
1872
  setActive = _useState6[1];
1871
1873
 
1872
- var _useState7 = React.useState(null),
1873
- _useState8 = slicedToArray._slicedToArray(_useState7, 2),
1874
- segmentData = _useState8[0],
1875
- setSegmentData = _useState8[1];
1876
-
1877
1874
  var refreshAD = function refreshAD(path) {
1878
1875
  var activeArticle = queueData.find(function (item) {
1879
1876
  return item.url.current === path;
@@ -2095,9 +2092,7 @@ var ArticleQueue = function ArticleQueue(props) {
2095
2092
  // Passing queueData to check for single article
2096
2093
  , queueData: queueData,
2097
2094
  showRelatedArticles: showRelatedArticles,
2098
- index: index,
2099
- segmentData: segmentData,
2100
- setSegmentData: setSegmentData
2095
+ index: index
2101
2096
  }))
2102
2097
  );
2103
2098
  })
package/dist/esm/View.js CHANGED
@@ -450,9 +450,7 @@ var Recommended = function Recommended(props) {
450
450
  client = props.client,
451
451
  _props$index = props.index,
452
452
  index = _props$index === undefined ? 0 : _props$index,
453
- cpModificationRequired = props.cpModificationRequired,
454
- segmentData = props.segmentData,
455
- setSegmentData = props.setSegmentData;
453
+ cpModificationRequired = props.cpModificationRequired;
456
454
 
457
455
  var _useState = useState(false),
458
456
  _useState2 = _slicedToArray(_useState, 2),
@@ -498,48 +496,29 @@ var Recommended = function Recommended(props) {
498
496
  // get users traits
499
497
  var getSegmentProfile = function () {
500
498
  var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
501
- var data, anonymousId, response, addTaxonomyName, favoriteCategories, articlesQuery, videosQuery, podcastQuery, params, _ref2, _ref3, _articles, videos, podcasts;
499
+ var anonymousId, response, data, addTaxonomyName, fetchWithTimeout, favoriteCategories, articlesQuery, videosQuery, podcastQuery, params, _ref2, _ref3, _articles, videos, podcasts;
502
500
 
503
501
  return regenerator.wrap(function _callee$(_context) {
504
502
  while (1) {
505
503
  switch (_context.prev = _context.next) {
506
504
  case 0:
507
- data = void 0;
508
-
509
- if (segmentData) {
510
- _context.next = 12;
511
- break;
512
- }
513
-
514
505
  anonymousId = analytics.user().anonymousId();
515
- _context.next = 5;
506
+ _context.next = 3;
516
507
  return fetch('/api/getSegmentProfile', {
517
508
  method: 'POST',
518
509
  body: _JSON$stringify({ anonymousId: anonymousId })
519
510
  });
520
511
 
521
- case 5:
512
+ case 3:
522
513
  response = _context.sent;
523
- _context.next = 8;
514
+ _context.next = 6;
524
515
  return response.json();
525
516
 
526
- case 8:
517
+ case 6:
527
518
  data = _context.sent;
528
519
 
529
- if (data && data.traits && data.traits.favorite_article_category) {
530
- setSegmentData(data);
531
- } else {
532
- setLoaded('failed');
533
- }
534
- _context.next = 13;
535
- break;
536
-
537
- case 12:
538
- data = segmentData;
539
-
540
- case 13:
541
520
  if (!(data && data.traits && data.traits.favorite_article_category)) {
542
- _context.next = 28;
521
+ _context.next = 26;
543
522
  break;
544
523
  }
545
524
 
@@ -561,6 +540,21 @@ var Recommended = function Recommended(props) {
561
540
  return query;
562
541
  };
563
542
 
543
+ fetchWithTimeout = function fetchWithTimeout(timeout, fn) {
544
+
545
+ return new _Promise(function (resolve, reject) {
546
+ // start timeout
547
+ var timeoutID = setTimeout(function () {
548
+ return resolve([]);
549
+ }, timeout);
550
+ // start calculation
551
+ fn().then(function (result) {
552
+ clearTimeout(timeoutID);
553
+ resolve(result);
554
+ });
555
+ });
556
+ };
557
+
564
558
  favoriteCategories = JSON.parse(data.traits.favorite_article_category);
565
559
  // grab 3 articles from sanity different from the one currently being read
566
560
 
@@ -570,16 +564,23 @@ var Recommended = function Recommended(props) {
570
564
  params = {
571
565
  id: article._id
572
566
  };
573
- _context.next = 22;
574
- return _Promise.all([client.fetch(articlesQuery, params), client.fetch(videosQuery, params), client.fetch(podcastQuery, params)]);
575
-
576
- case 22:
567
+ _context.next = 17;
568
+ return _Promise.all([fetchWithTimeout(1000, function () {
569
+ return client.fetch(articlesQuery, params);
570
+ }), fetchWithTimeout(600, function () {
571
+ return client.fetch(videosQuery, params);
572
+ }), fetchWithTimeout(600, function () {
573
+ return client.fetch(podcastQuery, params);
574
+ })]);
575
+
576
+ case 17:
577
577
  _ref2 = _context.sent;
578
578
  _ref3 = _slicedToArray(_ref2, 3);
579
579
  _articles = _ref3[0];
580
580
  videos = _ref3[1];
581
581
  podcasts = _ref3[2];
582
582
 
583
+ if (_articles.length === 0) setLoaded('failed');
583
584
  if (_articles) {
584
585
  if (videos[0] && _articles[2]) {
585
586
  _articles[2] = videos[0];
@@ -592,8 +593,13 @@ var Recommended = function Recommended(props) {
592
593
  }
593
594
  setArticles(_articles);
594
595
  }
596
+ _context.next = 27;
597
+ break;
598
+
599
+ case 26:
600
+ setLoaded('failed');
595
601
 
596
- case 28:
602
+ case 27:
597
603
  case 'end':
598
604
  return _context.stop();
599
605
  }
@@ -920,11 +926,7 @@ var Article = React__default.memo(forwardRef(function (props, ref) {
920
926
  _props$downloadCitati = props.downloadCitation,
921
927
  downloadCitation = _props$downloadCitati === undefined ? false : _props$downloadCitati,
922
928
  _props$useSegmentReco = props.useSegmentRecommendedArticles,
923
- useSegmentRecommendedArticles = _props$useSegmentReco === undefined ? false : _props$useSegmentReco,
924
- _props$segmentData = props.segmentData,
925
- segmentData = _props$segmentData === undefined ? null : _props$segmentData,
926
- _props$setSegmentData = props.setSegmentData,
927
- setSegmentData = _props$setSegmentData === undefined ? function () {} : _props$setSegmentData;
929
+ useSegmentRecommendedArticles = _props$useSegmentReco === undefined ? false : _props$useSegmentReco;
928
930
  var sliderData = props.sliderData;
929
931
 
930
932
 
@@ -1159,7 +1161,7 @@ var Article = React__default.memo(forwardRef(function (props, ref) {
1159
1161
  return React__default.createElement(
1160
1162
  'div',
1161
1163
  null,
1162
- useSegmentRecommendedArticles ? React__default.createElement(Recommended, { segmentData: segmentData, setSegmentData: setSegmentData, client: client, article: article, index: props.index, Settings: props.Settings, showRelatedArticleFallbackImage: props.showRelatedArticleFallbackImage, cpModificationRequired: cpModificationRequired }) : React__default.createElement(
1164
+ useSegmentRecommendedArticles ? React__default.createElement(Recommended, { client: client, article: article, index: props.index, Settings: props.Settings, showRelatedArticleFallbackImage: props.showRelatedArticleFallbackImage, cpModificationRequired: cpModificationRequired }) : React__default.createElement(
1163
1165
  'section',
1164
1166
  { id: 'related-content-section', className: 'my-1' },
1165
1167
  (article.relatedArticle || RelevantTopics()) && React__default.createElement(
@@ -1858,11 +1860,6 @@ var ArticleQueue = function ArticleQueue(props) {
1858
1860
  active = _useState6[0],
1859
1861
  setActive = _useState6[1];
1860
1862
 
1861
- var _useState7 = useState(null),
1862
- _useState8 = _slicedToArray(_useState7, 2),
1863
- segmentData = _useState8[0],
1864
- setSegmentData = _useState8[1];
1865
-
1866
1863
  var refreshAD = function refreshAD(path) {
1867
1864
  var activeArticle = queueData.find(function (item) {
1868
1865
  return item.url.current === path;
@@ -2084,9 +2081,7 @@ var ArticleQueue = function ArticleQueue(props) {
2084
2081
  // Passing queueData to check for single article
2085
2082
  , queueData: queueData,
2086
2083
  showRelatedArticles: showRelatedArticles,
2087
- index: index,
2088
- segmentData: segmentData,
2089
- setSegmentData: setSegmentData
2084
+ index: index
2090
2085
  }))
2091
2086
  );
2092
2087
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mjhls/mjh-framework",
3
- "version": "1.0.939-segment-test-v6",
3
+ "version": "1.0.939-segment-test-v8",
4
4
  "description": "Foundation Framework",
5
5
  "author": "mjh-framework",
6
6
  "license": "MIT",