'use client'; import { useViewMedia } from '../../hooks/useViewMedia'; import { findDuplicateGroups } from '../../lib/grouping'; import { Icon } from '../../icons'; import { useGallery, useGalleryStoreApi } from '../../store/context'; import { albumById } from '../../store/selectors'; import { MediaGrid } from '../MediaGrid'; import { PhotoTile } from '../PhotoTile'; import { EmptyState } from './EmptyState'; const EMPTY_COPY: Record = { favourites: { title: 'No Favourites', subtitle: 'Tap the heart on a photo to add it here.', icon: 'heart' }, 'recently-saved': { title: 'Nothing Saved Yet', subtitle: 'Downloaded and shared media will appear here.', icon: 'download' }, videos: { title: 'No Videos', subtitle: 'Imported videos will appear here.', icon: 'video' }, screenshots: { title: 'No Screenshots', subtitle: 'Screenshots are detected automatically on import.', icon: 'screenshot' }, search: { title: 'Search Your Library', subtitle: 'Search by name, place, tag or detected object.', icon: 'search' }, }; /** Generic grid screen for the simple filtered views. */ export function GridScreen() { const items = useViewMedia(); const view = useGallery((s) => s.view); if (items.length === 0) { const copy = EMPTY_COPY[view] ?? { title: 'No Items', subtitle: '', icon: 'image' }; return ; } return (
); } export function AlbumView() { const view = useGallery((s) => s.view); const albums = useGallery((s) => s.albums); const items = useViewMedia(); const album = albumById(albums, view); return (
{album?.name ?? 'Album'}
{items.length} item{items.length === 1 ? '' : 's'}
{items.length === 0 ? ( ) : ( )}
); } export function SharedAlbumsView() { const api = useGalleryStoreApi(); const shares = useGallery((s) => s.shares); const media = useGallery((s) => s.media); if (shares.length === 0) { return ( ); } return (
Shared Albums
{shares.map((sh) => { const cover = media.find((m) => m.id === sh.mediaIds[0]); return (
{cover ? : }
{sh.title}
{sh.mediaIds.length}
); })}
); } export function ActivityView() { const shares = useGallery((s) => s.shares); if (shares.length === 0) { return ( ); } return (
Activity
{shares.map((sh) => (
You shared “{sh.title}”
{sh.mediaIds.length} item{sh.mediaIds.length === 1 ? '' : 's'} ·{' '} {formatRelative(sh.createdAt)}
))}
); } function formatRelative(ts: number): string { const diff = Date.now() - ts; const min = Math.round(diff / 60000); if (min < 1) return 'just now'; if (min < 60) return `${min} min ago`; const hr = Math.round(min / 60); if (hr < 24) return `${hr} hr ago`; return `${Math.round(hr / 24)} day(s) ago`; } export function DuplicatesView() { const api = useGalleryStoreApi(); const media = useGallery((s) => s.media); const groups = findDuplicateGroups(media); if (groups.length === 0) { return ( ); } return (
{groups.length} Duplicate Group{groups.length === 1 ? '' : 's'}
{groups.map((group, i) => (
{group.slice(0, 4).map((m) => ( g.id)} /> ))}
))}
); }