UNPKG

@helpwave/hightide

Version:

helpwave's component and theming library

68 lines (67 loc) 2.35 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); // src/hooks/useSaveDelay.ts var useSaveDelay_exports = {}; __export(useSaveDelay_exports, { useSaveDelay: () => useSaveDelay }); module.exports = __toCommonJS(useSaveDelay_exports); var import_react = require("react"); function useSaveDelay(setNotificationStatus, delay) { const [updateTimer, setUpdateTimer] = (0, import_react.useState)(void 0); const [notificationTimer, setNotificationTimer] = (0, import_react.useState)(void 0); const restartTimer = (onSave) => { clearTimeout(updateTimer); setUpdateTimer(setTimeout(() => { onSave(); setNotificationStatus(true); clearTimeout(notificationTimer); setNotificationTimer(setTimeout(() => { setNotificationStatus(false); clearTimeout(notificationTimer); }, delay)); clearTimeout(updateTimer); }, delay)); }; const clearUpdateTimer = (hasSaved = true) => { clearTimeout(updateTimer); if (hasSaved) { setNotificationStatus(true); clearTimeout(notificationTimer); setNotificationTimer(setTimeout(() => { setNotificationStatus(false); clearTimeout(notificationTimer); }, delay)); } else { setNotificationStatus(false); } }; (0, import_react.useEffect)(() => { return () => { clearTimeout(updateTimer); clearTimeout(notificationTimer); }; }, []); return { restartTimer, clearUpdateTimer }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { useSaveDelay }); //# sourceMappingURL=useSaveDelay.js.map