Fix admin nav count count after upload

This commit is contained in:
Sam Becker 2024-04-01 10:25:40 -05:00
parent 4ea4c030e3
commit 81b0d797b7
2 changed files with 13 additions and 5 deletions

View File

@ -34,6 +34,7 @@ import SubmitButtonWithStatus from '@/components/SubmitButtonWithStatus';
import IconGrSync from '@/site/IconGrSync';
import { getStoragePhotoUrlsNoStore } from '@/services/storage/cache';
import PhotoDate from '@/photo/PhotoDate';
import { revalidatePath } from 'next/cache';
const DEBUG_PHOTO_BLOBS = false;
@ -58,7 +59,14 @@ export default async function AdminPhotosPage({
<SiteGrid
contentMain={
<div className="space-y-8">
<PhotoUpload shouldResize={!PRO_MODE_ENABLED} />
<PhotoUpload
shouldResize={!PRO_MODE_ENABLED}
onLastUpload={async () => {
'use server';
// Update upload count in admin nav
revalidatePath('/admin', 'layout');
}}
/>
{blobPhotoUrls.length > 0 &&
<div className={clsx(
'border-b pb-6',

View File

@ -9,9 +9,11 @@ import { clsx } from 'clsx/lite';
export default function PhotoUpload({
shouldResize,
onLastUpload,
debug,
}: {
shouldResize?: boolean
onLastUpload?: () => Promise<void>
debug?: boolean
}) {
const [isUploading, setIsUploading] = useState(false);
@ -55,11 +57,9 @@ export default function PhotoUpload({
blob,
extension,
)
.then(url => {
.then(async url => {
if (isLastBlob) {
// Refresh page to update upload list,
// relevant to upload count in nav
router.refresh();
await onLastUpload?.();
if (hasMultipleUploads) {
// Redirect to view multiple uploads
router.push(PATH_ADMIN_UPLOADS);