Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 69 additions & 26 deletions client/src/components/Home/MyFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ import {
Play,
AlertCircle,
MoreVertical,
FileVideo,
FileAudio,
FileImage,
FileCode,
Check,
} from "lucide-react";
import { motion, AnimatePresence } from "framer-motion";
import { notify as toast } from "@/services/toastService";
Expand Down Expand Up @@ -1103,26 +1108,64 @@ formatFileSize


// βœ… Get file icon based on type
function getFileIcon(type: string) {
switch (type) {
case "image":
return <ImageIcon className="w-5 h-5" />;
case "application":
return <FileText className="w-5 h-5" />;
default:
return <File className="w-5 h-5" />;
}
function getFileIcon(type: string, fileName?: string) {
const ext = fileName?.split(".").pop()?.toLowerCase();

// Check by extension first for specificity
if (ext === "pdf") return <FileText className="w-5 h-5" />;
if (["doc", "docx"].includes(ext || "")) return <FileText className="w-5 h-5" />;
if (["xls", "xlsx"].includes(ext || "")) return <FileText className="w-5 h-5" />;
if (["ppt", "pptx"].includes(ext || "")) return <FileText className="w-5 h-5" />;
if (["txt", "md", "csv"].includes(ext || "")) return <FileText className="w-5 h-5" />;
if (["html", "css", "js", "ts", "jsx", "tsx", "json"].includes(ext || "")) return <FileCode className="w-5 h-5" />;
if (["mp3", "wav", "ogg", "flac", "aac"].includes(ext || "")) return <FileAudio className="w-5 h-5" />;
if (["mp4", "mov", "avi", "mkv", "webm"].includes(ext || "")) return <FileVideo className="w-5 h-5" />;
if (["jpg", "jpeg", "png", "gif", "webp", "svg", "bmp"].includes(ext || "")) return <FileImage className="w-5 h-5" />;

// Fallback to MIME type category
switch (type) {
case "image":
return <FileImage className="w-5 h-5" />;
case "video":
return <FileVideo className="w-5 h-5" />;
case "audio":
return <FileAudio className="w-5 h-5" />;
case "text":
return <FileText className="w-5 h-5" />;
case "application":
return <FileText className="w-5 h-5" />;
default:
return <File className="w-5 h-5" />;
}
}

// βœ… Get file type color
const getFileTypeColor = (type: string) => {
const getFileTypeColor = (type: string, fileName?: string) => {
const ext = fileName?.split(".").pop()?.toLowerCase();

// Specific extension colors
if (ext === "pdf") return "#e74c3c";
if (["doc", "docx"].includes(ext || "")) return "#2980b9";
if (["xls", "xlsx"].includes(ext || "")) return "#27ae60";
if (["ppt", "pptx"].includes(ext || "")) return "#e67e22";
if (["txt", "md", "csv"].includes(ext || "")) return "#95a5a6";
if (["html", "css", "js", "ts", "jsx", "tsx", "json"].includes(ext || "")) return "#f39c12";
if (["mp3", "wav", "ogg", "flac", "aac"].includes(ext || "")) return "#9b59b6";
if (["mp4", "mov", "avi", "mkv", "webm"].includes(ext || "")) return "#e74c3c";
if (["jpg", "jpeg", "png", "gif", "webp", "svg", "bmp"].includes(ext || "")) return "#3498db";

// Fallback to MIME type category
switch (type) {
case "image":
return "#3498db";
case "application":
return "#2ecc71";
case "video":
return "#e74c3c";
case "audio":
return "#9b59b6";
case "text":
return "#95a5a6";
case "application":
return "#2ecc71";
default:
return "#9b59b6";
}
Expand Down Expand Up @@ -1787,11 +1830,11 @@ formatFileSize
<div
className="w-full h-full flex items-center justify-center"
style={{
backgroundColor: `${getFileTypeColor(file.type)}20`,
backgroundColor: `${getFileTypeColor(file.type, file.name)}20`,
}}
>
<div style={{ color: getFileTypeColor(file.type) }}>
{getFileIcon(file.type)}
<div style={{ color: getFileTypeColor(file.type, file.name) }}>
{getFileIcon(file.type, file.name)}
</div>
</div>
)}
Expand Down Expand Up @@ -1885,11 +1928,11 @@ formatFileSize
<div
className="p-1.5 rounded-lg mr-2 shrink-0"
style={{
backgroundColor: `${getFileTypeColor(file.type)}20`,
backgroundColor: `${getFileTypeColor(file.type, file.name)}20`,
}}
>
<div style={{ color: getFileTypeColor(file.type) }}>
{getFileIcon(file.type)}
<div style={{ color: getFileTypeColor(file.type, file.name) }}>
{getFileIcon(file.type, file.name)}
</div>
</div>
<h3 className="text-sm font-medium text-white truncate flex-1">
Expand Down Expand Up @@ -2084,11 +2127,11 @@ formatFileSize
<div
className="p-2 rounded-lg mr-3"
style={{
backgroundColor: `${getFileTypeColor(file.type)}20`,
backgroundColor: `${getFileTypeColor(file.type, file.name)}20`,
}}
>
<div style={{ color: getFileTypeColor(file.type) }}>
{getFileIcon(file.type)}
<div style={{ color: getFileTypeColor(file.type, file.name) }}>
{getFileIcon(file.type, file.name)}
</div>
</div>
<div>
Expand Down Expand Up @@ -2144,8 +2187,8 @@ formatFileSize
<span
className="px-2 py-1 rounded text-xs font-medium"
style={{
backgroundColor: `${getFileTypeColor(file.type)}20`,
color: getFileTypeColor(file.type),
backgroundColor: `${getFileTypeColor(file.type, file.name)}20`,
color: getFileTypeColor(file.type, file.name),
}}
>
{file.type.toUpperCase()}
Expand Down Expand Up @@ -2337,11 +2380,11 @@ formatFileSize
<div
className="p-2 rounded-lg mr-3"
style={{
backgroundColor: `${getFileTypeColor(file.type)}20`,
backgroundColor: `${getFileTypeColor(file.type, file.name)}20`,
}}
>
<div style={{ color: getFileTypeColor(file.type) }}>
{getFileIcon(file.type)}
<div style={{ color: getFileTypeColor(file.type, file.name) }}>
{getFileIcon(file.type, file.name)}
</div>
</div>
<div>
Expand Down
Loading