@mjhls/mjh-framework 1.0.661 → 1.0.662

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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # mjh-framework v. 1.0.661
2
+ # mjh-framework v. 1.0.662
3
3
 
4
4
  > Foundation Framework
5
5
 
@@ -68,23 +68,23 @@ var MasterDeck = function (_React$Component) {
68
68
  from: _this.params ? _this.params.from : 0,
69
69
  to: _this.params ? _this.params.to : 2,
70
70
  total_pages: null,
71
- scrolling: true,
71
+ scrolling: false,
72
72
  query: _this.query,
73
73
  currentPage: _this.props.currentPage || 1,
74
- dataRemapped: false,
74
+ dataRemapped: !_this.props.showBI || !_this.props.brandInsightAd,
75
75
  lastDataSize: _this.data ? _this.data.length : 0,
76
76
  itemsPerPage: _this.params ? _this.params.to - _this.params.from : 2
77
77
  }, _this.loadMore = debounce.debounce_1(function () {
78
78
  _this.setState(function (state) {
79
79
  var page = state.page,
80
80
  from = state.from,
81
- per = state.per,
82
- to = state.to;
81
+ to = state.to,
82
+ itemsPerPage = state.itemsPerPage;
83
83
 
84
84
  return {
85
85
  page: page + 1,
86
- from: from + per,
87
- to: to + per
86
+ from: from + itemsPerPage,
87
+ to: to + itemsPerPage
88
88
  };
89
89
  }, _this.loadData);
90
90
  }, 0), _this.loadData = function () {
@@ -99,7 +99,7 @@ var MasterDeck = function (_React$Component) {
99
99
  dataHandler = _this$props.dataHandler;
100
100
 
101
101
 
102
- var params = _extends._extends({}, _this.props.params, { from: from, to: to });
102
+ var params = _extends._extends({}, _this.props.params, { from: from, to: to + 1 });
103
103
 
104
104
  if (dataHandler) {
105
105
  var dataHandlerPromise = new asyncToGenerator._Promise(function (resolve, reject) {
@@ -123,31 +123,61 @@ var MasterDeck = function (_React$Component) {
123
123
  var pointer = _this.pointer;
124
124
  dataArr = dataArr[_this.pointerArray][pointer];
125
125
  }
126
- dataArr = dataArr.map(function (item) {
127
- return _extends._extends({}, item, {
128
- pageNumber: page
126
+
127
+ if (dataArr && dataArr.length > 0) {
128
+ var itemsPerPage = _this.state.itemsPerPage;
129
+
130
+ var scrolling = dataArr.length === itemsPerPage + 1;
131
+ dataArr = dataArr.slice(0, itemsPerPage).map(function (item) {
132
+ return _extends._extends({}, item, {
133
+ pageNumber: page
134
+ });
129
135
  });
130
- });
131
136
 
132
- _this.setState(function () {
133
- if (dataArr.length > 0) {
134
- return {
135
- data: [].concat(toConsumableArray._toConsumableArray(data), toConsumableArray._toConsumableArray(dataArr)),
136
- lastDataSize: dataArr.length,
137
- scrolling: true
138
- };
139
- } else {
140
- return {
141
- scrolling: false,
142
- lastDataSize: 0
143
- };
144
- }
145
- });
146
- }, _this.changePageNumber = function (pageNumber) {
137
+ _this.setState({
138
+ data: [].concat(toConsumableArray._toConsumableArray(data), toConsumableArray._toConsumableArray(dataArr)),
139
+ lastDataSize: dataArr.length,
140
+ scrolling: scrolling
141
+ });
142
+ } else {
143
+ _this.setState({
144
+ scrolling: false,
145
+ lastDataSize: 0
146
+ });
147
+ }
148
+ }, _this.checkMoreDataAvailable = function () {
149
+ debugger;
150
+ var _this$state2 = _this.state,
151
+ from = _this$state2.from,
152
+ itemsPerPage = _this$state2.itemsPerPage,
153
+ query = _this$state2.query;
147
154
  var _this$props2 = _this.props,
148
- seoPaginate = _this$props2.seoPaginate,
149
- pageview = _this$props2.pageview,
150
- router = _this$props2.router;
155
+ client = _this$props2.client,
156
+ dataHandler = _this$props2.dataHandler;
157
+
158
+ var params = _extends._extends({}, _this.props.params, { from: from + itemsPerPage, to: from + itemsPerPage + 1 });
159
+ if (dataHandler) {
160
+ var dataHandlerPromise = new asyncToGenerator._Promise(function (resolve, reject) {
161
+ try {
162
+ var result = dataHandler(params);
163
+ resolve(result);
164
+ } catch (e) {
165
+ reject(e);
166
+ }
167
+ });
168
+ dataHandlerPromise.then(function (dataArr) {
169
+ if (dataArr && dataArr.length > 0) _this.setState({ scrolling: true });else _this.setState({ scrolling: false });
170
+ });
171
+ } else {
172
+ client.fetch(query, params).then(function (dataArr) {
173
+ if (dataArr && dataArr.length > 0) _this.setState({ scrolling: true });else _this.setState({ scrolling: false });
174
+ });
175
+ }
176
+ }, _this.changePageNumber = function (pageNumber) {
177
+ var _this$props3 = _this.props,
178
+ seoPaginate = _this$props3.seoPaginate,
179
+ pageview = _this$props3.pageview,
180
+ router = _this$props3.router;
151
181
  var currentPage = _this.state.currentPage;
152
182
 
153
183
  if (seoPaginate) {
@@ -225,9 +255,6 @@ var MasterDeck = function (_React$Component) {
225
255
  var insertBrandInsightAd = function insertBrandInsightAd(arr, index, newElement) {
226
256
  return [].concat(toConsumableArray._toConsumableArray(arr.slice(0, index)), [newElement], toConsumableArray._toConsumableArray(arr.slice(index)));
227
257
  };
228
- _this.componentDidMount = function () {
229
- _this.setState({ dataRemapped: !showBI || !brandInsightAd ? true : false });
230
- };
231
258
  // Need to pass flag "lgInfeedAd={true}" along with brandInsightAd from site level for large infeed-ad to render
232
259
  // Checking lgInfeedAd flag in desktop view ( window >= 1400px ).
233
260
  // Integrating large infeed AD
@@ -372,10 +399,10 @@ var MasterDeck = function (_React$Component) {
372
399
  rightItems[i].component
373
400
  );
374
401
  }, _this.renderManualPagination = function () {
375
- var _this$state2 = _this.state,
376
- currentPage = _this$state2.currentPage,
377
- itemsPerPage = _this$state2.itemsPerPage,
378
- lastDataSize = _this$state2.lastDataSize;
402
+ var _this$state3 = _this.state,
403
+ currentPage = _this$state3.currentPage,
404
+ itemsPerPage = _this$state3.itemsPerPage,
405
+ lastDataSize = _this$state3.lastDataSize;
379
406
 
380
407
  console.log('lastDataSize:', lastDataSize);
381
408
  console.log('itemsPerPage:', itemsPerPage);
@@ -426,7 +453,11 @@ var MasterDeck = function (_React$Component) {
426
453
  }, {
427
454
  key: 'componentDidMount',
428
455
  value: function componentDidMount() {
429
- // this.loadData();
456
+ var _state = this.state,
457
+ data = _state.data,
458
+ itemsPerPage = _state.itemsPerPage;
459
+
460
+ if (!(data.length < itemsPerPage)) this.checkMoreDataAvailable();
430
461
  }
431
462
  // Passing 'brandInsightAd','showBI' and 'lgInfeedAd'
432
463
 
@@ -482,7 +513,16 @@ var MasterDeck = function (_React$Component) {
482
513
  'button',
483
514
  {
484
515
  className: 'btn',
485
- style: { margin: '0 auto 2rem', display: 'block', fontSize: '18px', padding: '.5rem 1.5rem', boxShadow: '1px 2px 4px 4px rgba(0,0,0,.15)', background: 'var(--primary)', color: '#fff', borderRadius: '5px' },
516
+ style: {
517
+ margin: '0 auto 2rem',
518
+ display: 'block',
519
+ fontSize: '18px',
520
+ padding: '.5rem 1.5rem',
521
+ boxShadow: '1px 2px 4px 4px rgba(0,0,0,.15)',
522
+ background: 'var(--primary)',
523
+ color: '#fff',
524
+ borderRadius: '5px'
525
+ },
486
526
  onClick: function onClick(e) {
487
527
  _this3.loadMore();
488
528
  } },
@@ -62,23 +62,23 @@ var MasterDeck = function (_React$Component) {
62
62
  from: _this.params ? _this.params.from : 0,
63
63
  to: _this.params ? _this.params.to : 2,
64
64
  total_pages: null,
65
- scrolling: true,
65
+ scrolling: false,
66
66
  query: _this.query,
67
67
  currentPage: _this.props.currentPage || 1,
68
- dataRemapped: false,
68
+ dataRemapped: !_this.props.showBI || !_this.props.brandInsightAd,
69
69
  lastDataSize: _this.data ? _this.data.length : 0,
70
70
  itemsPerPage: _this.params ? _this.params.to - _this.params.from : 2
71
71
  }, _this.loadMore = debounce_1(function () {
72
72
  _this.setState(function (state) {
73
73
  var page = state.page,
74
74
  from = state.from,
75
- per = state.per,
76
- to = state.to;
75
+ to = state.to,
76
+ itemsPerPage = state.itemsPerPage;
77
77
 
78
78
  return {
79
79
  page: page + 1,
80
- from: from + per,
81
- to: to + per
80
+ from: from + itemsPerPage,
81
+ to: to + itemsPerPage
82
82
  };
83
83
  }, _this.loadData);
84
84
  }, 0), _this.loadData = function () {
@@ -93,7 +93,7 @@ var MasterDeck = function (_React$Component) {
93
93
  dataHandler = _this$props.dataHandler;
94
94
 
95
95
 
96
- var params = _extends({}, _this.props.params, { from: from, to: to });
96
+ var params = _extends({}, _this.props.params, { from: from, to: to + 1 });
97
97
 
98
98
  if (dataHandler) {
99
99
  var dataHandlerPromise = new _Promise(function (resolve, reject) {
@@ -117,31 +117,61 @@ var MasterDeck = function (_React$Component) {
117
117
  var pointer = _this.pointer;
118
118
  dataArr = dataArr[_this.pointerArray][pointer];
119
119
  }
120
- dataArr = dataArr.map(function (item) {
121
- return _extends({}, item, {
122
- pageNumber: page
120
+
121
+ if (dataArr && dataArr.length > 0) {
122
+ var itemsPerPage = _this.state.itemsPerPage;
123
+
124
+ var scrolling = dataArr.length === itemsPerPage + 1;
125
+ dataArr = dataArr.slice(0, itemsPerPage).map(function (item) {
126
+ return _extends({}, item, {
127
+ pageNumber: page
128
+ });
123
129
  });
124
- });
125
130
 
126
- _this.setState(function () {
127
- if (dataArr.length > 0) {
128
- return {
129
- data: [].concat(_toConsumableArray(data), _toConsumableArray(dataArr)),
130
- lastDataSize: dataArr.length,
131
- scrolling: true
132
- };
133
- } else {
134
- return {
135
- scrolling: false,
136
- lastDataSize: 0
137
- };
138
- }
139
- });
140
- }, _this.changePageNumber = function (pageNumber) {
131
+ _this.setState({
132
+ data: [].concat(_toConsumableArray(data), _toConsumableArray(dataArr)),
133
+ lastDataSize: dataArr.length,
134
+ scrolling: scrolling
135
+ });
136
+ } else {
137
+ _this.setState({
138
+ scrolling: false,
139
+ lastDataSize: 0
140
+ });
141
+ }
142
+ }, _this.checkMoreDataAvailable = function () {
143
+ debugger;
144
+ var _this$state2 = _this.state,
145
+ from = _this$state2.from,
146
+ itemsPerPage = _this$state2.itemsPerPage,
147
+ query = _this$state2.query;
141
148
  var _this$props2 = _this.props,
142
- seoPaginate = _this$props2.seoPaginate,
143
- pageview = _this$props2.pageview,
144
- router = _this$props2.router;
149
+ client = _this$props2.client,
150
+ dataHandler = _this$props2.dataHandler;
151
+
152
+ var params = _extends({}, _this.props.params, { from: from + itemsPerPage, to: from + itemsPerPage + 1 });
153
+ if (dataHandler) {
154
+ var dataHandlerPromise = new _Promise(function (resolve, reject) {
155
+ try {
156
+ var result = dataHandler(params);
157
+ resolve(result);
158
+ } catch (e) {
159
+ reject(e);
160
+ }
161
+ });
162
+ dataHandlerPromise.then(function (dataArr) {
163
+ if (dataArr && dataArr.length > 0) _this.setState({ scrolling: true });else _this.setState({ scrolling: false });
164
+ });
165
+ } else {
166
+ client.fetch(query, params).then(function (dataArr) {
167
+ if (dataArr && dataArr.length > 0) _this.setState({ scrolling: true });else _this.setState({ scrolling: false });
168
+ });
169
+ }
170
+ }, _this.changePageNumber = function (pageNumber) {
171
+ var _this$props3 = _this.props,
172
+ seoPaginate = _this$props3.seoPaginate,
173
+ pageview = _this$props3.pageview,
174
+ router = _this$props3.router;
145
175
  var currentPage = _this.state.currentPage;
146
176
 
147
177
  if (seoPaginate) {
@@ -219,9 +249,6 @@ var MasterDeck = function (_React$Component) {
219
249
  var insertBrandInsightAd = function insertBrandInsightAd(arr, index, newElement) {
220
250
  return [].concat(_toConsumableArray(arr.slice(0, index)), [newElement], _toConsumableArray(arr.slice(index)));
221
251
  };
222
- _this.componentDidMount = function () {
223
- _this.setState({ dataRemapped: !showBI || !brandInsightAd ? true : false });
224
- };
225
252
  // Need to pass flag "lgInfeedAd={true}" along with brandInsightAd from site level for large infeed-ad to render
226
253
  // Checking lgInfeedAd flag in desktop view ( window >= 1400px ).
227
254
  // Integrating large infeed AD
@@ -366,10 +393,10 @@ var MasterDeck = function (_React$Component) {
366
393
  rightItems[i].component
367
394
  );
368
395
  }, _this.renderManualPagination = function () {
369
- var _this$state2 = _this.state,
370
- currentPage = _this$state2.currentPage,
371
- itemsPerPage = _this$state2.itemsPerPage,
372
- lastDataSize = _this$state2.lastDataSize;
396
+ var _this$state3 = _this.state,
397
+ currentPage = _this$state3.currentPage,
398
+ itemsPerPage = _this$state3.itemsPerPage,
399
+ lastDataSize = _this$state3.lastDataSize;
373
400
 
374
401
  console.log('lastDataSize:', lastDataSize);
375
402
  console.log('itemsPerPage:', itemsPerPage);
@@ -420,7 +447,11 @@ var MasterDeck = function (_React$Component) {
420
447
  }, {
421
448
  key: 'componentDidMount',
422
449
  value: function componentDidMount() {
423
- // this.loadData();
450
+ var _state = this.state,
451
+ data = _state.data,
452
+ itemsPerPage = _state.itemsPerPage;
453
+
454
+ if (!(data.length < itemsPerPage)) this.checkMoreDataAvailable();
424
455
  }
425
456
  // Passing 'brandInsightAd','showBI' and 'lgInfeedAd'
426
457
 
@@ -476,7 +507,16 @@ var MasterDeck = function (_React$Component) {
476
507
  'button',
477
508
  {
478
509
  className: 'btn',
479
- style: { margin: '0 auto 2rem', display: 'block', fontSize: '18px', padding: '.5rem 1.5rem', boxShadow: '1px 2px 4px 4px rgba(0,0,0,.15)', background: 'var(--primary)', color: '#fff', borderRadius: '5px' },
510
+ style: {
511
+ margin: '0 auto 2rem',
512
+ display: 'block',
513
+ fontSize: '18px',
514
+ padding: '.5rem 1.5rem',
515
+ boxShadow: '1px 2px 4px 4px rgba(0,0,0,.15)',
516
+ background: 'var(--primary)',
517
+ color: '#fff',
518
+ borderRadius: '5px'
519
+ },
480
520
  onClick: function onClick(e) {
481
521
  _this3.loadMore();
482
522
  } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mjhls/mjh-framework",
3
- "version": "1.0.661",
3
+ "version": "1.0.662",
4
4
  "description": "Foundation Framework",
5
5
  "author": "mjh-framework",
6
6
  "license": "MIT",