| 1 | import { loader } from './action-loader.js'; |
| 2 | |
| 3 | /** |
| 4 | * Handle for the legacy loader created by showLoader(). |
| 5 | * @type {import('./action-loader.js').ActionLoaderHandle|null} |
| 6 | */ |
| 7 | let legacyLoaderHandle = null; |
| 8 | |
| 9 | /** |
| 10 | * Shows the loader overlay. |
| 11 | * |
| 12 | * @deprecated Use `showActionLoader()` from action-loader.js instead. |
| 13 | * This function now creates a blocking action loader with no toast. |
| 14 | * The new system supports stacking multiple loaders and provides better control. |
| 15 | * |
| 16 | * @example |
| 17 | * // New recommended approach: |
| 18 | * import { showActionLoader } from './action-loader.js'; |
| 19 | * const handle = showActionLoader({ message: 'Loading...' }); |
| 20 | * // ... do work ... |
| 21 | * handle.hide(); |
| 22 | */ |
| 23 | export function showLoader() { |
| 24 | // Hide any existing legacy loader first to maintain old behavior |
| 25 | if (legacyLoaderHandle && legacyLoaderHandle.isActive) { |
| 26 | legacyLoaderHandle.hide(); |
| 27 | } |
| 28 | |
| 29 | // Create a blocking loader with no toast (matches old behavior) |
| 30 | legacyLoaderHandle = loader.show({ |
| 31 | slug: 'legacy-loader', |
| 32 | blocking: true, |
| 33 | toastMode: loader.ToastMode.NONE, |
| 34 | }); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Hides the loader overlay. |
| 39 | * |
| 40 | * @deprecated Use `hideActionLoader()` or `handle.hide()` from action-loader.js instead. |
| 41 | * This function now hides the legacy loader created by showLoader(). |
| 42 | * |
| 43 | * @example |
| 44 | * // New recommended approach: |
| 45 | * import { showActionLoader } from './action-loader.js'; |
| 46 | * const handle = showActionLoader({ message: 'Loading...' }); |
| 47 | * // ... do work ... |
| 48 | * await handle.hide(); |
| 49 | * |
| 50 | * @returns {Promise<void>} |
| 51 | */ |
| 52 | export async function hideLoader() { |
| 53 | if (!legacyLoaderHandle || !legacyLoaderHandle.isActive) { |
| 54 | console.warn('There is no loader showing to hide'); |
| 55 | return Promise.resolve(); |
| 56 | } |
| 57 | |
| 58 | await legacyLoaderHandle.hide(); |
| 59 | legacyLoaderHandle = null; |
| 60 | } |