diff --git a/server/index.js b/server/index.js index 3baeed8..650e216 100755 --- a/server/index.js +++ b/server/index.js @@ -820,6 +820,14 @@ app.get('*', (req, res) => { res.sendFile(path.join(__dirname, '../dist/index.html')); }); +// Helper function to convert permissions to rwx format +function permToRwx(perm) { + const r = perm & 4 ? 'r' : '-'; + const w = perm & 2 ? 'w' : '-'; + const x = perm & 1 ? 'x' : '-'; + return r + w + x; +} + async function getFileTree(dirPath, maxDepth = 3, currentDepth = 0, showHidden = true) { // Using fsPromises from import const items = []; @@ -836,12 +844,34 @@ async function getFileTree(dirPath, maxDepth = 3, currentDepth = 0, showHidden = entry.name === 'dist' || entry.name === 'build') continue; + const itemPath = path.join(dirPath, entry.name); const item = { name: entry.name, - path: path.join(dirPath, entry.name), + path: itemPath, type: entry.isDirectory() ? 'directory' : 'file' }; + // Get file stats for additional metadata + try { + const stats = await fsPromises.stat(itemPath); + item.size = stats.size; + item.modified = stats.mtime.toISOString(); + + // Convert permissions to rwx format + const mode = stats.mode; + const ownerPerm = (mode >> 6) & 7; + const groupPerm = (mode >> 3) & 7; + const otherPerm = mode & 7; + item.permissions = ((mode >> 6) & 7).toString() + ((mode >> 3) & 7).toString() + (mode & 7).toString(); + item.permissionsRwx = permToRwx(ownerPerm) + permToRwx(groupPerm) + permToRwx(otherPerm); + } catch (statError) { + // If stat fails, provide default values + item.size = 0; + item.modified = null; + item.permissions = '000'; + item.permissionsRwx = '---------'; + } + if (entry.isDirectory() && currentDepth < maxDepth) { // Recursively get subdirectories but limit depth try { diff --git a/src/components/FileTree.jsx b/src/components/FileTree.jsx index c2328db..1048bdb 100755 --- a/src/components/FileTree.jsx +++ b/src/components/FileTree.jsx @@ -1,7 +1,7 @@ import React, { useState, useEffect } from 'react'; import { ScrollArea } from './ui/scroll-area'; import { Button } from './ui/button'; -import { Folder, FolderOpen, File, FileText, FileCode } from 'lucide-react'; +import { Folder, FolderOpen, File, FileText, FileCode, List, TableProperties, Eye } from 'lucide-react'; import { cn } from '../lib/utils'; import CodeEditor from './CodeEditor'; import ImageViewer from './ImageViewer'; @@ -13,6 +13,7 @@ function FileTree({ selectedProject }) { const [expandedDirs, setExpandedDirs] = useState(new Set()); const [selectedFile, setSelectedFile] = useState(null); const [selectedImage, setSelectedImage] = useState(null); + const [viewMode, setViewMode] = useState('detailed'); // 'simple', 'detailed', 'compact' useEffect(() => { if (selectedProject) { @@ -20,6 +21,14 @@ function FileTree({ selectedProject }) { } }, [selectedProject]); + // Load view mode preference from localStorage + useEffect(() => { + const savedViewMode = localStorage.getItem('file-tree-view-mode'); + if (savedViewMode && ['simple', 'detailed', 'compact'].includes(savedViewMode)) { + setViewMode(savedViewMode); + } + }, []); + const fetchFiles = async () => { setLoading(true); try { @@ -52,6 +61,35 @@ function FileTree({ selectedProject }) { setExpandedDirs(newExpanded); }; + // Change view mode and save preference + const changeViewMode = (mode) => { + setViewMode(mode); + localStorage.setItem('file-tree-view-mode', mode); + }; + + // Format file size + const formatFileSize = (bytes) => { + if (!bytes || bytes === 0) return '0 B'; + const k = 1024; + const sizes = ['B', 'KB', 'MB', 'GB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]; + }; + + // Format date as relative time + const formatRelativeTime = (date) => { + if (!date) return '-'; + const now = new Date(); + const past = new Date(date); + const diffInSeconds = Math.floor((now - past) / 1000); + + if (diffInSeconds < 60) return 'just now'; + if (diffInSeconds < 3600) return `${Math.floor(diffInSeconds / 60)} min ago`; + if (diffInSeconds < 86400) return `${Math.floor(diffInSeconds / 3600)} hours ago`; + if (diffInSeconds < 2592000) return `${Math.floor(diffInSeconds / 86400)} days ago`; + return past.toLocaleDateString(); + }; + const renderFileTree = (items, level = 0) => { return items.map((item) => (