diff --git a/src/components/image-alt-display.tsx b/src/components/image-alt-display.tsx index 4688097..e880f66 100644 --- a/src/components/image-alt-display.tsx +++ b/src/components/image-alt-display.tsx @@ -7,6 +7,13 @@ import { Label } from "@/components/ui/label"; import { Badge } from "@/components/ui/badge"; import { ImageOff } from "lucide-react"; import { formatBytes } from "@/lib/utils"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; interface ImageAltDisplayProps { images: ImageAltData[]; @@ -15,6 +22,9 @@ interface ImageAltDisplayProps { export function ImageAltDisplay({ images }: ImageAltDisplayProps) { const [showMissingOnly, setShowMissingOnly] = useState(false); const [imageErrors, setImageErrors] = useState>({}); + const [sortOrder, setSortOrder] = useState<"default" | "asc" | "desc">( + "default" + ); const missingAltCount = images.filter((img) => !img.alt).length; @@ -22,6 +32,25 @@ export function ImageAltDisplay({ images }: ImageAltDisplayProps) { ? images.filter((img) => !img.alt) : images; + const sortedAndFilteredImages = [...filteredImages].sort((a, b) => { + if (sortOrder === "default") { + return 0; + } + + const sizeA = a.size; + const sizeB = b.size; + + if (sizeA === null && sizeB === null) return 0; + if (sizeA === null) return 1; + if (sizeB === null) return -1; + + if (sortOrder === "asc") { + return sizeA - sizeB; + } else { + return sizeB - sizeA; + } + }); + const handleImageError = (src: string) => { setImageErrors((prev) => ({ ...prev, [src]: true })); }; @@ -36,13 +65,35 @@ export function ImageAltDisplay({ images }: ImageAltDisplayProps) { return (
-
- setShowMissingOnly(!!checked)} - /> - +
+
+ setShowMissingOnly(!!checked)} + /> + +
+
+ + +
{missingAltCount > 0 ? ( @@ -58,7 +109,7 @@ export function ImageAltDisplay({ images }: ImageAltDisplayProps) {
- {filteredImages.map((image, index) => ( + {sortedAndFilteredImages.map((image, index) => (