@dhis2/app-service-offline 3.10.0 → 3.10.1

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.
@@ -186,6 +186,16 @@ const Dhis2ConnectionStatusProvider = (_ref) => {
186
186
  };
187
187
  }, [pingAndHandleStatus, serverVersion]);
188
188
  (0, _react.useEffect)(() => {
189
+ if (!offlineInterface.subscribeToDhis2ConnectionStatus) {
190
+ var _smartIntervalRef$cur3;
191
+
192
+ // Missing this functionality from the offline interface --
193
+ // use a ping on startup to get the status
194
+ (_smartIntervalRef$cur3 = smartIntervalRef.current) === null || _smartIntervalRef$cur3 === void 0 ? void 0 : _smartIntervalRef$cur3.invokeCallbackImmediately();
195
+ console.warn('Please upgrade to @dhis2/cli-app-scripts@>10.3.8 for full connection status features');
196
+ return;
197
+ }
198
+
189
199
  const unsubscribe = offlineInterface.subscribeToDhis2ConnectionStatus({
190
200
  onUpdate
191
201
  });
@@ -194,18 +204,21 @@ const Dhis2ConnectionStatusProvider = (_ref) => {
194
204
  };
195
205
  }, [offlineInterface, onUpdate]); // Memoize this value to prevent unnecessary rerenders of context provider
196
206
 
197
- const contextValue = (0, _react.useMemo)(() => ({
207
+ const contextValue = (0, _react.useMemo)(() => {
198
208
  // in the unlikely circumstance that offlineInterface.latestIsConnected
199
- // is `null` when this initializes, fail safe by defaulting to
200
- // `isConnected: false`
201
- isConnected: Boolean(isConnected),
202
- isDisconnected: !isConnected,
203
- lastConnected: isConnected ? null : // Only evaluate if disconnected, since local storage
204
- // is synchronous and disk-based.
205
- // If lastConnected is not set in localStorage though, set it.
206
- // (relevant on startup)
207
- getLastConnected(appName) || updateLastConnected(appName)
208
- }), [isConnected, appName]);
209
+ // is `null` or `undefined` when this initializes, fail safe by defaulting to
210
+ // `isConnected: true`. A ping or SW update should update the status shortly.
211
+ const validatedIsConnected = isConnected !== null && isConnected !== void 0 ? isConnected : true;
212
+ return {
213
+ isConnected: validatedIsConnected,
214
+ isDisconnected: !validatedIsConnected,
215
+ lastConnected: validatedIsConnected ? null : // Only evaluate if disconnected, since local storage
216
+ // is synchronous and disk-based.
217
+ // If lastConnected is not set in localStorage though, set it.
218
+ // (relevant on startup)
219
+ getLastConnected(appName) || updateLastConnected(appName)
220
+ };
221
+ }, [isConnected, appName]);
209
222
  return /*#__PURE__*/_react.default.createElement(Dhis2ConnectionStatusContext.Provider, {
210
223
  value: contextValue
211
224
  }, children);
@@ -162,9 +162,9 @@ describe('initialization to the right values based on offline interface', () =>
162
162
  } = (0, _reactHooks.renderHook)(() => (0, _dhis2ConnectionStatus.useDhis2ConnectionStatus)(), {
163
163
  wrapper: customWrapper
164
164
  });
165
- expect(result.current.isConnected).toBe(false);
166
- expect(result.current.isDisconnected).toBe(true);
167
- expect(result.current.lastConnected).toEqual(testCurrentDate);
165
+ expect(result.current.isConnected).toBe(true);
166
+ expect(result.current.isDisconnected).toBe(false);
167
+ expect(result.current.lastConnected).toBe(null);
168
168
  });
169
169
  });
170
170
  describe('interval behavior', () => {
@@ -160,6 +160,16 @@ export const Dhis2ConnectionStatusProvider = (_ref) => {
160
160
  };
161
161
  }, [pingAndHandleStatus, serverVersion]);
162
162
  useEffect(() => {
163
+ if (!offlineInterface.subscribeToDhis2ConnectionStatus) {
164
+ var _smartIntervalRef$cur3;
165
+
166
+ // Missing this functionality from the offline interface --
167
+ // use a ping on startup to get the status
168
+ (_smartIntervalRef$cur3 = smartIntervalRef.current) === null || _smartIntervalRef$cur3 === void 0 ? void 0 : _smartIntervalRef$cur3.invokeCallbackImmediately();
169
+ console.warn('Please upgrade to @dhis2/cli-app-scripts@>10.3.8 for full connection status features');
170
+ return;
171
+ }
172
+
163
173
  const unsubscribe = offlineInterface.subscribeToDhis2ConnectionStatus({
164
174
  onUpdate
165
175
  });
@@ -168,18 +178,21 @@ export const Dhis2ConnectionStatusProvider = (_ref) => {
168
178
  };
169
179
  }, [offlineInterface, onUpdate]); // Memoize this value to prevent unnecessary rerenders of context provider
170
180
 
171
- const contextValue = useMemo(() => ({
181
+ const contextValue = useMemo(() => {
172
182
  // in the unlikely circumstance that offlineInterface.latestIsConnected
173
- // is `null` when this initializes, fail safe by defaulting to
174
- // `isConnected: false`
175
- isConnected: Boolean(isConnected),
176
- isDisconnected: !isConnected,
177
- lastConnected: isConnected ? null : // Only evaluate if disconnected, since local storage
178
- // is synchronous and disk-based.
179
- // If lastConnected is not set in localStorage though, set it.
180
- // (relevant on startup)
181
- getLastConnected(appName) || updateLastConnected(appName)
182
- }), [isConnected, appName]);
183
+ // is `null` or `undefined` when this initializes, fail safe by defaulting to
184
+ // `isConnected: true`. A ping or SW update should update the status shortly.
185
+ const validatedIsConnected = isConnected !== null && isConnected !== void 0 ? isConnected : true;
186
+ return {
187
+ isConnected: validatedIsConnected,
188
+ isDisconnected: !validatedIsConnected,
189
+ lastConnected: validatedIsConnected ? null : // Only evaluate if disconnected, since local storage
190
+ // is synchronous and disk-based.
191
+ // If lastConnected is not set in localStorage though, set it.
192
+ // (relevant on startup)
193
+ getLastConnected(appName) || updateLastConnected(appName)
194
+ };
195
+ }, [isConnected, appName]);
183
196
  return /*#__PURE__*/React.createElement(Dhis2ConnectionStatusContext.Provider, {
184
197
  value: contextValue
185
198
  }, children);
@@ -152,9 +152,9 @@ describe('initialization to the right values based on offline interface', () =>
152
152
  } = renderHook(() => useDhis2ConnectionStatus(), {
153
153
  wrapper: customWrapper
154
154
  });
155
- expect(result.current.isConnected).toBe(false);
156
- expect(result.current.isDisconnected).toBe(true);
157
- expect(result.current.lastConnected).toEqual(testCurrentDate);
155
+ expect(result.current.isConnected).toBe(true);
156
+ expect(result.current.isDisconnected).toBe(false);
157
+ expect(result.current.lastConnected).toBe(null);
158
158
  });
159
159
  });
160
160
  describe('interval behavior', () => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dhis2/app-service-offline",
3
3
  "description": "A runtime service for online/offline detection and offline caching",
4
- "version": "3.10.0",
4
+ "version": "3.10.1",
5
5
  "main": "./build/cjs/index.js",
6
6
  "module": "./build/es/index.js",
7
7
  "types": "build/types/index.d.ts",
@@ -33,7 +33,7 @@
33
33
  "coverage": "yarn test --coverage"
34
34
  },
35
35
  "peerDependencies": {
36
- "@dhis2/app-service-config": "3.10.0",
36
+ "@dhis2/app-service-config": "3.10.1",
37
37
  "prop-types": "^15.7.2",
38
38
  "react": "^16.8.6",
39
39
  "react-dom": "^16.8.6"