@trackunit/react-core-hooks 0.2.145 → 0.2.147

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/index.cjs.js CHANGED
@@ -386,14 +386,24 @@ const useCustomFieldRuntimeForEntity = (entity) => {
386
386
  */
387
387
  const useEventRuntime = () => {
388
388
  const [eventInfo, setEventInfo] = React.useState();
389
+ const [loading, setLoading] = React.useState(true);
390
+ const [error, setError] = React.useState();
389
391
  React.useEffect(() => {
390
392
  const getEventInfo = () => __awaiter(void 0, void 0, void 0, function* () {
391
- const updatedEventInfo = yield irisAppRuntimeCore.EventRuntime.getEventInfo();
392
- setEventInfo(updatedEventInfo);
393
+ setLoading(true);
394
+ try {
395
+ const updatedEventInfo = yield irisAppRuntimeCore.EventRuntime.getEventInfo();
396
+ setLoading(false);
397
+ setEventInfo(updatedEventInfo);
398
+ }
399
+ catch (e) {
400
+ setLoading(false);
401
+ setError(new Error("Failed to get event info"));
402
+ }
393
403
  });
394
404
  getEventInfo();
395
405
  }, []);
396
- return { eventInfo };
406
+ return { eventInfo, loading, error };
397
407
  };
398
408
 
399
409
  /**
@@ -415,14 +425,24 @@ const useEventRuntime = () => {
415
425
  */
416
426
  const useSiteRuntime = () => {
417
427
  const [siteInfo, setSiteInfo] = React.useState();
428
+ const [loading, setLoading] = React.useState(true);
429
+ const [error, setError] = React.useState();
418
430
  React.useEffect(() => {
419
431
  const getSiteInfo = () => __awaiter(void 0, void 0, void 0, function* () {
420
- const updatedSiteInfo = yield irisAppRuntimeCore.SiteRuntime.getSiteInfo();
421
- setSiteInfo(updatedSiteInfo);
432
+ setLoading(true);
433
+ try {
434
+ const updatedSiteInfo = yield irisAppRuntimeCore.SiteRuntime.getSiteInfo();
435
+ setLoading(false);
436
+ setSiteInfo(updatedSiteInfo);
437
+ }
438
+ catch (e) {
439
+ setLoading(false);
440
+ setError(new Error("Failed to get site info"));
441
+ }
422
442
  });
423
443
  getSiteInfo();
424
444
  }, []);
425
- return { siteInfo };
445
+ return { siteInfo, loading, error };
426
446
  };
427
447
 
428
448
  const UserSubscriptionContext = React__namespace.createContext(null);
package/index.esm.js CHANGED
@@ -360,14 +360,24 @@ const useCustomFieldRuntimeForEntity = (entity) => {
360
360
  */
361
361
  const useEventRuntime = () => {
362
362
  const [eventInfo, setEventInfo] = useState();
363
+ const [loading, setLoading] = useState(true);
364
+ const [error, setError] = useState();
363
365
  useEffect(() => {
364
366
  const getEventInfo = () => __awaiter(void 0, void 0, void 0, function* () {
365
- const updatedEventInfo = yield EventRuntime.getEventInfo();
366
- setEventInfo(updatedEventInfo);
367
+ setLoading(true);
368
+ try {
369
+ const updatedEventInfo = yield EventRuntime.getEventInfo();
370
+ setLoading(false);
371
+ setEventInfo(updatedEventInfo);
372
+ }
373
+ catch (e) {
374
+ setLoading(false);
375
+ setError(new Error("Failed to get event info"));
376
+ }
367
377
  });
368
378
  getEventInfo();
369
379
  }, []);
370
- return { eventInfo };
380
+ return { eventInfo, loading, error };
371
381
  };
372
382
 
373
383
  /**
@@ -389,14 +399,24 @@ const useEventRuntime = () => {
389
399
  */
390
400
  const useSiteRuntime = () => {
391
401
  const [siteInfo, setSiteInfo] = useState();
402
+ const [loading, setLoading] = useState(true);
403
+ const [error, setError] = useState();
392
404
  useEffect(() => {
393
405
  const getSiteInfo = () => __awaiter(void 0, void 0, void 0, function* () {
394
- const updatedSiteInfo = yield SiteRuntime.getSiteInfo();
395
- setSiteInfo(updatedSiteInfo);
406
+ setLoading(true);
407
+ try {
408
+ const updatedSiteInfo = yield SiteRuntime.getSiteInfo();
409
+ setLoading(false);
410
+ setSiteInfo(updatedSiteInfo);
411
+ }
412
+ catch (e) {
413
+ setLoading(false);
414
+ setError(new Error("Failed to get site info"));
415
+ }
396
416
  });
397
417
  getSiteInfo();
398
418
  }, []);
399
- return { siteInfo };
419
+ return { siteInfo, loading, error };
400
420
  };
401
421
 
402
422
  const UserSubscriptionContext = React.createContext(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-hooks",
3
- "version": "0.2.145",
3
+ "version": "0.2.147",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -1,6 +1,8 @@
1
1
  import { EventInfo } from "@trackunit/iris-app-runtime-core";
2
2
  export interface UseEventRuntime {
3
3
  eventInfo: EventInfo | undefined;
4
+ loading: boolean;
5
+ error: Error | undefined;
4
6
  }
5
7
  /**
6
8
  * A hook to expose event runtime for React components
@@ -1,6 +1,8 @@
1
1
  import { SiteInfo } from "@trackunit/iris-app-runtime-core";
2
2
  export interface UseSiteRuntime {
3
3
  siteInfo?: SiteInfo;
4
+ loading: boolean;
5
+ error: Error | undefined;
4
6
  }
5
7
  /**
6
8
  * A hook to expose site runtime for React components