diff --git a/static/js/components/filePreview.js b/static/js/components/filePreview.js index 0d31b75..f3e7f4e 100644 --- a/static/js/components/filePreview.js +++ b/static/js/components/filePreview.js @@ -66,7 +66,7 @@ export class FilePreview { } async previewFile(file) { - const contentDiv = document.getElementById(`${this.options.containerId}Content`); + const contentDiv = document.getElementById('filePreviewContent'); const extension = file.name.split('.').pop().toLowerCase(); // Show loading spinner diff --git a/static/js/file-grid.js b/static/js/file-grid.js index 2f7043e..6854e25 100644 --- a/static/js/file-grid.js +++ b/static/js/file-grid.js @@ -9,6 +9,28 @@ * - File details display */ +import { FilePreview } from './components/filePreview.js'; + +/** + * Formats a file size in bytes to a human-readable string. + * @param {number} bytes - The file size in bytes + * @returns {string} Formatted file size string + */ +function formatFileSize(bytes) { + if (!bytes) return '0 B'; + + const units = ['B', 'KB', 'MB', 'GB', 'TB']; + let size = bytes; + let unitIndex = 0; + + while (size >= 1024 && unitIndex < units.length - 1) { + size /= 1024; + unitIndex++; + } + + return `${size.toFixed(1)} ${units[unitIndex]}`; +} + let currentView = 'grid'; let lastSelectedIndex = -1; let sortColumn = 'name'; // Set default sort column to name @@ -21,6 +43,14 @@ window.isAdmin = document.body.dataset.isAdmin === 'true'; // Check if we're on the trash page const isTrashPage = window.location.pathname.includes('/trash'); +// Initialize FilePreview component +const filePreview = new FilePreview({ + containerId: 'filePreviewModal', + onClose: () => { + // Clean up any resources if needed + } +}); + /** * Initializes the file view and fetches files. * Sets up the preferred view and initial file sorting. @@ -189,17 +219,31 @@ function renderFiles(files) { ${isTrashPage ? `