Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Refactor (#2413)

Leendert de Borstf6e9c780c0bb
diff --git a/apps/web/src/components/settings/importexport/ImportServiceCard.tsx b/apps/web/src/components/settings/importexport/ImportServiceCard.tsx
index 368b753ea..86e8e1b1f 100644
--- a/apps/web/src/components/settings/importexport/ImportServiceCard.tsx
+++ b/apps/web/src/components/settings/importexport/ImportServiceCard.tsx
@@ -16,6 +16,7 @@ import { useNotifications } from '@/context/NotificationContext';
import { useWebApi } from '@/context/WebApiContext';
import { useVaultMutate } from '@/hooks/useVaultMutate';
import { delay } from '@/utils/Delay';
+import { formatBytes } from '@/utils/FormatBytes';
import type { FaviconTarget } from '@aliasvault/client/rust/RustCore';
import type { ImportedCredential } from '@aliasvault/client/transfer/import/models/ImportedCredential';
@@ -87,21 +88,6 @@ const yieldToPaint = (): Promise<void> =>
setTimeout(resolve, 100);
});
-/**
- * Format a byte count to human readable format (e.g. "3.9 MB").
- * @param bytes - the byte count
- */
-const formatBytes = (bytes: number): string => {
- const units = ['B', 'KB', 'MB', 'GB', 'TB'];
- let size = bytes;
- let unitIndex = 0;
- while (size >= 1024 && unitIndex < units.length - 1) {
- size /= 1024;
- unitIndex++;
- }
- return unitIndex === 0 ? `${Math.round(size)} ${units[unitIndex]}` : `${(Math.round(size * 10) / 10).toString()} ${units[unitIndex]}`;
-};
-
/**
* One line naming an error: its class name when that says more than "Error", then the message.
* @param error - the thrown value, which from wasm or a library is not always an Error
diff --git a/apps/web/src/components/shared/Modal.tsx b/apps/web/src/components/shared/Modal.tsx
index 0c78f031d..2496d97d6 100644
--- a/apps/web/src/components/shared/Modal.tsx
+++ b/apps/web/src/components/shared/Modal.tsx
@@ -27,10 +27,13 @@ const Modal: React.FC<ModalProps> = ({ children, id, panelRef, panelClassName =
};
return (
- <div className={`fixed inset-0 ${zIndexClass} overflow-y-auto bg-gray-600/50 backdrop-blur-sm dark:bg-black/80`} onKeyDown={onKeyDown}>
- <div className={`flex min-h-full justify-center p-4 ${position === 'top' ? 'items-start pt-40 pb-8' : 'items-center'}`} onClick={handleBackdropClick}>
- <div ref={panelRef} id={id} tabIndex={tabIndex} className={`relative rounded-lg border border-gray-200 bg-white shadow-xl dark:border-gray-600 dark:bg-gray-800 dark:shadow-2xl ${panelClassName}`}>
- {children}
+ <div className={`fixed inset-0 ${zIndexClass}`} onKeyDown={onKeyDown}>
+ <div className="fixed inset-0 bg-gray-600/50 backdrop-blur-sm dark:bg-black/80" />
+ <div className="fixed inset-0 overflow-y-auto">
+ <div className={`flex min-h-full justify-center p-4 ${position === 'top' ? 'items-start pt-40 pb-8' : 'items-center'}`} onClick={handleBackdropClick}>
+ <div ref={panelRef} id={id} tabIndex={tabIndex} className={`relative rounded-lg border border-gray-200 bg-white shadow-xl dark:border-gray-600 dark:bg-gray-800 dark:shadow-2xl ${panelClassName}`}>
+ {children}
+ </div>
</div>
</div>
</div>
diff --git a/apps/web/src/utils/FormatBytes.ts b/apps/web/src/utils/FormatBytes.ts
new file mode 100644
index 000000000..838597c72
--- /dev/null
+++ b/apps/web/src/utils/FormatBytes.ts
@@ -0,0 +1,14 @@
+/**
+ * Format a byte count for display, e.g. "3.9 MB".
+ * @param bytes - the byte count
+ */
+export const formatBytes = (bytes: number): string => {
+ const units = ['B', 'KB', 'MB', 'GB', 'TB'];
+ let size = bytes;
+ let unitIndex = 0;
+ while (size >= 1024 && unitIndex < units.length - 1) {
+ size /= 1024;
+ unitIndex++;
+ }
+ return unitIndex === 0 ? `${Math.round(size)} ${units[unitIndex]}` : `${(Math.round(size * 10) / 10).toString()} ${units[unitIndex]}`;
+};