From f5fb88ed8811e566f69829cc34a1a88ea3e93ce9 Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 8 Mar 2026 23:04:23 -0500 Subject: [PATCH] Add edit and photo upload to DogDetail --- client/src/pages/DogDetail.jsx | 94 ++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 5 deletions(-) diff --git a/client/src/pages/DogDetail.jsx b/client/src/pages/DogDetail.jsx index af61ae5..9688c63 100644 --- a/client/src/pages/DogDetail.jsx +++ b/client/src/pages/DogDetail.jsx @@ -1,12 +1,16 @@ -import { useEffect, useState } from 'react' +import { useEffect, useState, useRef } from 'react' import { useParams, Link } from 'react-router-dom' -import { Dog, GitBranch, Edit, Trash2 } from 'lucide-react' +import { Dog, GitBranch, Edit, Upload, Trash2 } from 'lucide-react' import axios from 'axios' +import DogForm from '../components/DogForm' function DogDetail() { const { id } = useParams() const [dog, setDog] = useState(null) const [loading, setLoading] = useState(true) + const [showEditModal, setShowEditModal] = useState(false) + const [uploading, setUploading] = useState(false) + const fileInputRef = useRef(null) useEffect(() => { fetchDog() @@ -23,6 +27,40 @@ function DogDetail() { } } + const handlePhotoUpload = async (e) => { + const file = e.target.files[0] + if (!file) return + + setUploading(true) + const formData = new FormData() + formData.append('photo', file) + + try { + await axios.post(`/api/dogs/${id}/photos`, formData, { + headers: { 'Content-Type': 'multipart/form-data' } + }) + fetchDog() + } catch (error) { + console.error('Error uploading photo:', error) + alert('Failed to upload photo') + } finally { + setUploading(false) + if (fileInputRef.current) fileInputRef.current.value = '' + } + } + + const handleDeletePhoto = async (photoIndex) => { + if (!confirm('Delete this photo?')) return + + try { + await axios.delete(`/api/dogs/${id}/photos/${photoIndex}`) + fetchDog() + } catch (error) { + console.error('Error deleting photo:', error) + alert('Failed to delete photo') + } + } + if (loading) { return
Loading...
} @@ -40,7 +78,7 @@ function DogDetail() { View Pedigree - @@ -81,11 +119,46 @@ function DogDetail() {
-

Photos

+
+

Photos

+ + +
{dog.photo_urls && dog.photo_urls.length > 0 ? (
{dog.photo_urls.map((url, index) => ( - {`${dog.name} +
+ {`${dog.name} + +
))}
) : ( @@ -138,6 +211,17 @@ function DogDetail() {
)} + + {showEditModal && ( + setShowEditModal(false)} + onSave={() => { + fetchDog() + setShowEditModal(false) + }} + /> + )} ) }