const imgContentArray = block.content; logger.log('Block Content:', imgContentArray);…
Jump to turn (6)
- 1const imgContentArray = block.content; logger.log('Block Content:', imgContentAr
- 2// src/types/jsonTypes.ts export type JSONValueNoNull = string | number | boolea
- 3we could allow a array
- 4so how should this code look then? // src/components/main/blocks/BlockPhoto.tsx
- 5//src/components/main/modals/ModalPhoto.tsx import React, { useState, useEffect,
- 6guess its pointless to stress over it until teh api is done
- User
const imgContentArray = block.content; logger.log('Block Content:', imgContentArray);
codeconst imgContent = Array.isArray(imgContentArray) && imgContentArray.length > 0 ? imgContentArray[0] : null; logger.log('Accessed Image Content:', imgContent); // @url https://parceljs.org/recipes/image/ const imgPlaceholder = new URL('../../../imgs/placeholder.jpg?width=800&quality=80', import.meta.url); //const imgPlaceholder = `${API_URL}uploads/placeholder.jpg`; const [imgUrl, setImgUrl] = useState<string>{imgPlaceholder};// Start with the placeholder useEffect(() => { if (imgContent && typeof imgContent === 'string' && /\.(jpg|jpeg|png)$/i.test(imgContent)) { const constructedImgUrl = `${API_URL}${imgContent.startsWith('/') ? '' : 'uploads/'}${imgContent}`; setImgUrl(constructedImgUrl); } else { setImgUrl(imgPlaceholder);// Fallback to placeholder if invalid } }, [imgContent, API_URL]); logger.log('Constructed Image URL:', imgUrl); if (!block) { return <p>No block available.</p>; }