import { useState, useEffect } from 'react'; import { X, ArrowLeft, Wand2 } from 'lucide-react'; import Masonry from 'react-masonry-css'; // Function to get last modified date from filename for sorting const getDateFromFilename = (filename) => { // Extract date if it's in the format "chrome-study - YYYY-MM-DDTHHMMSS" const dateMatch = filename.match(/chrome-study - (\d{4}-\d{2}-\d{2}T\d{6})/); if (dateMatch) { return new Date(dateMatch[1].replace('T', 'T').slice(0, 19)); } // Extract number if it's in the format "chrome-study (XX)" or "chrome-study-XX" const numMatch = filename.match(/chrome-study[- ]\(?(\d+)/); if (numMatch) { return Number.parseInt(numMatch[1], 10); } return 0; // Default value for sorting }; const LibraryPage = ({ onBack, onUseAsTemplate }) => { const [images, setImages] = useState([]); const [fullscreenImage, setFullscreenImage] = useState(null); const [isLoading, setIsLoading] = useState(true); const [hoveredImage, setHoveredImage] = useState(null); // Breakpoint columns configuration for the masonry layout const breakpointColumnsObj = { default: 4, 1100: 3, 700: 2, 500: 1 }; useEffect(() => { // Function to get all images from the library folder const fetchImages = async () => { try { // Simulate fetching the list of images // In a real app, you would fetch this from an API const imageFiles = [ "chrome-study (17).png", "chrome-study (19).png", "chrome-study (27).png", "chrome-study (43).png", "chrome-study (47).png", "chrome-study (48).png", "chrome-study (55).png", "chrome-study (56).png", "chrome-study (58).png", "chrome-study (62).png", "chrome-study (64).png", "chrome-study (72).png", "chrome-study (76).png", "chrome-study (77).png", "chrome-study (78).png", "chrome-study (79).png", "chrome-study (81).png", "chrome-study (83).png", "chrome-study (84).png", "chrome-study (86).png", "chrome-study (87).png", "chrome-study (92).png", "chrome-study (94).png", "chrome-study (95).png", "chrome-study (98).png", "chrome-study (99).png", "chrome-study - 2025-03-29T231111.407.png", "chrome-study - 2025-03-29T231628.676.png", "chrome-study - 2025-03-29T231852.687.png", "chrome-study - 2025-03-29T232157.263.png", "chrome-study - 2025-03-29T232601.690.png", "chrome-study - 2025-03-29T235802.886.png", "chrome-study - 2025-03-30T000256.137.png", "chrome-study - 2025-03-30T000847.148.png", "chrome-study - 2025-03-30T001126.978.png", "chrome-study - 2025-03-30T001518.410.png", "chrome-study - 2025-03-30T002129.834.png", "chrome-study - 2025-03-30T002928.187.png", "chrome-study - 2025-03-30T003503.053.png", "chrome-study - 2025-03-30T003713.255.png", "chrome-study - 2025-03-30T003942.300.png", "chrome-study - 2025-03-30T011127.402.png", "chrome-study-11.png", "chrome-study-6.png" ]; // Sort images by "newest" (using filename to guess date/order) // In a real app, you would have actual metadata const sortedImages = imageFiles.sort((a, b) => { const dateA = getDateFromFilename(a); const dateB = getDateFromFilename(b); return dateB - dateA; // Descending order }); setImages(sortedImages); setIsLoading(false); } catch (error) { console.error("Error fetching library images:", error); setIsLoading(false); } }; fetchImages(); }, []); const handleImageClick = (imagePath) => { setFullscreenImage(imagePath); }; const handleKeyDown = (event, imagePath) => { if (event.key === 'Enter' || event.key === ' ') { setFullscreenImage(imagePath); } }; return (
{/* Fixed header section */}
{/* Simple Header */}
Submit by replying to this{" "}tweet
{/* Content with padding to account for fixed header */}
{/* Loading state */} {isLoading && (
)} {/* Masonry grid of images */} {images.map((image, index) => (
)}
))} {/* No images state */} {!isLoading && images.length === 0 && (

No images in library

Create some images to see them here

)}
{/* Fullscreen image modal */} {fullscreenImage && (
Fullscreen view
)} ); }; export default LibraryPage;