source: components/BuildCard.tsx@ 3870834

main
Last change on this file since 3870834 was 8a7f936, checked in by Mihail <mihail2.naumov@…>, 6 months ago

Added Forge Page, added suggest component, fixed styling

  • Property mode set to 100644
File size: 3.4 KB
Line 
1import React, {useEffect, useState} from 'react';
2import {Card, CardContent, CardMedia, Typography, Box, Chip} from '@mui/material';
3import StarIcon from '@mui/icons-material/Star';
4import {onGetBuildDetails} from "../pages/+Layout.telefunc";
5
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]);
25
26 return (
27 <Card
28 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 }}
42 >
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>
60
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>
66 </Box>
67
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}}/>
78 <Typography variant="body2" fontWeight="bold">
79 {Number(build.avgRating || 5).toFixed(1)}
80 </Typography>
81 </Box>
82 </Box>
83 </CardContent>
84 </Card>
85 );
86}
Note: See TracBrowser for help on using the repository browser.