4df18ccb0b
* feat: add slug parameter to action-loader for programmatic identification
Add optional `slug` parameter to ActionLoaderHandle for easier identification via code or CSS. Update all loader.show() calls across the codebase to include descriptive slugs ('app-init', 'chat-rename', 'chat-delete', 'bulk-delete', 'chat-load', 'image-generation', 'legacy-loader'). Add data attributes (data-slug, data-loader-id, data-blocking) to toast content div. Expose slug via getter and make id private with getter.
* Apply suggestions from code review
Fix slug jsdoc wording
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* fix: Add identifier to second loader in img gen
---------
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
import { loader } from './action-loader.js';
|
|
|
|
/**
|
|
* Handle for the legacy loader created by showLoader().
|
|
* @type {import('./action-loader.js').ActionLoaderHandle|null}
|
|
*/
|
|
let legacyLoaderHandle = null;
|
|
|
|
/**
|
|
* Shows the loader overlay.
|
|
*
|
|
* @deprecated Use `showActionLoader()` from action-loader.js instead.
|
|
* This function now creates a blocking action loader with no toast.
|
|
* The new system supports stacking multiple loaders and provides better control.
|
|
*
|
|
* @example
|
|
* // New recommended approach:
|
|
* import { showActionLoader } from './action-loader.js';
|
|
* const handle = showActionLoader({ message: 'Loading...' });
|
|
* // ... do work ...
|
|
* handle.hide();
|
|
*/
|
|
export function showLoader() {
|
|
// Hide any existing legacy loader first to maintain old behavior
|
|
if (legacyLoaderHandle && legacyLoaderHandle.isActive) {
|
|
legacyLoaderHandle.hide();
|
|
}
|
|
|
|
// Create a blocking loader with no toast (matches old behavior)
|
|
legacyLoaderHandle = loader.show({
|
|
slug: 'legacy-loader',
|
|
blocking: true,
|
|
toastMode: loader.ToastMode.NONE,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Hides the loader overlay.
|
|
*
|
|
* @deprecated Use `hideActionLoader()` or `handle.hide()` from action-loader.js instead.
|
|
* This function now hides the legacy loader created by showLoader().
|
|
*
|
|
* @example
|
|
* // New recommended approach:
|
|
* import { showActionLoader } from './action-loader.js';
|
|
* const handle = showActionLoader({ message: 'Loading...' });
|
|
* // ... do work ...
|
|
* await handle.hide();
|
|
*
|
|
* @returns {Promise<void>}
|
|
*/
|
|
export async function hideLoader() {
|
|
if (!legacyLoaderHandle || !legacyLoaderHandle.isActive) {
|
|
console.warn('There is no loader showing to hide');
|
|
return Promise.resolve();
|
|
}
|
|
|
|
await legacyLoaderHandle.hide();
|
|
legacyLoaderHandle = null;
|
|
}
|