@mjhls/mjh-framework 1.0.939-segment-test-v12 → 1.0.939

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
@@ -473,11 +473,10 @@ var Recommended = function Recommended(props) {
473
473
  articles = _useState4[0],
474
474
  setArticles = _useState4[1];
475
475
 
476
- var _useState5 = React.useState('loading'),
476
+ var _useState5 = React.useState(false),
477
477
  _useState6 = slicedToArray._slicedToArray(_useState5, 2),
478
478
  loaded = _useState6[0],
479
- setLoaded = _useState6[1]; //loading, loaded, failed
480
-
479
+ setLoaded = _useState6[1];
481
480
 
482
481
  var starting = index * 5;
483
482
  var contentMapping = {
@@ -503,33 +502,32 @@ var Recommended = function Recommended(props) {
503
502
  categories: stringify._JSON$stringify(mainCategories)
504
503
  });
505
504
  }
506
-
505
+ var anonymousId = analytics.user().anonymousId();
507
506
  // get users traits
508
507
  var getSegmentProfile = function () {
509
508
  var _ref = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee() {
510
- var anonymousId, response, data, addTaxonomyName, favoriteCategories, articlesCategory, videosCategory, podcastCategory, taxonomyCategories, taxonomies, articlesQuery, videosQuery, podcastQuery, params, _ref2, _ref3, _articles, videos, podcasts;
509
+ var response, data, addTaxonomyName, favoriteCategories, articlesQuery, videosQuery, podcastQuery, params, _ref2, _ref3, _articles, videos, podcasts;
511
510
 
512
511
  return asyncToGenerator.regenerator.wrap(function _callee$(_context) {
513
512
  while (1) {
514
513
  switch (_context.prev = _context.next) {
515
514
  case 0:
516
- anonymousId = analytics.user().anonymousId();
517
- _context.next = 3;
515
+ _context.next = 2;
518
516
  return fetch('/api/getSegmentProfile', {
519
517
  method: 'POST',
520
518
  body: stringify._JSON$stringify({ anonymousId: anonymousId })
521
519
  });
522
520
 
523
- case 3:
521
+ case 2:
524
522
  response = _context.sent;
525
- _context.next = 6;
523
+ _context.next = 5;
526
524
  return response.json();
527
525
 
528
- case 6:
526
+ case 5:
529
527
  data = _context.sent;
530
528
 
531
529
  if (!(data && data.traits && data.traits.favorite_article_category)) {
532
- _context.next = 40;
530
+ _context.next = 21;
533
531
  break;
534
532
  }
535
533
 
@@ -548,62 +546,30 @@ var Recommended = function Recommended(props) {
548
546
 
549
547
  query = query + ' )';
550
548
 
549
+ console.log(query);
550
+
551
551
  return query;
552
552
  };
553
553
 
554
554
  favoriteCategories = JSON.parse(data.traits.favorite_article_category);
555
-
556
- //grab contentCategory ID
557
-
558
- _context.next = 12;
559
- return client.fetch("*[_type == 'contentCategory' && name == 'Articles'][0]{_id}");
560
-
561
- case 12:
562
- articlesCategory = _context.sent;
563
- _context.next = 15;
564
- return client.fetch("*[_type == 'contentCategory' && name == 'Videos'][0]{_id}");
565
-
566
- case 15:
567
- videosCategory = _context.sent;
568
- _context.next = 18;
569
- return client.fetch("*[_type == 'contentCategory' && name == 'Podcasts'][0]{_id}");
570
-
571
- case 18:
572
- podcastCategory = _context.sent;
573
- _context.next = 21;
574
- return client.fetch('*[_type == \'taxonomy\' ' + addTaxonomyName(favoriteCategories) + ']');
575
-
576
- case 21:
577
- taxonomyCategories = _context.sent;
578
- taxonomies = '';
579
-
580
- taxonomyCategories.forEach(function (taxonomy, index) {
581
- if (index === 0) {
582
- taxonomies = taxonomies + (' && ( references(\'' + taxonomy._id + '\')');
583
- } else {
584
- taxonomies = taxonomies + (' || references(\'' + taxonomy._id + '\')');
585
- }
586
- });
587
- taxonomies = taxonomies + ' )';
588
-
589
555
  // grab 3 articles from sanity different from the one currently being read
590
- articlesQuery = '*[_type == \'article\'\n && !(_id in path("drafts.**"))\n && defined(title)\n && defined(url)\n && is_visible == true \n && passwordLock != true\n && references(\'' + articlesCategory._id + '\')\n ' + taxonomies + '\n && defined(published)\n && _id != $id\n && dateTime(published) <= dateTime(now())] | order(published desc) [' + starting + '...' + (starting + 5) + '] {\n ...,\n title,\n thumbnail,\n url,\n contentCategory->,\n published,\n }';
591
- videosQuery = '*[_type == \'article\'\n && !(_id in path("drafts.**"))\n && defined(title)\n && defined(url)\n && is_visible == true \n && passwordLock != true\n && references(\'' + videosCategory._id + '\')\n ' + taxonomies + '\n && defined(published)\n && _id != $id\n && dateTime(published) <= dateTime(now())] | order(published desc) [' + starting + '...' + (starting + 1) + '] {\n ...,\n title,\n thumbnail,\n url,\n contentCategory->,\n published,\n }';
592
- podcastQuery = '*[_type == \'article\'\n && !(_id in path("drafts.**"))\n && defined(title)\n && defined(url)\n && is_visible == true \n && passwordLock != true\n && references(\'' + podcastCategory._id + '\')\n ' + taxonomies + '\n && defined(published)\n && _id != $id\n && dateTime(published) <= dateTime(now())] | order(published desc) [' + starting + '...' + (starting + 2) + '] {\n ...,\n title,\n thumbnail,\n url,\n contentCategory->,\n published,\n }';
556
+
557
+ articlesQuery = '*[_type == \'article\'\n && !(_id in path("drafts.**"))\n && defined(title)\n && defined(url)\n && is_visible == true \n && passwordLock != true\n && references(*[_type == \'contentCategory\' && name == \'Articles\']._id)\n && references(*[_type == \'taxonomy\' ' + addTaxonomyName(favoriteCategories) + ']._id)\n && defined(published)\n && _id != $id\n && dateTime(published) <= dateTime(now())] | order(published desc) [' + starting + '...' + (starting + 5) + '] {\n ...,\n title,\n thumbnail,\n url,\n contentCategory->,\n published,\n }';
558
+ videosQuery = '*[_type == \'article\'\n && !(_id in path("drafts.**"))\n && defined(title)\n && defined(url)\n && is_visible == true \n && passwordLock != true\n && references(*[_type == \'contentCategory\' && name == \'Videos\']._id)\n && references(*[_type == \'taxonomy\' ' + addTaxonomyName(favoriteCategories) + ' ]._id)\n && defined(published)\n && _id != $id\n && dateTime(published) <= dateTime(now())] | order(published desc) [' + starting + '...' + (starting + 1) + '] {\n ...,\n title,\n thumbnail,\n url,\n contentCategory->,\n published,\n }';
559
+ podcastQuery = '*[_type == \'article\'\n && !(_id in path("drafts.**"))\n && defined(title)\n && defined(url)\n && is_visible == true \n && passwordLock != true\n && references(*[_type == \'contentCategory\' && name == \'Podcasts\']._id)\n && references(*[_type == \'taxonomy\' ' + addTaxonomyName(favoriteCategories) + ']._id)\n && defined(published)\n && _id != $id\n && dateTime(published) <= dateTime(now())] | order(published desc) [' + starting + '...' + (starting + 2) + '] {\n ...,\n title,\n thumbnail,\n url,\n contentCategory->,\n published,\n }';
593
560
  params = {
594
561
  id: article._id
595
562
  };
596
- _context.next = 31;
563
+ _context.next = 15;
597
564
  return asyncToGenerator._Promise.all([client.fetch(articlesQuery, params), client.fetch(videosQuery, params), client.fetch(podcastQuery, params)]);
598
565
 
599
- case 31:
566
+ case 15:
600
567
  _ref2 = _context.sent;
601
568
  _ref3 = slicedToArray._slicedToArray(_ref2, 3);
602
569
  _articles = _ref3[0];
603
570
  videos = _ref3[1];
604
571
  podcasts = _ref3[2];
605
572
 
606
- if (_articles.length === 0) setLoaded('failed');
607
573
  if (_articles) {
608
574
  if (videos[0] && _articles[2]) {
609
575
  _articles[2] = videos[0];
@@ -616,13 +582,8 @@ var Recommended = function Recommended(props) {
616
582
  }
617
583
  setArticles(_articles);
618
584
  }
619
- _context.next = 41;
620
- break;
621
-
622
- case 40:
623
- setLoaded('failed');
624
585
 
625
- case 41:
586
+ case 21:
626
587
  case 'end':
627
588
  return _context.stop();
628
589
  }
@@ -638,13 +599,12 @@ var Recommended = function Recommended(props) {
638
599
  getSegmentProfile();
639
600
  } catch (err) {
640
601
  console.log(err);
641
- setLoaded('failed');
642
602
  }
643
603
  }, [segmentLoaded]);
644
604
 
645
605
  React.useEffect(function () {
646
606
  if (articles && articles.length > 0) {
647
- setLoaded('loaded');
607
+ setLoaded(true);
648
608
  }
649
609
  }, [articles]);
650
610
 
@@ -652,19 +612,18 @@ var Recommended = function Recommended(props) {
652
612
  try {
653
613
  analytics.ready(function () {
654
614
  setSegmentLoaded(function () {
655
- return 'loaded';
615
+ return true;
656
616
  });
657
617
  });
658
618
  } catch (err) {
659
619
  console.log(err);
660
- setLoaded('failed');
661
620
  }
662
621
  }, []);
663
622
 
664
623
  return React__default['default'].createElement(
665
624
  'div',
666
625
  { id: 'recommended' },
667
- loaded === 'loaded' && React__default['default'].createElement(
626
+ loaded ? React__default['default'].createElement(
668
627
  React__default['default'].Fragment,
669
628
  null,
670
629
  React__default['default'].createElement(
@@ -685,7 +644,7 @@ var Recommended = function Recommended(props) {
685
644
  { className: styles.recommendTopImg },
686
645
  React__default['default'].createElement(
687
646
  'a',
688
- { href: '/view/' + article.url.current + '?utm_source=website&utm_medium=dynamic_content&utm_campaign=in_feed_unit' },
647
+ { href: '/view/' + article.url.current },
689
648
  React__default['default'].createElement('img', { src: urlFor({ source: article.thumbnail, client: client, imageHeight: 306, imageWidth: 544 }) })
690
649
  )
691
650
  ),
@@ -704,7 +663,7 @@ var Recommended = function Recommended(props) {
704
663
  ),
705
664
  React__default['default'].createElement(
706
665
  'a',
707
- { href: '/view/' + article.url.current + '?utm_source=website&utm_medium=dynamic_content&utm_campaign=in_feed_unit', className: styles.topLink },
666
+ { href: '/view/' + article.url.current, className: styles.topLink },
708
667
  '>> ',
709
668
  'Read Article'
710
669
  )
@@ -721,7 +680,7 @@ var Recommended = function Recommended(props) {
721
680
  ),
722
681
  React__default['default'].createElement(
723
682
  'a',
724
- { href: '/view/' + article.url.current + '?utm_source=website&utm_medium=dynamic_content&utm_campaign=in_feed_unit' },
683
+ { href: '/view/' + article.url.current },
725
684
  React__default['default'].createElement(
726
685
  'div',
727
686
  { className: styles.smImage },
@@ -737,8 +696,7 @@ var Recommended = function Recommended(props) {
737
696
  }
738
697
  })
739
698
  )
740
- ),
741
- loaded === 'failed' && React__default['default'].createElement(
699
+ ) : React__default['default'].createElement(
742
700
  'section',
743
701
  { id: 'related-content-section', className: 'my-1' },
744
702
  (article.relatedArticle || RelevantTopics({ article: article })) && React__default['default'].createElement(
package/dist/esm/View.js CHANGED
@@ -462,11 +462,10 @@ var Recommended = function Recommended(props) {
462
462
  articles = _useState4[0],
463
463
  setArticles = _useState4[1];
464
464
 
465
- var _useState5 = useState('loading'),
465
+ var _useState5 = useState(false),
466
466
  _useState6 = _slicedToArray(_useState5, 2),
467
467
  loaded = _useState6[0],
468
- setLoaded = _useState6[1]; //loading, loaded, failed
469
-
468
+ setLoaded = _useState6[1];
470
469
 
471
470
  var starting = index * 5;
472
471
  var contentMapping = {
@@ -492,33 +491,32 @@ var Recommended = function Recommended(props) {
492
491
  categories: _JSON$stringify(mainCategories)
493
492
  });
494
493
  }
495
-
494
+ var anonymousId = analytics.user().anonymousId();
496
495
  // get users traits
497
496
  var getSegmentProfile = function () {
498
497
  var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
499
- var anonymousId, response, data, addTaxonomyName, favoriteCategories, articlesCategory, videosCategory, podcastCategory, taxonomyCategories, taxonomies, articlesQuery, videosQuery, podcastQuery, params, _ref2, _ref3, _articles, videos, podcasts;
498
+ var response, data, addTaxonomyName, favoriteCategories, articlesQuery, videosQuery, podcastQuery, params, _ref2, _ref3, _articles, videos, podcasts;
500
499
 
501
500
  return regenerator.wrap(function _callee$(_context) {
502
501
  while (1) {
503
502
  switch (_context.prev = _context.next) {
504
503
  case 0:
505
- anonymousId = analytics.user().anonymousId();
506
- _context.next = 3;
504
+ _context.next = 2;
507
505
  return fetch('/api/getSegmentProfile', {
508
506
  method: 'POST',
509
507
  body: _JSON$stringify({ anonymousId: anonymousId })
510
508
  });
511
509
 
512
- case 3:
510
+ case 2:
513
511
  response = _context.sent;
514
- _context.next = 6;
512
+ _context.next = 5;
515
513
  return response.json();
516
514
 
517
- case 6:
515
+ case 5:
518
516
  data = _context.sent;
519
517
 
520
518
  if (!(data && data.traits && data.traits.favorite_article_category)) {
521
- _context.next = 40;
519
+ _context.next = 21;
522
520
  break;
523
521
  }
524
522
 
@@ -537,62 +535,30 @@ var Recommended = function Recommended(props) {
537
535
 
538
536
  query = query + ' )';
539
537
 
538
+ console.log(query);
539
+
540
540
  return query;
541
541
  };
542
542
 
543
543
  favoriteCategories = JSON.parse(data.traits.favorite_article_category);
544
-
545
- //grab contentCategory ID
546
-
547
- _context.next = 12;
548
- return client.fetch("*[_type == 'contentCategory' && name == 'Articles'][0]{_id}");
549
-
550
- case 12:
551
- articlesCategory = _context.sent;
552
- _context.next = 15;
553
- return client.fetch("*[_type == 'contentCategory' && name == 'Videos'][0]{_id}");
554
-
555
- case 15:
556
- videosCategory = _context.sent;
557
- _context.next = 18;
558
- return client.fetch("*[_type == 'contentCategory' && name == 'Podcasts'][0]{_id}");
559
-
560
- case 18:
561
- podcastCategory = _context.sent;
562
- _context.next = 21;
563
- return client.fetch('*[_type == \'taxonomy\' ' + addTaxonomyName(favoriteCategories) + ']');
564
-
565
- case 21:
566
- taxonomyCategories = _context.sent;
567
- taxonomies = '';
568
-
569
- taxonomyCategories.forEach(function (taxonomy, index) {
570
- if (index === 0) {
571
- taxonomies = taxonomies + (' && ( references(\'' + taxonomy._id + '\')');
572
- } else {
573
- taxonomies = taxonomies + (' || references(\'' + taxonomy._id + '\')');
574
- }
575
- });
576
- taxonomies = taxonomies + ' )';
577
-
578
544
  // grab 3 articles from sanity different from the one currently being read
579
- articlesQuery = '*[_type == \'article\'\n && !(_id in path("drafts.**"))\n && defined(title)\n && defined(url)\n && is_visible == true \n && passwordLock != true\n && references(\'' + articlesCategory._id + '\')\n ' + taxonomies + '\n && defined(published)\n && _id != $id\n && dateTime(published) <= dateTime(now())] | order(published desc) [' + starting + '...' + (starting + 5) + '] {\n ...,\n title,\n thumbnail,\n url,\n contentCategory->,\n published,\n }';
580
- videosQuery = '*[_type == \'article\'\n && !(_id in path("drafts.**"))\n && defined(title)\n && defined(url)\n && is_visible == true \n && passwordLock != true\n && references(\'' + videosCategory._id + '\')\n ' + taxonomies + '\n && defined(published)\n && _id != $id\n && dateTime(published) <= dateTime(now())] | order(published desc) [' + starting + '...' + (starting + 1) + '] {\n ...,\n title,\n thumbnail,\n url,\n contentCategory->,\n published,\n }';
581
- podcastQuery = '*[_type == \'article\'\n && !(_id in path("drafts.**"))\n && defined(title)\n && defined(url)\n && is_visible == true \n && passwordLock != true\n && references(\'' + podcastCategory._id + '\')\n ' + taxonomies + '\n && defined(published)\n && _id != $id\n && dateTime(published) <= dateTime(now())] | order(published desc) [' + starting + '...' + (starting + 2) + '] {\n ...,\n title,\n thumbnail,\n url,\n contentCategory->,\n published,\n }';
545
+
546
+ articlesQuery = '*[_type == \'article\'\n && !(_id in path("drafts.**"))\n && defined(title)\n && defined(url)\n && is_visible == true \n && passwordLock != true\n && references(*[_type == \'contentCategory\' && name == \'Articles\']._id)\n && references(*[_type == \'taxonomy\' ' + addTaxonomyName(favoriteCategories) + ']._id)\n && defined(published)\n && _id != $id\n && dateTime(published) <= dateTime(now())] | order(published desc) [' + starting + '...' + (starting + 5) + '] {\n ...,\n title,\n thumbnail,\n url,\n contentCategory->,\n published,\n }';
547
+ videosQuery = '*[_type == \'article\'\n && !(_id in path("drafts.**"))\n && defined(title)\n && defined(url)\n && is_visible == true \n && passwordLock != true\n && references(*[_type == \'contentCategory\' && name == \'Videos\']._id)\n && references(*[_type == \'taxonomy\' ' + addTaxonomyName(favoriteCategories) + ' ]._id)\n && defined(published)\n && _id != $id\n && dateTime(published) <= dateTime(now())] | order(published desc) [' + starting + '...' + (starting + 1) + '] {\n ...,\n title,\n thumbnail,\n url,\n contentCategory->,\n published,\n }';
548
+ podcastQuery = '*[_type == \'article\'\n && !(_id in path("drafts.**"))\n && defined(title)\n && defined(url)\n && is_visible == true \n && passwordLock != true\n && references(*[_type == \'contentCategory\' && name == \'Podcasts\']._id)\n && references(*[_type == \'taxonomy\' ' + addTaxonomyName(favoriteCategories) + ']._id)\n && defined(published)\n && _id != $id\n && dateTime(published) <= dateTime(now())] | order(published desc) [' + starting + '...' + (starting + 2) + '] {\n ...,\n title,\n thumbnail,\n url,\n contentCategory->,\n published,\n }';
582
549
  params = {
583
550
  id: article._id
584
551
  };
585
- _context.next = 31;
552
+ _context.next = 15;
586
553
  return _Promise.all([client.fetch(articlesQuery, params), client.fetch(videosQuery, params), client.fetch(podcastQuery, params)]);
587
554
 
588
- case 31:
555
+ case 15:
589
556
  _ref2 = _context.sent;
590
557
  _ref3 = _slicedToArray(_ref2, 3);
591
558
  _articles = _ref3[0];
592
559
  videos = _ref3[1];
593
560
  podcasts = _ref3[2];
594
561
 
595
- if (_articles.length === 0) setLoaded('failed');
596
562
  if (_articles) {
597
563
  if (videos[0] && _articles[2]) {
598
564
  _articles[2] = videos[0];
@@ -605,13 +571,8 @@ var Recommended = function Recommended(props) {
605
571
  }
606
572
  setArticles(_articles);
607
573
  }
608
- _context.next = 41;
609
- break;
610
-
611
- case 40:
612
- setLoaded('failed');
613
574
 
614
- case 41:
575
+ case 21:
615
576
  case 'end':
616
577
  return _context.stop();
617
578
  }
@@ -627,13 +588,12 @@ var Recommended = function Recommended(props) {
627
588
  getSegmentProfile();
628
589
  } catch (err) {
629
590
  console.log(err);
630
- setLoaded('failed');
631
591
  }
632
592
  }, [segmentLoaded]);
633
593
 
634
594
  useEffect(function () {
635
595
  if (articles && articles.length > 0) {
636
- setLoaded('loaded');
596
+ setLoaded(true);
637
597
  }
638
598
  }, [articles]);
639
599
 
@@ -641,19 +601,18 @@ var Recommended = function Recommended(props) {
641
601
  try {
642
602
  analytics.ready(function () {
643
603
  setSegmentLoaded(function () {
644
- return 'loaded';
604
+ return true;
645
605
  });
646
606
  });
647
607
  } catch (err) {
648
608
  console.log(err);
649
- setLoaded('failed');
650
609
  }
651
610
  }, []);
652
611
 
653
612
  return React__default.createElement(
654
613
  'div',
655
614
  { id: 'recommended' },
656
- loaded === 'loaded' && React__default.createElement(
615
+ loaded ? React__default.createElement(
657
616
  React__default.Fragment,
658
617
  null,
659
618
  React__default.createElement(
@@ -674,7 +633,7 @@ var Recommended = function Recommended(props) {
674
633
  { className: styles.recommendTopImg },
675
634
  React__default.createElement(
676
635
  'a',
677
- { href: '/view/' + article.url.current + '?utm_source=website&utm_medium=dynamic_content&utm_campaign=in_feed_unit' },
636
+ { href: '/view/' + article.url.current },
678
637
  React__default.createElement('img', { src: urlFor({ source: article.thumbnail, client: client, imageHeight: 306, imageWidth: 544 }) })
679
638
  )
680
639
  ),
@@ -693,7 +652,7 @@ var Recommended = function Recommended(props) {
693
652
  ),
694
653
  React__default.createElement(
695
654
  'a',
696
- { href: '/view/' + article.url.current + '?utm_source=website&utm_medium=dynamic_content&utm_campaign=in_feed_unit', className: styles.topLink },
655
+ { href: '/view/' + article.url.current, className: styles.topLink },
697
656
  '>> ',
698
657
  'Read Article'
699
658
  )
@@ -710,7 +669,7 @@ var Recommended = function Recommended(props) {
710
669
  ),
711
670
  React__default.createElement(
712
671
  'a',
713
- { href: '/view/' + article.url.current + '?utm_source=website&utm_medium=dynamic_content&utm_campaign=in_feed_unit' },
672
+ { href: '/view/' + article.url.current },
714
673
  React__default.createElement(
715
674
  'div',
716
675
  { className: styles.smImage },
@@ -726,8 +685,7 @@ var Recommended = function Recommended(props) {
726
685
  }
727
686
  })
728
687
  )
729
- ),
730
- loaded === 'failed' && React__default.createElement(
688
+ ) : React__default.createElement(
731
689
  'section',
732
690
  { id: 'related-content-section', className: 'my-1' },
733
691
  (article.relatedArticle || RelevantTopics({ article: article })) && React__default.createElement(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mjhls/mjh-framework",
3
- "version": "1.0.939-segment-test-v12",
3
+ "version": "1.0.939",
4
4
  "description": "Foundation Framework",
5
5
  "author": "mjh-framework",
6
6
  "license": "MIT",