Refine bulk updating experience
This commit is contained in:
parent
d16881637e
commit
bd9b33422f
@ -5,7 +5,7 @@ import AdminPhotosTable from '@/admin/AdminPhotosTable';
|
|||||||
import Note from '@/components/Note';
|
import Note from '@/components/Note';
|
||||||
import AdminChildPage from '@/components/AdminChildPage';
|
import AdminChildPage from '@/components/AdminChildPage';
|
||||||
import { PATH_ADMIN_PHOTOS } from '@/app/path';
|
import { PATH_ADMIN_PHOTOS } from '@/app/path';
|
||||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { syncPhotosAction } from '@/photo/actions';
|
import { syncPhotosAction } from '@/photo/actions';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import ResponsiveText from '@/components/primitives/ResponsiveText';
|
import ResponsiveText from '@/components/primitives/ResponsiveText';
|
||||||
@ -32,16 +32,16 @@ export default function AdminPhotosUpdateClient({
|
|||||||
const errorRef = useRef<Error>(undefined);
|
const errorRef = useRef<Error>(undefined);
|
||||||
|
|
||||||
// Use state for updating progress button and error UI
|
// Use state for updating progress button and error UI
|
||||||
|
const [statusText, setStatusText] =
|
||||||
|
useState(getPhotosUpdateStatusText(photos));
|
||||||
const [photoIdsSyncing, setPhotoIdsSyncing] = useState<string[]>([]);
|
const [photoIdsSyncing, setPhotoIdsSyncing] = useState<string[]>([]);
|
||||||
const [error, setError] = useState<Error>();
|
|
||||||
const [progress, setProgress] = useState(0);
|
const [progress, setProgress] = useState(0);
|
||||||
|
const [error, setError] = useState<Error>();
|
||||||
|
|
||||||
const arePhotoIdsSyncing = photoIdsSyncing.length > 0;
|
const arePhotoIdsSyncing = photoIdsSyncing.length > 0;
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const statusText = useMemo(() => getPhotosUpdateStatusText(photos), [photos]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (photos.length === 0 && !error && !errorRef.current) {
|
if (photos.length === 0 && !error && !errorRef.current) {
|
||||||
router.push(PATH_ADMIN_PHOTOS);
|
router.push(PATH_ADMIN_PHOTOS);
|
||||||
@ -88,6 +88,8 @@ export default function AdminPhotosUpdateClient({
|
|||||||
photoIdsToSync.current = photoIdsToSync.current.filter(
|
photoIdsToSync.current = photoIdsToSync.current.filter(
|
||||||
id => !photoIds.includes(id),
|
id => !photoIds.includes(id),
|
||||||
);
|
);
|
||||||
|
setStatusText(getPhotosUpdateStatusText(photos
|
||||||
|
.filter(({ id }) => photoIdsToSync.current.includes(id))));
|
||||||
setProgress(
|
setProgress(
|
||||||
(photos.length - photoIdsToSync.current.length) /
|
(photos.length - photoIdsToSync.current.length) /
|
||||||
photos.length,
|
photos.length,
|
||||||
@ -127,11 +129,17 @@ export default function AdminPhotosUpdateClient({
|
|||||||
>
|
>
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<div className="font-bold">
|
<div className="font-bold">
|
||||||
Photo updates: {statusText}
|
{arePhotoIdsSyncing
|
||||||
|
? <>Updating photos: {statusText}</>
|
||||||
|
: <>Photo updates: {statusText}</>}
|
||||||
</div>
|
</div>
|
||||||
Sync to capture new EXIF fields, optimize image data,
|
{arePhotoIdsSyncing
|
||||||
{' '}
|
? <>Leave browser open until updates complete</>
|
||||||
use AI to generate missing text (if configured)
|
: <>
|
||||||
|
Sync to capture new EXIF fields, optimize image data,
|
||||||
|
{' '}
|
||||||
|
use AI to generate missing text (if configured)
|
||||||
|
</>}
|
||||||
</div>
|
</div>
|
||||||
</Note>
|
</Note>
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
|
|||||||
@ -52,7 +52,10 @@ export default function PhotoSyncButton({
|
|||||||
: 'Regenerate photo data'}>
|
: 'Regenerate photo data'}>
|
||||||
<LoaderButton
|
<LoaderButton
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={clsx('scroll-mt-8', className)}
|
className={clsx(
|
||||||
|
'scroll-mt-32',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
icon={updateMode
|
icon={updateMode
|
||||||
? <IconBroom size={18} />
|
? <IconBroom size={18} />
|
||||||
: <IconGrSync
|
: <IconGrSync
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user