@atlaskit/editor-plugin-synced-block
Version:
SyncedBlock plugin for @atlaskit/editor-core
29 lines (28 loc) • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SyncBlockRefresher = void 0;
var _react = require("react");
var _hooks = require("@atlaskit/editor-common/hooks");
var _editorPluginConnectivity = require("@atlaskit/editor-plugin-connectivity");
// Component that manages synced block data synchronization.
// Uses provider-based GraphQL subscriptions for updates when online.
// Falls back to polling at regular intervals when offline.
var SyncBlockRefresher = exports.SyncBlockRefresher = function SyncBlockRefresher(_ref) {
var syncBlockStoreManager = _ref.syncBlockStoreManager,
api = _ref.api;
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['connectivity'], function (states) {
var _states$connectivityS;
return {
mode: (_states$connectivityS = states.connectivityState) === null || _states$connectivityS === void 0 ? void 0 : _states$connectivityS.mode
};
}),
mode = _useSharedPluginState.mode;
var isOnline = !(0, _editorPluginConnectivity.isOfflineMode)(mode);
(0, _react.useEffect)(function () {
var useRealTimeSubscriptions = isOnline;
syncBlockStoreManager.referenceManager.setRealTimeSubscriptionsEnabled(useRealTimeSubscriptions);
}, [syncBlockStoreManager, isOnline]);
return null;
};