@oneblink/apps-react 6.0.0-beta.2 → 6.0.0-beta.4

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.
@@ -10,10 +10,13 @@ import BaseMapGallery from '@arcgis/core/widgets/BasemapGallery';
10
10
  import OnLoading from '../components/renderer/OnLoading';
11
11
  import MaterialIcon from './MaterialIcon';
12
12
  import '../styles/arcgis-external.css';
13
+ import useIsPageVisible from '../hooks/useIsPageVisible';
13
14
  function FormElementArcGISWebMap({ element, id, ...props }) {
14
15
  const [loadError, setLoadError] = React.useState();
15
16
  const ref = React.useRef(null);
17
+ const layerPanelRef = React.useRef(null);
16
18
  const [isLoading, setIsLoading] = React.useState(true);
19
+ const isPageVisible = useIsPageVisible();
17
20
  React.useEffect(() => {
18
21
  let view;
19
22
  const loadMap = async () => {
@@ -45,13 +48,14 @@ function FormElementArcGISWebMap({ element, id, ...props }) {
45
48
  const layerList = new LayerList({
46
49
  view,
47
50
  });
48
- view.ui.add(new Expand({
51
+ layerPanelRef.current = new Expand({
49
52
  expandIcon: 'layers',
50
53
  view,
51
54
  content: layerList,
52
55
  expanded: element.showLayerPanel,
53
56
  mode: 'floating',
54
- }), 'top-right');
57
+ });
58
+ view.ui.add(layerPanelRef.current, 'top-right');
55
59
  const baseMapGallery = new BaseMapGallery({ view });
56
60
  view.ui.add(new Expand({
57
61
  expandIcon: 'basemap',
@@ -77,6 +81,14 @@ function FormElementArcGISWebMap({ element, id, ...props }) {
77
81
  }
78
82
  };
79
83
  }, [element]);
84
+ React.useEffect(() => {
85
+ if (isPageVisible && layerPanelRef.current) {
86
+ layerPanelRef.current.visible = true;
87
+ }
88
+ else if (!isPageVisible && layerPanelRef.current) {
89
+ layerPanelRef.current.visible = false;
90
+ }
91
+ }, [isPageVisible]);
80
92
  if (loadError) {
81
93
  return (React.createElement("figure", { className: "ob-figure" },
82
94
  React.createElement("div", { className: "figure-content has-text-centered" },
@@ -1 +1 @@
1
- {"version":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C,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,IAAI,CAAC,4CAA4C,EAAE,CAAC,CAAC,CAAA;gBAC7D,YAAY,CAAC,CAAU,CAAC,CAAA;gBACxB,YAAY,CAAC,KAAK,CAAC,CAAA;aACpB;QACH,CAAC,CAAA;QAED,OAAO,EAAE,CAAA;QAET,OAAO,GAAG,EAAE;YACV,IAAI,IAAI,EAAE;gBACR,IAAI,CAAC,OAAO,EAAE,CAAA;aACf;QACH,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAEb,IAAI,SAAS,EAAE;QACb,OAAO,CACL,gCAAQ,SAAS,EAAC,WAAW;YAC3B,6BAAK,SAAS,EAAC,kCAAkC;gBAC/C,oBAAC,YAAY,IAAC,SAAS,EAAC,iDAAiD,YAE1D;gBACf,4BAAI,SAAS,EAAC,YAAY,6CAA4C;gBACtE,+BAAI,SAAS,CAAC,OAAO,CAAK,CACtB,CACC,CACV,CAAA;KACF;IAED,OAAO,CACL;QACG,SAAS,IAAI,oBAAC,SAAS,OAAG;QAC3B,6BACE,SAAS,EAAC,gBAAgB,EAC1B,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,EAAE,sBACY,KAAK,CAAC,kBAAkB,CAAC,GAC3C,CACD,CACJ,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { FormTypes } from '@oneblink/types'\nimport MapView from '@arcgis/core/views/MapView'\nimport WebMap from '@arcgis/core/WebMap'\nimport Home from '@arcgis/core/widgets/Home'\nimport Search from '@arcgis/core/widgets/Search'\nimport Zoom from '@arcgis/core/widgets/Zoom'\nimport LayerList from '@arcgis/core/widgets/LayerList'\nimport Expand from '@arcgis/core/widgets/Expand'\nimport BaseMapGallery from '@arcgis/core/widgets/BasemapGallery'\nimport OnLoading from '../components/renderer/OnLoading'\nimport MaterialIcon from './MaterialIcon'\n\nimport '../styles/arcgis-external.css'\n\ntype Props = {\n element: FormTypes.ArcGISWebMapElement\n id: string\n 'aria-describedby'?: string\n}\n\nfunction FormElementArcGISWebMap({ element, id, ...props }: Props) {\n const [loadError, setLoadError] = React.useState<Error>()\n const ref = React.useRef<HTMLDivElement | null>(null)\n const [isLoading, setIsLoading] = React.useState<boolean>(true)\n\n React.useEffect(() => {\n let view: MapView\n\n const loadMap = async () => {\n try {\n const map = new WebMap({\n portalItem: {\n id: element.webMapId,\n },\n })\n await map.load()\n\n view = new MapView({\n map: map,\n container: ref.current || undefined,\n })\n\n // remove default widgets\n const components = view.ui.getComponents()\n for (const component of components) {\n view.ui.remove(component)\n }\n\n view.ui.add(\n new Search({\n view,\n }),\n 'top-left',\n )\n view.ui.add(\n new Home({\n view,\n }),\n 'top-left',\n )\n view.ui.add(\n new Zoom({\n view,\n }),\n 'bottom-left',\n )\n\n const layerList = new LayerList({\n view,\n })\n\n view.ui.add(\n new Expand({\n expandIcon: 'layers',\n view,\n content: layerList,\n expanded: element.showLayerPanel,\n mode: 'floating',\n }),\n 'top-right',\n )\n\n const baseMapGallery = new BaseMapGallery({ view })\n\n view.ui.add(\n new Expand({\n expandIcon: 'basemap',\n view,\n content: baseMapGallery,\n mode: 'floating',\n }),\n 'bottom-right',\n )\n\n // once the view has loaded\n view.when(() => {\n setIsLoading(false)\n })\n } catch (e) {\n console.warn('Error while trying to load arcgis web map ', e)\n setLoadError(e as Error)\n setIsLoading(false)\n }\n }\n\n loadMap()\n\n return () => {\n if (view) {\n view.destroy()\n }\n }\n }, [element])\n\n if (loadError) {\n return (\n <figure className=\"ob-figure\">\n <div className=\"figure-content has-text-centered\">\n <MaterialIcon className=\"icon-large has-margin-bottom-6 has-text-warning\">\n error\n </MaterialIcon>\n <h4 className=\"title is-4\">We were unable to display your web map</h4>\n <p>{loadError.message}</p>\n </div>\n </figure>\n )\n }\n\n return (\n <>\n {isLoading && <OnLoading />}\n <div\n className=\"arcgis-web-map\"\n ref={ref}\n id={id}\n aria-describedby={props['aria-describedby']}\n />\n </>\n )\n}\n\nexport default React.memo(FormElementArcGISWebMap)\n"]}
1
+ {"version":3,"file":"ArcGISWebMap.js","sourceRoot":"","sources":["../../src/components/ArcGISWebMap.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,OAAO,MAAM,4BAA4B,CAAA;AAChD,OAAO,MAAM,MAAM,qBAAqB,CAAA;AACxC,OAAO,IAAI,MAAM,2BAA2B,CAAA;AAC5C,OAAO,MAAM,MAAM,6BAA6B,CAAA;AAChD,OAAO,IAAI,MAAM,2BAA2B,CAAA;AAC5C,OAAO,SAAS,MAAM,gCAAgC,CAAA;AACtD,OAAO,MAAM,MAAM,6BAA6B,CAAA;AAChD,OAAO,cAAc,MAAM,qCAAqC,CAAA;AAChE,OAAO,SAAS,MAAM,kCAAkC,CAAA;AACxD,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAEzC,OAAO,+BAA+B,CAAA;AACtC,OAAO,gBAAgB,MAAM,2BAA2B,CAAA;AAQxD,SAAS,uBAAuB,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,KAAK,EAAS;IAC/D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAS,CAAA;IACzD,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAwB,IAAI,CAAC,CAAA;IACrD,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAgB,IAAI,CAAC,CAAA;IACvD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAU,IAAI,CAAC,CAAA;IAC/D,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,IAAa,CAAA;QAEjB,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE;YACzB,IAAI;gBACF,MAAM,GAAG,GAAG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,OAAO,CACL;QACG,SAAS,IAAI,oBAAC,SAAS,OAAG;QAC3B,6BACE,SAAS,EAAC,gBAAgB,EAC1B,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,EAAE,sBACY,KAAK,CAAC,kBAAkB,CAAC,GAC3C,CACD,CACJ,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { FormTypes } from '@oneblink/types'\nimport MapView from '@arcgis/core/views/MapView'\nimport WebMap from '@arcgis/core/WebMap'\nimport Home from '@arcgis/core/widgets/Home'\nimport Search from '@arcgis/core/widgets/Search'\nimport Zoom from '@arcgis/core/widgets/Zoom'\nimport LayerList from '@arcgis/core/widgets/LayerList'\nimport Expand from '@arcgis/core/widgets/Expand'\nimport BaseMapGallery from '@arcgis/core/widgets/BasemapGallery'\nimport OnLoading from '../components/renderer/OnLoading'\nimport MaterialIcon from './MaterialIcon'\n\nimport '../styles/arcgis-external.css'\nimport useIsPageVisible from '../hooks/useIsPageVisible'\n\ntype Props = {\n element: FormTypes.ArcGISWebMapElement\n id: string\n 'aria-describedby'?: string\n}\n\nfunction FormElementArcGISWebMap({ element, id, ...props }: Props) {\n const [loadError, setLoadError] = React.useState<Error>()\n const ref = React.useRef<HTMLDivElement | null>(null)\n const layerPanelRef = React.useRef<Expand | null>(null)\n const [isLoading, setIsLoading] = React.useState<boolean>(true)\n const isPageVisible = useIsPageVisible()\n\n React.useEffect(() => {\n let view: MapView\n\n const loadMap = async () => {\n try {\n const map = new WebMap({\n portalItem: {\n id: element.webMapId,\n },\n })\n await map.load()\n\n view = new MapView({\n map: map,\n container: ref.current || undefined,\n })\n\n // remove default widgets\n const components = view.ui.getComponents()\n for (const component of components) {\n view.ui.remove(component)\n }\n\n view.ui.add(\n new Search({\n view,\n }),\n 'top-left',\n )\n view.ui.add(\n new Home({\n view,\n }),\n 'top-left',\n )\n view.ui.add(\n new Zoom({\n view,\n }),\n 'bottom-left',\n )\n\n const layerList = new LayerList({\n view,\n })\n\n layerPanelRef.current = new Expand({\n expandIcon: 'layers',\n view,\n content: layerList,\n expanded: element.showLayerPanel,\n mode: 'floating',\n })\n\n view.ui.add(layerPanelRef.current, 'top-right')\n\n const baseMapGallery = new BaseMapGallery({ view })\n\n view.ui.add(\n new Expand({\n expandIcon: 'basemap',\n view,\n content: baseMapGallery,\n mode: 'floating',\n }),\n 'bottom-right',\n )\n\n // once the view has loaded\n view.when(() => {\n setIsLoading(false)\n })\n } catch (e) {\n console.warn('Error while trying to load arcgis web map ', e)\n setLoadError(e as Error)\n setIsLoading(false)\n }\n }\n\n loadMap()\n\n return () => {\n if (view) {\n view.destroy()\n }\n }\n }, [element])\n\n React.useEffect(() => {\n if (isPageVisible && layerPanelRef.current) {\n layerPanelRef.current.visible = true\n } else if (!isPageVisible && layerPanelRef.current) {\n layerPanelRef.current.visible = false\n }\n }, [isPageVisible])\n\n if (loadError) {\n return (\n <figure className=\"ob-figure\">\n <div className=\"figure-content has-text-centered\">\n <MaterialIcon className=\"icon-large has-margin-bottom-6 has-text-warning\">\n error\n </MaterialIcon>\n <h4 className=\"title is-4\">We were unable to display your web map</h4>\n <p>{loadError.message}</p>\n </div>\n </figure>\n )\n }\n\n return (\n <>\n {isLoading && <OnLoading />}\n <div\n className=\"arcgis-web-map\"\n ref={ref}\n id={id}\n aria-describedby={props['aria-describedby']}\n />\n </>\n )\n}\n\nexport default React.memo(FormElementArcGISWebMap)\n"]}
@@ -78,7 +78,7 @@ children, }) {
78
78
  try {
79
79
  await draftService.syncDrafts({
80
80
  formsAppId,
81
- throwError: false,
81
+ throwError: true,
82
82
  abortSignal,
83
83
  });
84
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useDrafts.js","sourceRoot":"","sources":["../../src/hooks/useDrafts.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,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,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;QAC7C,MAAM,8BAA8B,GAClC,iBAAiB,CAAC,4BAA4B,CAAC,GAAG,EAAE,CAClD,UAAU,CAAC,SAAS,CAAC,CACtB,CAAA;QACH,MAAM,wBAAwB,GAC5B,YAAY,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAA;QAChD,OAAO,GAAG,EAAE;YACV,eAAe,CAAC,KAAK,EAAE,CAAA;YACvB,8BAA8B,EAAE,CAAA;YAChC,wBAAwB,EAAE,CAAA;QAC5B,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA;IAEhB,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;YAC7C,UAAU,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;YAClC,OAAO,GAAG,EAAE;gBACV,eAAe,CAAC,KAAK,EAAE,CAAA;YACzB,CAAC,CAAA;SACF;IACH,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAA;IAE3B,OAAO,CACL,oBAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAAG,QAAQ,CAA0B,CAC1E,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS;IAC/B,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;IAC7C,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CACb,4FAA4F,CAC7F,CAAA;KACF;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import * as React from 'react'\nimport { draftService, submissionService } from '@oneblink/apps'\nimport useAuth from './useAuth'\nimport useIsMounted from './useIsMounted'\nimport useIsOffline from './useIsOffline'\n\n/** The value returned from `useDrafts()` hook */\nexport type DraftsContextValue = {\n /** `true` if drafts are currently loading for the first time. */\n isLoading: boolean\n /** The incomplete submissions that were saved for later */\n drafts: draftService.LocalFormSubmissionDraft[]\n /** `true` drafts are syncing with other devices */\n isSyncing: boolean\n /**\n * The date when the sync process last completed successfully, will be `null`\n * until it has completed the first time.\n */\n lastSyncTime: Date | null\n /** A function to trigger syncing of the drafts */\n syncDrafts: (abortSignal: AbortSignal | undefined) => Promise<void>\n /** An Error object if syncing drafts fails */\n syncError: Error | null\n /** A function to clear Error object from syncing drafts */\n clearSyncError: () => void\n /** A function to remove a draft */\n deleteDraft: (formSubmissionDraftId: string) => Promise<void>\n}\n\nconst DraftsContext = React.createContext<DraftsContextValue | undefined>(\n undefined,\n)\n\n/**\n * React Component that provides the context for the `useDrafts()` hook to be\n * used by components further down your component tree. **It should only be\n * included in your component tree once and ideally at the root of the\n * application.**\n *\n * #### Example\n *\n * ```jsx\n * import * as React from 'react'\n * import { DraftsContextProvider, useDrafts } from '@oneblink/apps-react'\n *\n * function Component() {\n * const draftsContext = useDrafts()\n * // use drafts here\n * }\n *\n * function App() {\n * return (\n * <DraftsContextProvider>\n * <Component />\n * </DraftsContextProvider>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport function DraftsContextProvider({\n /** The identifier for the forms app associated with the user's drafts */\n formsAppId,\n /**\n * `true` if drafts are enabled, otherwise `false`. Can be used for account\n * tier validation.\n */\n isDraftsEnabled,\n /** Your application components */\n children,\n}: {\n formsAppId: number\n isDraftsEnabled: boolean\n children: React.ReactNode\n}) {\n const isMounted = useIsMounted()\n const isOffline = useIsOffline()\n const { isLoggedIn, isUsingFormsKey } = useAuth()\n\n const [syncState, setSyncState] = React.useState<{\n lastSyncTime: Date | null\n isSyncing: boolean\n syncError: Error | null\n }>({\n lastSyncTime: null,\n isSyncing: false,\n syncError: null,\n })\n const clearSyncError = React.useCallback(() => {\n setSyncState((currentState) => ({\n ...currentState,\n syncError: null,\n }))\n }, [])\n const syncDrafts = React.useCallback(\n async (abortSignal: AbortSignal | undefined) => {\n if (!isDraftsEnabled || !isLoggedIn || isUsingFormsKey) {\n return\n }\n\n if (isMounted.current) {\n setSyncState((currentState) => ({\n ...currentState,\n isSyncing: true,\n syncError: null,\n }))\n }\n\n let newError = null\n\n try {\n await draftService.syncDrafts({\n formsAppId,\n throwError: false,\n abortSignal,\n })\n } catch (error) {\n newError = error as Error\n }\n\n if (isMounted.current) {\n setSyncState({\n lastSyncTime: new Date(),\n isSyncing: false,\n syncError: newError,\n })\n }\n },\n [formsAppId, isDraftsEnabled, isLoggedIn, isMounted, isUsingFormsKey],\n )\n\n const [drafts, setDrafts] = React.useState<\n draftService.LocalFormSubmissionDraft[] | null\n >(null)\n\n const deleteDraft = React.useCallback(\n (draftId) => {\n return draftService.deleteDraft(draftId, formsAppId)\n },\n [formsAppId],\n )\n\n const value = React.useMemo<DraftsContextValue>(\n () => ({\n // Sync\n syncDrafts,\n isSyncing: syncState.isSyncing,\n syncError: syncState.syncError,\n lastSyncTime: syncState.lastSyncTime,\n clearSyncError,\n // Load\n isLoading: !drafts,\n drafts: drafts || [],\n // Delete,\n deleteDraft,\n }),\n [\n syncDrafts,\n syncState.isSyncing,\n syncState.syncError,\n syncState.lastSyncTime,\n clearSyncError,\n drafts,\n deleteDraft,\n ],\n )\n\n React.useEffect(() => {\n const abortController = new AbortController()\n const unregisterPendingQueueListener =\n submissionService.registerPendingQueueListener(() =>\n syncDrafts(undefined),\n )\n const unregisterDraftsListener =\n draftService.registerDraftsListener(setDrafts)\n return () => {\n abortController.abort()\n unregisterPendingQueueListener()\n unregisterDraftsListener()\n }\n }, [syncDrafts])\n\n React.useEffect(() => {\n if (!isOffline) {\n const abortController = new AbortController()\n syncDrafts(abortController.signal)\n return () => {\n abortController.abort()\n }\n }\n }, [isOffline, syncDrafts])\n\n return (\n <DraftsContext.Provider value={value}>{children}</DraftsContext.Provider>\n )\n}\n\n/**\n * React hook to get the context value for Drafts. Will throw an Error if used\n * outside of the `<DraftsContextProvider />` component.\n *\n * @returns\n * @group Hooks\n */\nexport default function useDrafts(): DraftsContextValue {\n const value = React.useContext(DraftsContext)\n if (!value) {\n throw new Error(\n `\"useDrafts\" hook was used outside of the \"<DraftsContextProvider />\" component's children.`,\n )\n }\n return value\n}\n"]}
1
+ {"version":3,"file":"useDrafts.js","sourceRoot":"","sources":["../../src/hooks/useDrafts.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAyBzC,MAAM,aAAa,GAAG,KAAK,CAAC,aAAa,CACvC,SAAS,CACV,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,qBAAqB,CAAC;AACpC,yEAAyE;AACzE,UAAU;AACV;;;GAGG;AACH,eAAe;AACf,kCAAkC;AAClC,QAAQ,GAKT;IACC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,OAAO,EAAE,CAAA;IAEjD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAI7C;QACD,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,IAAI;KAChB,CAAC,CAAA;IACF,MAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QAC5C,YAAY,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;YAC9B,GAA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EAAE,KAAK,IAAG,QAAQ,CAA0B,CAC1E,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS;IAC/B,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;IAC7C,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CACb,4FAA4F,CAC7F,CAAA;KACF;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import * as React from 'react'\nimport { draftService, submissionService } from '@oneblink/apps'\nimport useAuth from './useAuth'\nimport useIsMounted from './useIsMounted'\nimport useIsOffline from './useIsOffline'\n\n/** The value returned from `useDrafts()` hook */\nexport type DraftsContextValue = {\n /** `true` if drafts are currently loading for the first time. */\n isLoading: boolean\n /** The incomplete submissions that were saved for later */\n drafts: draftService.LocalFormSubmissionDraft[]\n /** `true` drafts are syncing with other devices */\n isSyncing: boolean\n /**\n * The date when the sync process last completed successfully, will be `null`\n * until it has completed the first time.\n */\n lastSyncTime: Date | null\n /** A function to trigger syncing of the drafts */\n syncDrafts: (abortSignal: AbortSignal | undefined) => Promise<void>\n /** An Error object if syncing drafts fails */\n syncError: Error | null\n /** A function to clear Error object from syncing drafts */\n clearSyncError: () => void\n /** A function to remove a draft */\n deleteDraft: (formSubmissionDraftId: string) => Promise<void>\n}\n\nconst DraftsContext = React.createContext<DraftsContextValue | undefined>(\n undefined,\n)\n\n/**\n * React Component that provides the context for the `useDrafts()` hook to be\n * used by components further down your component tree. **It should only be\n * included in your component tree once and ideally at the root of the\n * application.**\n *\n * #### Example\n *\n * ```jsx\n * import * as React from 'react'\n * import { DraftsContextProvider, useDrafts } from '@oneblink/apps-react'\n *\n * function Component() {\n * const draftsContext = useDrafts()\n * // use drafts here\n * }\n *\n * function App() {\n * return (\n * <DraftsContextProvider>\n * <Component />\n * </DraftsContextProvider>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport function DraftsContextProvider({\n /** The identifier for the forms app associated with the user's drafts */\n formsAppId,\n /**\n * `true` if drafts are enabled, otherwise `false`. Can be used for account\n * tier validation.\n */\n isDraftsEnabled,\n /** Your application components */\n children,\n}: {\n formsAppId: number\n isDraftsEnabled: boolean\n children: React.ReactNode\n}) {\n const isMounted = useIsMounted()\n const isOffline = useIsOffline()\n const { isLoggedIn, isUsingFormsKey } = useAuth()\n\n const [syncState, setSyncState] = React.useState<{\n lastSyncTime: Date | null\n isSyncing: boolean\n syncError: Error | null\n }>({\n lastSyncTime: null,\n isSyncing: false,\n syncError: null,\n })\n const clearSyncError = React.useCallback(() => {\n setSyncState((currentState) => ({\n ...currentState,\n syncError: null,\n }))\n }, [])\n const syncDrafts = React.useCallback(\n async (abortSignal: AbortSignal | undefined) => {\n if (!isDraftsEnabled || !isLoggedIn || isUsingFormsKey) {\n return\n }\n\n if (isMounted.current) {\n setSyncState((currentState) => ({\n ...currentState,\n isSyncing: true,\n syncError: null,\n }))\n }\n\n let newError = null\n\n try {\n await draftService.syncDrafts({\n formsAppId,\n throwError: true,\n abortSignal,\n })\n } catch (error) {\n newError = error as Error\n }\n\n if (isMounted.current) {\n setSyncState({\n lastSyncTime: new Date(),\n isSyncing: false,\n syncError: newError,\n })\n }\n },\n [formsAppId, isDraftsEnabled, isLoggedIn, isMounted, isUsingFormsKey],\n )\n\n const [drafts, setDrafts] = React.useState<\n draftService.LocalFormSubmissionDraft[] | null\n >(null)\n\n const deleteDraft = React.useCallback(\n (draftId) => {\n return draftService.deleteDraft(draftId, formsAppId)\n },\n [formsAppId],\n )\n\n const value = React.useMemo<DraftsContextValue>(\n () => ({\n // Sync\n syncDrafts,\n isSyncing: syncState.isSyncing,\n syncError: syncState.syncError,\n lastSyncTime: syncState.lastSyncTime,\n clearSyncError,\n // Load\n isLoading: !drafts,\n drafts: drafts || [],\n // Delete,\n deleteDraft,\n }),\n [\n syncDrafts,\n syncState.isSyncing,\n syncState.syncError,\n syncState.lastSyncTime,\n clearSyncError,\n drafts,\n deleteDraft,\n ],\n )\n\n React.useEffect(() => {\n const abortController = new AbortController()\n const unregisterPendingQueueListener =\n submissionService.registerPendingQueueListener(() =>\n syncDrafts(undefined),\n )\n const unregisterDraftsListener =\n draftService.registerDraftsListener(setDrafts)\n return () => {\n abortController.abort()\n unregisterPendingQueueListener()\n unregisterDraftsListener()\n }\n }, [syncDrafts])\n\n React.useEffect(() => {\n if (!isOffline) {\n const abortController = new AbortController()\n syncDrafts(abortController.signal)\n return () => {\n abortController.abort()\n }\n }\n }, [isOffline, syncDrafts])\n\n return (\n <DraftsContext.Provider value={value}>{children}</DraftsContext.Provider>\n )\n}\n\n/**\n * React hook to get the context value for Drafts. Will throw an Error if used\n * outside of the `<DraftsContextProvider />` component.\n *\n * @returns\n * @group Hooks\n */\nexport default function useDrafts(): DraftsContextValue {\n const value = React.useContext(DraftsContext)\n if (!value) {\n throw new Error(\n `\"useDrafts\" hook was used outside of the \"<DraftsContextProvider />\" component's children.`,\n )\n }\n return value\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oneblink/apps-react",
3
3
  "description": "Helper functions for OneBlink apps in ReactJS.",
4
- "version": "6.0.0-beta.2",
4
+ "version": "6.0.0-beta.4",
5
5
  "author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/oneblink/apps-react/issues"