import { useState } from 'react'; import { Link } from 'react-router-dom'; import { useAuth } from '@picobaas/client/react'; import { useImages } from '../hooks/useImages'; import { PUBLIC_BUCKET } from '../config'; import ImageUploader from '../components/ImageUploader'; import type { UploadOptions } from '../types'; export default function HomePage() { const { isAuthenticated } = useAuth(); const { uploadImage } = useImages(PUBLIC_BUCKET); const [isUploading, setIsUploading] = useState(false); const [uploadResult, setUploadResult] = useState<{ success: boolean; url?: string; error?: string; } | null>(null); const handleUpload = async (file: File, options: UploadOptions) => { setIsUploading(true); setUploadResult(null); try { const image = await uploadImage(file, options); if (image) { // Use short URL if available, otherwise fall back to raw URL const shareUrl = image.shortUrl ? `${window.location.origin}${image.shortUrl}` : image.url; setUploadResult({ success: true, url: shareUrl }); } } catch (err) { setUploadResult({ success: false, error: err instanceof Error ? err.message : 'Upload failed', }); } finally { setIsUploading(false); } }; const copyToClipboard = async (url: string) => { try { await navigator.clipboard.writeText(url); alert('Link copied to clipboard!'); } catch { // Fallback const input = document.createElement('input'); input.value = url; document.body.appendChild(input); input.select(); document.execCommand('copy'); document.body.removeChild(input); alert('Link copied to clipboard!'); } }; return (
{/* Hero section */}

Share images instantly

Upload an image and get a shareable link. No account required.

{!isAuthenticated && (

Create an account {' '} to manage your uploads and access more features.

)}
{/* Upload result */} {uploadResult && (
{uploadResult.success ? (

Image uploaded successfully!

Open image in new tab →
) : (

Upload failed

{uploadResult.error}

)}
)} {/* Upload area */} {!uploadResult?.success && (
)} {/* Features */}

Instant Upload

Drop your image and get a link instantly. No sign-up needed.

Auto Expiry

Set expiration times to automatically delete images after a period.

Easy Sharing

Get shareable links for your images with just one click.

); }