@@ -51,12 +56,12 @@ export default function ImageInput({
htmlFor={INPUT_ID}
className={clsx(
'shrink-0 select-none text-main',
- loading && 'pointer-events-none cursor-not-allowed',
+ isUploading && 'pointer-events-none cursor-not-allowed',
)}
>
1
? (fileUploadIndex + 1) / filesLength * 0.95
: undefined}
@@ -64,12 +69,12 @@ export default function ImageInput({
size={18}
className="translate-x-[-0.5px] translate-y-[0.5px]"
/>}
- aria-disabled={loading}
+ aria-disabled={isUploading}
onClick={() => inputRef.current?.click()}
hideTextOnMobile={false}
primary
>
- {loading
+ {isUploading
? filesLength > 1
? `Uploading ${fileUploadIndex + 1} of ${filesLength}`
: 'Uploading'
@@ -81,17 +86,19 @@ export default function ImageInput({
type="file"
className="hidden!"
accept={ACCEPTED_PHOTO_FILE_TYPES.join(',')}
- disabled={loading}
+ disabled={isUploading}
multiple
onChange={async e => {
onStart?.();
const { files } = e.currentTarget;
if (files && files.length > 0) {
- setFilesLength(files.length);
+ setUploadState?.({ filesLength: files.length });
for (let i = 0; i < files.length; i++) {
const file = files[i];
- setFileUploadIndex(i);
- setFileUploadName(file.name);
+ setUploadState?.({
+ fileUploadIndex: i,
+ fileUploadName: file.name,
+ });
const callbackArgs = {
extension: file.name.split('.').pop()?.toLowerCase(),
hasMultipleUploads: files.length > 1,
@@ -111,7 +118,7 @@ export default function ImageInput({
// Process images that need resizing
const image = await blobToImage(file);
- setImage(image);
+ setUploadState?.({ image });
ctx.save();
diff --git a/src/components/more/MoreMenuItem.tsx b/src/components/more/MoreMenuItem.tsx
index fe54671d..26e82c37 100644
--- a/src/components/more/MoreMenuItem.tsx
+++ b/src/components/more/MoreMenuItem.tsx
@@ -74,17 +74,21 @@ export default function MoreMenuItem({
});
}
}
- if (href && href !== pathname) {
- if (hrefDownloadName) {
- setIsLoading(true);
- downloadFileFromBrowser(href, hrefDownloadName)
- .finally(() => {
- setIsLoading(false);
- dismissMenu?.();
- });
+ if (href) {
+ if (href !== pathname) {
+ if (hrefDownloadName) {
+ setIsLoading(true);
+ downloadFileFromBrowser(href, hrefDownloadName)
+ .finally(() => {
+ setIsLoading(false);
+ dismissMenu?.();
+ });
+ } else {
+ setTransitionDidStart(true);
+ startTransition(() => router.push(href));
+ }
} else {
- setTransitionDidStart(true);
- startTransition(() => router.push(href));
+ dismissMenu?.();
}
}
}}
diff --git a/src/photo/PhotoUpload.tsx b/src/photo/PhotoUpload.tsx
index 1e1b7717..6ebacf17 100644
--- a/src/photo/PhotoUpload.tsx
+++ b/src/photo/PhotoUpload.tsx
@@ -1,32 +1,31 @@
'use client';
-import { useState } from 'react';
import { uploadPhotoFromClient } from '@/platforms/storage';
import { useRouter } from 'next/navigation';
import { PATH_ADMIN_UPLOADS, pathForAdminUploadUrl } from '@/app/paths';
import ImageInput from '../components/ImageInput';
import { clsx } from 'clsx/lite';
+import { useAppState } from '@/state/AppState';
export default function PhotoUpload({
shouldResize,
onLastUpload,
- isUploading,
- setIsUploading,
showUploadStatus,
debug,
}: {
shouldResize?: boolean
onLastUpload?: () => Promise
- isUploading: boolean
- setIsUploading: (isUploading: boolean) => void
showUploadStatus?: boolean
debug?: boolean
}) {
- const [uploadError, setUploadError] = useState();
- const [debugDownload, setDebugDownload] = useState<{
- href: string
- fileName: string
- }>();
+ const {
+ uploadState: {
+ isUploading,
+ uploadError,
+ debugDownload,
+ },
+ setUploadState,
+ } = useAppState();
const router = useRouter();
@@ -38,11 +37,12 @@ export default function PhotoUpload({