Browse Source

[frontend] Add pubSub to trigger error alerts

Johan Ahlen 5 years ago
parent
commit
f14bf62fc2

+ 2 - 1
desktop/core/src/desktop/js/api/utils.ts

@@ -16,6 +16,7 @@
 
 import axios, { AxiosError, AxiosTransformer } from 'axios';
 import qs from 'qs';
+import huePubSub from 'utils/huePubSub';
 
 import { CancellablePromise } from './cancellablePromise';
 import hueUtils from 'utils/hueUtils';
@@ -100,7 +101,7 @@ export const post = <T, U = unknown, E = string>(
       if (!options || !options.silenceErrors) {
         hueUtils.logError(response);
         if (message.indexOf('AuthorizationException') === -1) {
-          $(document).trigger('error', message);
+          huePubSub.publish('hue.error', message);
         }
       }
     };

+ 1 - 2
desktop/core/src/desktop/js/utils/hueConfig.ts

@@ -14,7 +14,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-import $ from 'jquery';
 import { simplePostAsync } from 'api/apiUtils';
 import { FETCH_CONFIG_API } from 'api/urls';
 import {
@@ -45,7 +44,7 @@ export const refreshConfig = async (): Promise<HueConfig> => {
         lastKnownConfig = apiResponse;
         resolve(lastKnownConfig);
       } else {
-        $(document).trigger('error', apiResponse.message);
+        huePubSub.publish('hue.error', apiResponse.message);
         reject();
       }
     } catch (err) {

+ 3 - 0
desktop/core/src/desktop/templates/common_header_footer_components.mako

@@ -376,6 +376,9 @@ from metadata.conf import has_optimizer, OPTIMIZER
     $(document).on("warn", function (e, msg) {
       $.jHueNotify.warn(msg);
     });
+    window.huePubSub.subscribe('hue.error', function (msg) {
+      $.jHueNotify.error(msg);
+    });
     $(document).on("error", function (e, msg) {
       $.jHueNotify.error(msg);
     });