diff --git a/package.json b/package.json index 5a93613..ad9af48 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "skate-spots", "private": true, - "version": "1.0.75", + "version": "1.0.76", "type": "module", "homepage": "https://skate-spots.com", "scripts": { diff --git a/src/pages/CreateSpotPage.tsx b/src/pages/CreateSpotPage.tsx index 83d8326..ec86096 100644 --- a/src/pages/CreateSpotPage.tsx +++ b/src/pages/CreateSpotPage.tsx @@ -61,6 +61,9 @@ export default function CreateSpotPage() { const [images, setImages] = useState([]); const [isGettingLocation, setIsGettingLocation] = useState(false); const [showCamera, setShowCamera] = useState(false); + // True while the Quick Snap photo is uploading in the background after landing + // on this form. + const [isUploadingQuickPhoto, setIsUploadingQuickPhoto] = useState(false); // Pre-fill coordinates from URL params (from map click) useEffect(() => { @@ -74,12 +77,44 @@ export default function CreateSpotPage() { // Check for quick capture image from map page const quickCapture = searchParams.get('quickCapture'); if (quickCapture === 'true') { + // Backward-compat: an already-uploaded URL (old flow). const capturedImage = sessionStorage.getItem('quickCaptureImage'); if (capturedImage) { setImages([capturedImage]); sessionStorage.removeItem('quickCaptureImage'); } + + // New Quick Snap flow: a raw photo (data URL) stashed by the map page. + // We navigate here immediately for speed, then upload the photo HERE so a + // slow/failed Blossom upload never strands the user before the form. + const pendingPhoto = sessionStorage.getItem('quickCapturePendingPhoto'); + if (pendingPhoto) { + sessionStorage.removeItem('quickCapturePendingPhoto'); + (async () => { + setIsUploadingQuickPhoto(true); + try { + const res = await fetch(pendingPhoto); + const blob = await res.blob(); + const file = new File([blob], `skate-spot-${Date.now()}.jpg`, { type: 'image/jpeg' }); + const uploadTags = await uploadFile(file); + const url = uploadTags[0]?.[1]; + if (url) { + setImages((prev) => (prev.includes(url) ? prev : [...prev, url])); + } + } catch (error) { + toast({ + title: 'Photo upload failed', + description: + error instanceof Error ? error.message : 'Could not upload the photo. You can add one below.', + variant: 'destructive', + }); + } finally { + setIsUploadingQuickPhoto(false); + } + })(); + } } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [searchParams]); const handleCategoryChange = (category: string) => { @@ -600,6 +635,13 @@ export default function CreateSpotPage() { ))} + {/* Quick Snap photo uploading in the background */} + {isUploadingQuickPhoto && ( +
+ + Uploading photo… +
+ )} {/* Camera capture button */}