hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import type { JSX } from "solid-js"; |
| 2 | import { |
| 3 | IconFileAudio, |
| 4 | IconFileImage, |
| 5 | IconFileSpreadsheet, |
| 6 | IconFileText, |
| 7 | IconFileVideo, |
| 8 | IconNote, |
| 9 | } from "@/components/ui/icons"; |
| 10 | |
| 11 | export function fileExtension(name: string): string { |
| 12 | const ext = name.split(".").pop()?.toLowerCase(); |
| 13 | return ext && ext !== name.toLowerCase() ? ext : "file"; |
| 14 | } |
| 15 | |
| 16 | export type FileTypeMeta = { label: string; class: string; icon: JSX.Element }; |
| 17 | |
| 18 | /** Icon + badge color for a file, by content type / extension — shared across notes and homework file lists. */ |
| 19 | export function fileTypeMeta(file: { name: string; content_type: string }, iconClass = "h-5 w-5"): FileTypeMeta { |
| 20 | const type = file.content_type.toLowerCase(); |
| 21 | const ext = fileExtension(file.name); |
| 22 | if (type.startsWith("image/")) return { label: ext, class: "border-sky-500/25 bg-sky-500/10 text-sky-700 dark:text-sky-300", icon: <IconFileImage class={iconClass} /> }; |
| 23 | if (type.startsWith("video/")) return { label: ext, class: "border-violet-500/25 bg-violet-500/10 text-violet-700 dark:text-violet-300", icon: <IconFileVideo class={iconClass} /> }; |
| 24 | if (type.startsWith("audio/")) return { label: ext, class: "border-fuchsia-500/25 bg-fuchsia-500/10 text-fuchsia-700 dark:text-fuchsia-300", icon: <IconFileAudio class={iconClass} /> }; |
| 25 | if (type === "application/pdf" || ext === "pdf") return { label: "pdf", class: "border-rose-500/25 bg-rose-500/10 text-rose-700 dark:text-rose-300", icon: <IconFileText class={iconClass} /> }; |
| 26 | if (["xls", "xlsx", "csv"].includes(ext) || type.includes("spreadsheet")) return { label: ext, class: "border-emerald-500/25 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300", icon: <IconFileSpreadsheet class={iconClass} /> }; |
| 27 | if (["doc", "docx", "txt", "md", "rtf"].includes(ext) || type.startsWith("text/") || type.includes("word")) return { label: ext, class: "border-blue-500/25 bg-blue-500/10 text-blue-700 dark:text-blue-300", icon: <IconFileText class={iconClass} /> }; |
| 28 | return { label: ext, class: "border-border bg-background text-muted-foreground", icon: <IconNote class={iconClass} /> }; |
| 29 | } |