Refactor: Implement Cloudflare Image Variants

This commit is contained in:
gpt-engineer-app[bot]
2025-10-10 14:09:51 +00:00
parent 9fc12be7e1
commit f57ae0d3ce
17 changed files with 216 additions and 48 deletions

View File

@@ -3,6 +3,7 @@ import { Badge } from '@/components/ui/badge';
import { Star, MapPin, Ruler, FerrisWheel } from 'lucide-react';
import { Company } from '@/types/database';
import { useNavigate } from 'react-router-dom';
import { getCloudflareImageUrl } from '@/lib/cloudflareImageUtils';
interface DesignerCardProps {
company: Company;
@@ -38,11 +39,12 @@ export function DesignerCard({ company }: DesignerCardProps) {
{/* Logo or Icon */}
<div className="relative z-10 flex items-center justify-center">
{company.logo_url ? (
{(company.logo_url || (company as any).logo_image_id) ? (
<img
src={company.logo_url}
src={company.logo_url || getCloudflareImageUrl((company as any).logo_image_id, 'logo')}
alt={`${company.name} logo`}
className="max-w-20 max-h-20 object-contain filter drop-shadow-sm"
loading="lazy"
/>
) : (
<div className="p-4 rounded-full bg-muted/30 backdrop-blur-sm border border-border/30">

View File

@@ -4,6 +4,7 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Company } from '@/types/database';
import { getCloudflareImageUrl } from '@/lib/cloudflareImageUtils';
interface ManufacturerCardProps {
company: Company;
@@ -42,9 +43,15 @@ export function ManufacturerCard({ company }: ManufacturerCardProps) {
<div className="aspect-video relative bg-gradient-to-br from-primary/20 via-primary/10 to-transparent overflow-hidden">
{(company.card_image_url || company.card_image_id) ? (
<img
src={company.card_image_url || `https://imagedelivery.net/${import.meta.env.VITE_CLOUDFLARE_ACCOUNT_HASH}/${company.card_image_id}/public`}
src={company.card_image_url || getCloudflareImageUrl(company.card_image_id, 'card')}
srcSet={company.card_image_id ? `
${getCloudflareImageUrl(company.card_image_id, 'cardthumb')} 600w,
${getCloudflareImageUrl(company.card_image_id, 'card')} 1200w
` : undefined}
sizes="(max-width: 640px) 600px, 1200px"
alt={company.name}
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
loading="lazy"
/>
) : (
<>
@@ -59,12 +66,13 @@ export function ManufacturerCard({ company }: ManufacturerCardProps) {
{/* Logo Display */}
<div className="absolute inset-0 flex items-center justify-center">
{company.logo_url ? (
{(company.logo_url || (company as any).logo_image_id) ? (
<div className="w-16 h-16 md:w-20 md:h-20 bg-background/90 rounded-xl overflow-hidden shadow-lg backdrop-blur-sm border border-border/50">
<img
src={company.logo_url}
src={company.logo_url || getCloudflareImageUrl((company as any).logo_image_id, 'logo')}
alt={`${company.name} logo`}
className="w-full h-full object-contain p-2"
loading="lazy"
/>
</div>
) : (

View File

@@ -4,6 +4,7 @@ import { Card, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Building, Star, MapPin } from 'lucide-react';
import { Company } from '@/types/database';
import { getCloudflareImageUrl } from '@/lib/cloudflareImageUtils';
interface OperatorCardProps {
company: Company;
@@ -29,9 +30,15 @@ const OperatorCard = ({ company }: OperatorCardProps) => {
<div className="aspect-video relative bg-gradient-to-br from-primary/20 via-primary/10 to-transparent overflow-hidden">
{(company.card_image_url || company.card_image_id) ? (
<img
src={company.card_image_url || `https://imagedelivery.net/${import.meta.env.VITE_CLOUDFLARE_ACCOUNT_HASH}/${company.card_image_id}/public`}
src={company.card_image_url || getCloudflareImageUrl(company.card_image_id, 'card')}
srcSet={company.card_image_id ? `
${getCloudflareImageUrl(company.card_image_id, 'cardthumb')} 600w,
${getCloudflareImageUrl(company.card_image_id, 'card')} 1200w
` : undefined}
sizes="(max-width: 640px) 600px, 1200px"
alt={company.name}
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
loading="lazy"
/>
) : (
<>
@@ -46,12 +53,13 @@ const OperatorCard = ({ company }: OperatorCardProps) => {
{/* Logo Display */}
<div className="absolute inset-0 flex items-center justify-center">
{company.logo_url ? (
{(company.logo_url || (company as any).logo_image_id) ? (
<div className="w-20 h-20 bg-background/90 rounded-xl overflow-hidden shadow-lg backdrop-blur-sm border border-border/50">
<img
src={company.logo_url}
src={company.logo_url || getCloudflareImageUrl((company as any).logo_image_id, 'logo')}
alt={`${company.name} logo`}
className="w-full h-full object-contain p-2"
loading="lazy"
/>
</div>
) : (

View File

@@ -4,6 +4,7 @@ import { Card, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Building2, Star, MapPin } from 'lucide-react';
import { Company } from '@/types/database';
import { getCloudflareImageUrl } from '@/lib/cloudflareImageUtils';
interface ParkOwnerCardProps {
company: Company;
@@ -29,9 +30,15 @@ const ParkOwnerCard = ({ company }: ParkOwnerCardProps) => {
<div className="aspect-video relative bg-gradient-to-br from-primary/20 via-primary/10 to-transparent overflow-hidden">
{(company.card_image_url || company.card_image_id) ? (
<img
src={company.card_image_url || `https://imagedelivery.net/${import.meta.env.VITE_CLOUDFLARE_ACCOUNT_HASH}/${company.card_image_id}/public`}
src={company.card_image_url || getCloudflareImageUrl(company.card_image_id, 'card')}
srcSet={company.card_image_id ? `
${getCloudflareImageUrl(company.card_image_id, 'cardthumb')} 600w,
${getCloudflareImageUrl(company.card_image_id, 'card')} 1200w
` : undefined}
sizes="(max-width: 640px) 600px, 1200px"
alt={company.name}
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
loading="lazy"
/>
) : (
<>
@@ -46,12 +53,13 @@ const ParkOwnerCard = ({ company }: ParkOwnerCardProps) => {
{/* Logo Display */}
<div className="absolute inset-0 flex items-center justify-center">
{company.logo_url ? (
{(company.logo_url || (company as any).logo_image_id) ? (
<div className="w-20 h-20 bg-background/90 rounded-xl overflow-hidden shadow-lg backdrop-blur-sm border border-border/50">
<img
src={company.logo_url}
src={company.logo_url || getCloudflareImageUrl((company as any).logo_image_id, 'logo')}
alt={`${company.name} logo`}
className="w-full h-full object-contain p-2"
loading="lazy"
/>
</div>
) : (

View File

@@ -3,6 +3,7 @@ import { useNavigate } from 'react-router-dom';
import { Card, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Park } from '@/types/database';
import { getCloudflareImageUrl } from '@/lib/cloudflareImageUtils';
interface ParkCardProps {
park: Park;
@@ -48,9 +49,15 @@ export function ParkCard({ park }: ParkCardProps) {
<div className="aspect-[4/3] bg-gradient-to-br from-primary/20 via-secondary/20 to-accent/20 flex items-center justify-center relative">
{(park.card_image_url || park.card_image_id) ? (
<img
src={park.card_image_url || `https://imagedelivery.net/${import.meta.env.VITE_CLOUDFLARE_ACCOUNT_HASH}/${park.card_image_id}/public`}
src={park.card_image_url || getCloudflareImageUrl(park.card_image_id, 'card')}
srcSet={park.card_image_id ? `
${getCloudflareImageUrl(park.card_image_id, 'cardthumb')} 600w,
${getCloudflareImageUrl(park.card_image_id, 'card')} 1200w
` : undefined}
sizes="(max-width: 640px) 600px, 1200px"
alt={park.name}
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
loading="lazy"
/>
) : (
<div className="opacity-50 flex items-center justify-center">

View File

@@ -4,6 +4,7 @@ import { Badge } from '@/components/ui/badge';
import { Star, MapPin, Clock, Zap, FerrisWheel, Waves, Theater, Train } from 'lucide-react';
import { MeasurementDisplay } from '@/components/ui/measurement-display';
import { Ride } from '@/types/database';
import { getCloudflareImageUrl } from '@/lib/cloudflareImageUtils';
interface RideCardProps {
ride: Ride;
@@ -57,9 +58,15 @@ export function RideCard({ ride, showParkName = true, className, parkSlug }: Rid
<div className="aspect-[4/3] bg-gradient-to-br from-primary/20 via-secondary/20 to-accent/20 flex items-center justify-center relative">
{(ride.card_image_url || ride.card_image_id || ride.image_url) ? (
<img
src={ride.card_image_url || (ride.card_image_id ? `https://imagedelivery.net/${import.meta.env.VITE_CLOUDFLARE_ACCOUNT_HASH}/${ride.card_image_id}/public` : ride.image_url)}
src={ride.card_image_url || getCloudflareImageUrl(ride.card_image_id, 'card') || ride.image_url}
srcSet={ride.card_image_id ? `
${getCloudflareImageUrl(ride.card_image_id, 'cardthumb')} 600w,
${getCloudflareImageUrl(ride.card_image_id, 'card')} 1200w
` : undefined}
sizes="(max-width: 640px) 600px, 1200px"
alt={ride.name}
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
loading="lazy"
/>
) : (
<div className="opacity-50 flex items-center justify-center">

View File

@@ -4,6 +4,7 @@ import { Button } from '@/components/ui/button';
import { FerrisWheel } from 'lucide-react';
import { RideModel } from '@/types/database';
import { useNavigate } from 'react-router-dom';
import { getCloudflareImageUrl } from '@/lib/cloudflareImageUtils';
interface RideModelCardProps {
model: RideModel;
@@ -45,9 +46,15 @@ export function RideModelCard({ model, manufacturerSlug }: RideModelCardProps) {
>
{(cardImageUrl || cardImageId) ? (
<img
src={cardImageUrl || `https://imagedelivery.net/${import.meta.env.VITE_CLOUDFLARE_ACCOUNT_HASH}/${cardImageId}/public`}
src={cardImageUrl || getCloudflareImageUrl(cardImageId, 'card')}
srcSet={cardImageId ? `
${getCloudflareImageUrl(cardImageId, 'cardthumb')} 600w,
${getCloudflareImageUrl(cardImageId, 'card')} 1200w
` : undefined}
sizes="(max-width: 640px) 600px, 1200px"
alt={model.name}
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300"
loading="lazy"
/>
) : (
<div className="flex items-center justify-center h-full">

View File

@@ -5,6 +5,7 @@ import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Image as ImageIcon, ImagePlus, X } from 'lucide-react';
import { UppyPhotoUpload } from './UppyPhotoUpload';
import { getCloudflareImageUrl } from '@/lib/cloudflareImageUtils';
export type ImageType = 'logo' | 'banner' | 'card';
@@ -140,7 +141,15 @@ export function EntityImageUploader({
{hasImage ? (
<div className="relative aspect-[16/9] bg-muted">
<img
src={currentImage.url}
src={
currentImage.url || (
type === 'logo'
? getCloudflareImageUrl(currentImage.id, 'logo')
: type === 'banner'
? getCloudflareImageUrl(currentImage.id, 'banner')
: getCloudflareImageUrl(currentImage.id, 'card')
)
}
alt={`${spec.label} preview`}
className="w-full h-full object-cover"
/>

View File

@@ -142,7 +142,8 @@ export function UppyPhotoUpload({
if (statusResponse.ok) {
const status: UploadSuccessResponse = await statusResponse.json();
if (status.uploaded && status.urls) {
return status.urls.public;
const CLOUDFLARE_ACCOUNT_HASH = import.meta.env.VITE_CLOUDFLARE_ACCOUNT_HASH;
return `https://imagedelivery.net/${CLOUDFLARE_ACCOUNT_HASH}/${cloudflareId}/public`;
}
}