Ignore:
Timestamp:
12/29/25 00:37:49 (6 months ago)
Author:
Mihail <mihail2.naumov@…>
Branches:
main
Children:
5af32f0
Parents:
ae5d054
Message:

Added Forge Page, added suggest component, fixed styling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • components/BuildCard.tsx

    rae5d054 r8a7f936  
    1 import React from 'react';
    2 import { Card, CardMedia, CardContent, Typography, Box, Chip } from '@mui/material';
     1import React, {useEffect, useState} from 'react';
     2import {Card, CardContent, CardMedia, Typography, Box, Chip} from '@mui/material';
    33import StarIcon from '@mui/icons-material/Star';
    4 // import PersonIcon from '@mui/icons-material/Person';
     4import {onGetBuildDetails} from "../pages/+Layout.telefunc";
    55
    6 export default function BuildCard({ build, onClick }: { build: any, onClick: () => void }) {
    7     const formattedPrice = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'EUR' }).format(build.total_price || 0);
     6export default function BuildCard({build, onClick}: { build: any, onClick?: () => void }) {
     7    const [caseImage, setCaseImage] = useState<string>("https://placehold.co/600x400?text=PC+Build");
     8    const [imageLoading, setImageLoading] = useState(true);
     9
     10    const formattedPrice = new Intl.NumberFormat('en-US', {
     11        style: 'currency',
     12        currency: 'EUR'
     13    }).format(build.total_price || 0);
     14
     15    useEffect(() => {
     16        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");
     20            })
     21            .catch(() => {
     22            })
     23            .finally(() => setImageLoading(false));
     24    }, [build.id]);
    825
    926    return (
    1027        <Card
    11             sx={{ height: '100%', display: 'flex', flexDirection: 'column', cursor: 'pointer', transition: 'all 0.2s', '&:hover': { transform: 'translateY(-4px)', boxShadow: 6 } }}
    1228            onClick={onClick}
     29            sx={{
     30                width: '100%',
     31                height: '100%',
     32                display: 'flex',
     33                flexDirection: 'column',
     34                cursor: onClick ? 'pointer' : 'default',
     35                transition: 'transform 0.2s, box-shadow 0.2s',
     36                '&:hover': onClick ? {
     37                    transform: 'translateY(-4px)',
     38                    boxShadow: 6
     39                } : {},
     40                position: 'relative'
     41            }}
    1342        >
    14             <CardMedia
    15                 component="img"
    16                 height="160"
    17                 image={build.img_url || "https://placehold.co/600x400?text=PC+Build"}
    18                 alt={build.name}
    19             />
    20             <CardContent sx={{ flexGrow: 1, pb: 1 }}>
    21                 <Typography gutterBottom variant="h6" noWrap title={build.name}>
    22                     {build.name}
    23                 </Typography>
     43            <Box sx={{position: 'relative', paddingTop: '75%'}}>
     44                <CardMedia
     45                    component="img"
     46                    image={caseImage || '/placeholder-pc.png'}
     47                    alt={build.name}
     48                    sx={{
     49                        position: 'absolute',
     50                        top: 0,
     51                        left: 0,
     52                        width: '100%',
     53                        height: '100%',
     54                        objectFit: 'contain',
     55                        p: 2,
     56                        bgcolor: '#f5f5f5'
     57                    }}
     58                />
     59            </Box>
    2460
    25                 {/*Ne se renderira user-ot*/}
    26                 <Box sx={{ display: 'flex', alignItems: 'center', mb: 1, color: 'text.secondary' }}>
    27                     {/*    <PersonIcon sx={{ fontSize: 16, mr: 0.5 }} />*/}
    28                     {/*    <Typography variant="caption">{build.user || 'Unknown'}</Typography>*/}
     61            <CardContent sx={{flexGrow: 1, display: 'flex', flexDirection: 'column', justifyContent: 'space-between'}}>
     62                <Box sx={{mb: 2}}>
     63                    <Typography variant="h6" component="div" fontWeight="bold" wrap title={build.name}>
     64                        {build.name}
     65                    </Typography>
    2966                </Box>
    3067
    31                 <Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mt: 'auto' }}>
    32                     <Chip label={formattedPrice} size="small" color="primary" variant="outlined" />
    33                     <Box sx={{ display: 'flex', alignItems: 'center' }}>
    34                         <StarIcon fontSize="small" sx={{ color: '#faaf00', mr: 0.5 }} />
     68                <Box sx={{display: 'flex', justifyContent: 'space-between', alignItems: 'center', mt: 'auto'}}>
     69                    <Chip
     70                        label={formattedPrice}
     71                        color="primary"
     72                        variant="outlined"
     73                        size="small"
     74                        sx={{fontWeight: 'bold'}}
     75                    />
     76                    <Box sx={{display: 'flex', alignItems: 'center'}}>
     77                        <StarIcon sx={{color: '#faaf00', fontSize: 20, mr: 0.5}}/>
    3578                        <Typography variant="body2" fontWeight="bold">
    3679                            {Number(build.avgRating || 5).toFixed(1)}
Note: See TracChangeset for help on using the changeset viewer.