// Gallery.jsx - a grid of thumbnails for folders that are mostly pictures. // // The thumbnail is the file itself: bkn has no image resizing, so a gallery of // 40 photos is 40 full downloads. loading="lazy" keeps that to what is on // screen, and the grid caps how many are on screen at once. If galleries of // hundreds of photos become normal, the fix is a resize endpoint in bkn, not a // cleverer grid. function Gallery({ entries, busy, onOpen, onPreview, downloadURL }) { if (busy) { return (
Loading…
); } if (!entries.length) return ; return (
{entries.map(e => ( ))}
); } const IMAGE_EXT = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'avif', 'bmp', 'svg', 'ico']; function isImage(entry) { if (!entry || entry.kind !== 'file') return false; if ((entry.content_type || '').startsWith('image/')) return true; const dot = entry.name.lastIndexOf('.'); if (dot < 0) return false; return IMAGE_EXT.includes(entry.name.slice(dot + 1).toLowerCase()); } // A folder of photos should open in the gallery without anyone choosing it, // and a folder of documents should not. function looksLikeAGallery(entries) { const files = entries.filter(e => e.kind === 'file'); if (files.length < 3) return false; return files.filter(isImage).length / files.length >= 0.6; } function ViewToggle({ view, onChange }) { const opts = [ { key: 'list', label: 'List', icon: 'drive' }, { key: 'gallery', label: 'Gallery', icon: 'folder' }, ]; return (
{opts.map(o => ( ))}
); }