@selfcommunity/react-core 0.1.6 → 0.1.7

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.
@@ -60,9 +60,11 @@ function SCPreferencesProvider({
60
60
  */
61
61
 
62
62
  (0, _react.useEffect)(() => {
63
- Promise.all([_apiServices.PreferenceService.getAllPreferences(), _apiServices.FeatureService.getAllFeatures()]).then(function (results) {
64
- setPreferences(results[0]);
65
- setFeatures(results[1]);
63
+ Promise.all([_apiServices.PreferenceService.getAllPreferences(), _apiServices.FeatureService.getAllFeatures()]).then(function ([preferences, features]) {
64
+ setPreferences(preferences['results'].reduce((obj, p) => Object.assign({}, obj, {
65
+ [`${p.section}.${p.name}`]: p
66
+ }), {}));
67
+ setFeatures(features['results'].map(f => f.name));
66
68
  setLoading(false);
67
69
  }).catch(_error => {
68
70
  _utils.Logger.error(_Errors.SCOPE_SC_CORE, _error);
@@ -109,8 +109,23 @@ function useSCWebSocket() {
109
109
 
110
110
 
111
111
  const setNotificationCounters = payload => {
112
- payload.count_interactions !== undefined && scUserContext.setUnseenInteractionsCounter(payload.count_interactions);
113
- payload.count_notification_banners !== undefined && scUserContext.setUnseenInteractionsCounter(payload.count_notification_banners);
112
+ /**
113
+ * The counter count_interactions includes pure interactions and notification banners,
114
+ * so unseen_interactions_counter = payload.count_interactions - payload.count_notification_banners
115
+ * if payload.count_notification_banners exists (was added later in the payload of the message ws)
116
+ */
117
+ let unseen_interactions_counter = 0;
118
+
119
+ if (payload.count_interactions !== undefined) {
120
+ unseen_interactions_counter = payload.count_interactions;
121
+ }
122
+
123
+ if (payload.count_notification_banners !== undefined) {
124
+ unseen_interactions_counter = Math.max(unseen_interactions_counter - payload.count_notification_banners, 0);
125
+ scUserContext.setUnseenInteractionsCounter(payload.count_notification_banners);
126
+ }
127
+
128
+ payload.count_interactions !== undefined && scUserContext.setUnseenInteractionsCounter(unseen_interactions_counter);
114
129
  };
115
130
 
116
131
  return {
@@ -60,9 +60,11 @@ function SCPreferencesProvider({
60
60
  */
61
61
 
62
62
  (0, _react.useEffect)(() => {
63
- Promise.all([_apiServices.PreferenceService.getAllPreferences(), _apiServices.FeatureService.getAllFeatures()]).then(function (results) {
64
- setPreferences(results[0]);
65
- setFeatures(results[1]);
63
+ Promise.all([_apiServices.PreferenceService.getAllPreferences(), _apiServices.FeatureService.getAllFeatures()]).then(function ([preferences, features]) {
64
+ setPreferences(preferences['results'].reduce((obj, p) => Object.assign({}, obj, {
65
+ [`${p.section}.${p.name}`]: p
66
+ }), {}));
67
+ setFeatures(features['results'].map(f => f.name));
66
68
  setLoading(false);
67
69
  }).catch(_error => {
68
70
  _utils.Logger.error(_Errors.SCOPE_SC_CORE, _error);
@@ -109,8 +109,23 @@ function useSCWebSocket() {
109
109
 
110
110
 
111
111
  const setNotificationCounters = payload => {
112
- payload.count_interactions !== undefined && scUserContext.setUnseenInteractionsCounter(payload.count_interactions);
113
- payload.count_notification_banners !== undefined && scUserContext.setUnseenInteractionsCounter(payload.count_notification_banners);
112
+ /**
113
+ * The counter count_interactions includes pure interactions and notification banners,
114
+ * so unseen_interactions_counter = payload.count_interactions - payload.count_notification_banners
115
+ * if payload.count_notification_banners exists (was added later in the payload of the message ws)
116
+ */
117
+ let unseen_interactions_counter = 0;
118
+
119
+ if (payload.count_interactions !== undefined) {
120
+ unseen_interactions_counter = payload.count_interactions;
121
+ }
122
+
123
+ if (payload.count_notification_banners !== undefined) {
124
+ unseen_interactions_counter = Math.max(unseen_interactions_counter - payload.count_notification_banners, 0);
125
+ scUserContext.setUnseenInteractionsCounter(payload.count_notification_banners);
126
+ }
127
+
128
+ payload.count_interactions !== undefined && scUserContext.setUnseenInteractionsCounter(unseen_interactions_counter);
114
129
  };
115
130
 
116
131
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/provider/SCPreferencesProvider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkE,MAAM,OAAO,CAAC;AAEvF,OAAO,EAAC,wBAAwB,EAAC,MAAM,wBAAwB,CAAC;AAIhE;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,yCAA0E,CAAC;AAE5G;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,EAAC,QAAe,EAAC,EAAE;IAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAC,GAAG,GAAG,CAAC,OAAO,CA4BzG;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,wBAAwB,CAE3D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/provider/SCPreferencesProvider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuD,MAAM,OAAO,CAAC;AAE5E,OAAO,EAAC,wBAAwB,EAAC,MAAM,wBAAwB,CAAC;AAIhE;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,yCAA0E,CAAC;AAE5G;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,EAAC,QAAe,EAAC,EAAE;IAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAC,GAAG,GAAG,CAAC,OAAO,CA4BzG;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,wBAAwB,CAE3D"}
@@ -1 +1 @@
1
- {"version":3,"file":"useSCWebSocket.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSCWebSocket.ts"],"names":[],"mappings":";AAKA,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAMlD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc;;;EAuFrC"}
1
+ {"version":3,"file":"useSCWebSocket.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSCWebSocket.ts"],"names":[],"mappings":";AAKA,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAMlD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc;;;EAmGrC"}