From 915b71297c05dc5c18c8186ea35c6f6500cf6201 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Fri, 10 Nov 2023 22:22:46 -0600 Subject: [PATCH] Post toast when overwriting photo EXIF data --- src/app/(auth-state)/admin/photos/page.tsx | 3 ++ src/components/SubmitButtonWithStatus.tsx | 38 +++++++++++++++------- src/photo/PhotoEditPageClient.tsx | 2 -- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/app/(auth-state)/admin/photos/page.tsx b/src/app/(auth-state)/admin/photos/page.tsx index ba81c851..b94e7fed 100644 --- a/src/app/(auth-state)/admin/photos/page.tsx +++ b/src/app/(auth-state)/admin/photos/page.tsx @@ -125,6 +125,9 @@ export default async function AdminTagsPage({ } + onFormSubmitToastMessage={` + "${titleForPhoto(photo)}" EXIF data synced + `} /> { icon?: JSX.Element styleAsLink?: boolean spinnerColor?: SpinnerColor + onFormSubmitToastMessage?: string } -export default function SubmitButtonWithStatus(props: Props) { - const { - icon, - styleAsLink, - spinnerColor, - children, - disabled, - className, - type: _type, - ...buttonProps - } = props; +export default function SubmitButtonWithStatus({ + icon, + styleAsLink, + spinnerColor, + onFormSubmitToastMessage, + children, + disabled, + className, + type: _type, + ...buttonProps +}: Props) { const { pending } = useFormStatus(); + const pendingPrevious = useRef(pending); + + useEffect(() => { + if ( + pendingPrevious.current && + !pending && + onFormSubmitToastMessage + ) { + toastSuccess(onFormSubmitToastMessage); + } + pendingPrevious.current = pending; + }, [pending, onFormSubmitToastMessage]); return (