UNPKG

@wordpress/editor

Version:
62 lines (60 loc) 2.28 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/editor/src/components/sync-connection-error-modal/use-retry-countdown.ts var use_retry_countdown_exports = {}; __export(use_retry_countdown_exports, { useRetryCountdown: () => useRetryCountdown }); module.exports = __toCommonJS(use_retry_countdown_exports); var import_element = require("@wordpress/element"); function useRetryCountdown(connectionStatus) { const [secondsRemaining, setSecondsRemaining] = (0, import_element.useState)(); (0, import_element.useEffect)(() => { if (!connectionStatus) { return; } if ("connected" === connectionStatus.status) { setSecondsRemaining(void 0); return; } if ("disconnected" !== connectionStatus.status || !connectionStatus.willAutoRetryInMs) { return; } const { willAutoRetryInMs: retryInMs } = connectionStatus; const retryAt = Date.now() + retryInMs; setSecondsRemaining(Math.ceil(retryInMs / 1e3)); const intervalId = setInterval(() => { const remaining = Math.ceil((retryAt - Date.now()) / 1e3); setSecondsRemaining(Math.max(0, remaining)); if (remaining <= 0) { clearInterval(intervalId); } }, 1e3); return () => clearInterval(intervalId); }, [connectionStatus]); return { onManualRetry: () => setSecondsRemaining(0), secondsRemaining }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { useRetryCountdown }); //# sourceMappingURL=use-retry-countdown.cjs.map