diff --git a/frontend/src/components/ImageUploadSection.tsx b/frontend/src/components/ImageUploadSection.tsx index 9f15fbf6..01642a38 100644 --- a/frontend/src/components/ImageUploadSection.tsx +++ b/frontend/src/components/ImageUploadSection.tsx @@ -4,9 +4,11 @@ import { ImagesService, Body_upload_image_images_post } from "../api"; export function ImageUploadSection({ tempImage, setTempImage, + showLabel = false, }: { tempImage: string; setTempImage: (value: string) => void; + showLabel?: boolean; }) { const fileInputRef = useRef(null); const [uploadError, setUploadError] = useState(""); @@ -130,7 +132,8 @@ export function ImageUploadSection({ return (
-
image url or path:
+ {/* Conditionally show label */} + {showLabel &&
image url or path:
}
{/* URL Input */} diff --git a/frontend/src/pages/BookEditor.tsx b/frontend/src/pages/BookEditor.tsx index 368534b6..b18c323c 100644 --- a/frontend/src/pages/BookEditor.tsx +++ b/frontend/src/pages/BookEditor.tsx @@ -28,6 +28,27 @@ function PropsForm({ tempProps, setTempProps }: PropsFormProps) { console.error("Error parsing tempProps JSON:", e); } + const imageKeys = new Set([ + "image", + "imageUrl", + "imageSrc", + "backgroundImage", + "img", + ]); + + // Helper to check if a key is an image field + const isImageField = (key: string): boolean => { + const lowerKey = key.toLowerCase(); + return ( + imageKeys.has(lowerKey) || + lowerKey.includes("image") || + lowerKey.includes("img") || + (typeof propsObject[key] === "string" && + (propsObject[key].startsWith("http") || + propsObject[key].startsWith("/"))) + ); + }; + // Compute arrays based on the initial propsObject const objectArrays = Object.keys(propsObject).filter( (key) => @@ -215,6 +236,14 @@ function PropsForm({ tempProps, setTempProps }: PropsFormProps) { className="border border-gray-300 rounded p-1 font-mono whitespace-pre w-full max-w-full min-w-0" style={{ resize: "vertical" }} /> + ) : isImageField(key) ? ( + // *** NEW: Use ImageUploadSection for image fields *** + + handleInputChange(key, newValue) + } + /> ) : ( True + ) : isImageField(field) ? ( + // *** NEW: Use ImageUploadSection for image fields in arrays *** + + handleOptionChange(arrayKey, index, field, newValue) + } + /> ) : ( Preview Book