'use client'; import { OUTDATED_THRESHOLD, Photo } from '@/photo'; import AdminPhotosTable from '@/admin/AdminPhotosTable'; import LoaderButton from '@/components/primitives/LoaderButton'; import IconGrSync from '@/site/IconGrSync'; import Note from '@/components/Note'; import AdminChildPage from '@/components/AdminChildPage'; import { PATH_ADMIN_PHOTOS } from '@/site/paths'; import { useState } from 'react'; import { syncPhotosAction } from '@/photo/actions'; import { useRouter } from 'next/navigation'; import ResponsiveText from '@/components/primitives/ResponsiveText'; const UPDATE_BATCH_SIZE_MAX = 4; export default function AdminOutdatedClient({ photos, hasAiTextGeneration, }: { photos: Photo[] hasAiTextGeneration: boolean }) { const updateBatchSize = Math.min(UPDATE_BATCH_SIZE_MAX, photos.length); const [photoIdsSyncing, setPhotoIdsSyncing] = useState([]); const arePhotoIdsSyncing = photoIdsSyncing.length > 0; const router = useRouter(); return ( Outdated ({photos.length}) Outdated } accessory={} hideTextOnMobile={false} onClick={async () => { if (window.confirm( // eslint-disable-next-line max-len `Are you sure you want to sync the oldest ${updateBatchSize} photos? This action cannot be undone.`, )) { const photosToSync = photos .slice(0, updateBatchSize) .map(photo => photo.id); const isFinalBatch = photosToSync.length >= photos.length; setPhotoIdsSyncing(photosToSync); syncPhotosAction(photosToSync) .finally(() => { if (isFinalBatch) { router.push(PATH_ADMIN_PHOTOS); } else { setPhotoIdsSyncing([]); router.refresh(); } }); } }} isLoading={arePhotoIdsSyncing} > {arePhotoIdsSyncing ? 'Syncing' : Sync Next {updateBatchSize} Photos } } >
{photos.length} {' '} {photos.length === 1 ? 'photo' : 'photos'} {' ('}last updated before {' '} {new Date(OUTDATED_THRESHOLD).toLocaleDateString()}{')'} {' '} may have: missing EXIF fields, inaccurate blur data, {' '} undesired privacy settings {hasAiTextGeneration && ', missing AI-generated text'}
); }