mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-21 05:10:41 +00:00
feat: enhance backup and download functionalities
- Updated `BackupCenterPage` to support download progress tracking during remote backup downloads. - Modified `ImportPage` to simplify export functionality by removing unnecessary payload handling. - Improved `JwtWarningPage` to utilize a new clipboard utility for copying text with feedback. - Enhanced `PublicSendPage` to show download progress for files being downloaded. - Updated `RecoverTwoFactorPage` to include autocomplete attributes for better user experience. - Refactored `SendsPage` to use the new clipboard utility for copying access URLs. - Enhanced `SettingsPage` to utilize the clipboard utility for copying sensitive information. - Improved `TotpCodesPage` to use the clipboard utility for copying TOTP codes. - Updated `VaultPage` and related components to support download progress for attachments. - Introduced a new `app-notify` module for consistent notification handling across the application. - Created a `clipboard` utility for improved clipboard interactions with user feedback. - Added progress tracking for file downloads in the API layer, enhancing user experience during downloads.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { dispatchAppNotify } from '@/lib/app-notify';
|
||||
import { t } from '@/lib/i18n';
|
||||
|
||||
interface CopyTextOptions {
|
||||
successMessage?: string;
|
||||
errorMessage?: string;
|
||||
emptyMessage?: string;
|
||||
notify?: boolean;
|
||||
onSuccess?: () => void;
|
||||
onError?: () => void;
|
||||
}
|
||||
|
||||
export async function copyTextToClipboard(value: string, options: CopyTextOptions = {}): Promise<boolean> {
|
||||
const text = String(value || '');
|
||||
if (!text.trim()) {
|
||||
if (options.notify !== false) {
|
||||
dispatchAppNotify('warning', options.emptyMessage || t('txt_nothing_to_copy'));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
options.onSuccess?.();
|
||||
if (options.notify !== false) {
|
||||
dispatchAppNotify('success', options.successMessage || t('txt_copied'));
|
||||
}
|
||||
return true;
|
||||
} catch {
|
||||
options.onError?.();
|
||||
if (options.notify !== false) {
|
||||
dispatchAppNotify('error', options.errorMessage || t('txt_copy_failed'));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user