Ignore:
Timestamp:
12/29/25 04:34:44 (6 months ago)
Author:
Mihail <mihail2.naumov@…>
Branches:
main
Children:
41a2f81
Parents:
f46bf5c
Message:

Added add component button, fixed several things

File:
1 edited

Legend:

Unmodified
Added
Removed
  • components/BuildCard.tsx

    rf46bf5c r958bc89  
    11import React, {useEffect, useState} from 'react';
    2 import {Card, CardContent, CardMedia, Typography, Box, Chip} from '@mui/material';
     2import {Card, CardContent, CardMedia, Typography, Box, Chip, CircularProgress} from '@mui/material';
    33import StarIcon from '@mui/icons-material/Star';
    44import {onGetBuildDetails} from "../pages/+Layout.telefunc";
     
    77    const [caseImage, setCaseImage] = useState<string>("https://placehold.co/600x400?text=PC+Build");
    88    const [imageLoading, setImageLoading] = useState(true);
     9    const [details, setDetails] = useState<any>(null);
    910
    1011    const formattedPrice = new Intl.NumberFormat('en-US', {
     
    1415
    1516    useEffect(() => {
     17        setImageLoading(true);
    1618        onGetBuildDetails({buildId: build.id})
    17             .then(details => {
    18                 const caseComponent = details.components.find((c: any) => c.type === 'case');
    19                 setCaseImage(caseComponent?.imgUrl || caseComponent?.imgUrl || "https://placehold.co/600x400?text=PC+Build");
     19            .then(fullDetails => {
     20                setDetails(fullDetails);
     21
     22                const caseComponent = fullDetails.components?.find((c: any) => c.type === 'case');
     23                setCaseImage(
     24                    caseComponent?.imgUrl ||
     25                    "https://placehold.co/600x400?text=PC+Build"
     26                );
    2027            })
    21             .catch(() => {
     28            .catch((error) => {
     29                console.error("Failed to load build details:", error);
     30                setDetails(null);
    2231            })
    23             .finally(() => setImageLoading(false));
     32            .finally(() => {
     33                setImageLoading(false);
     34            });
    2435    }, [build.id]);
     36
     37    if (imageLoading) {
     38        return (
     39            <Card sx={{width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center'}}>
     40                <CircularProgress />
     41            </Card>
     42        );
     43    }
    2544
    2645    return (
     
    4463                <CardMedia
    4564                    component="img"
    46                     image={caseImage || '/placeholder-pc.png'}
     65                    image={caseImage}
    4766                    alt={build.name}
    4867                    sx={{
     
    6079
    6180            <CardContent sx={{flexGrow: 1, display: 'flex', flexDirection: 'column', justifyContent: 'space-between'}}>
     81                <Box sx={{mb: 1}}>
     82                    <Typography variant="h6" component="div" fontWeight="bold">
     83                        {build.name}
     84                    </Typography>
     85                </Box>
     86
    6287                <Box sx={{mb: 2}}>
    63                     <Typography variant="h6" component="div" fontWeight="bold" wrap title={build.name}>
    64                         {build.name}
     88                    <Typography
     89                        variant="body2"
     90                        color="text.secondary"
     91                        sx={{fontStyle: 'italic', fontSize: '0.875rem'}}
     92                    >
     93                        {details?.description || "No description provided."}
    6594                    </Typography>
    6695                </Box>
     
    75104                    />
    76105                    <Box sx={{display: 'flex', alignItems: 'center'}}>
    77                         <StarIcon sx={{color: '#faaf00', fontSize: 20, mr: 0.5}}/>
     106                        <StarIcon sx={{color: '#faaf00', fontSize: 20, ml: 1}}/>
    78107                        <Typography variant="body2" fontWeight="bold">
    79                             {Number(build.avgRating || 5).toFixed(1)}
     108                            {Number(build.avgRating || 0).toFixed(1)}
    80109                        </Typography>
    81110                    </Box>
Note: See TracChangeset for help on using the changeset viewer.