Changes in components/ComponentDialog.tsx [6ce6739:a932c9e]
- File:
-
- 1 edited
-
components/ComponentDialog.tsx (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
components/ComponentDialog.tsx
r6ce6739 ra932c9e 1 import React, { useEffect, useState} from 'react';1 import React, { useEffect, useState } from 'react'; 2 2 import { 3 3 Dialog, DialogContent, IconButton, Grid, Box, Typography, … … 9 9 import SortIcon from '@mui/icons-material/Sort'; 10 10 11 import { onGetAllComponents} from '../pages/+Layout.telefunc';11 import { onGetAllComponents } from '../pages/+Layout.telefunc'; 12 12 import ComponentDetailsDialog from "./ComponentDetailsDialog"; 13 13 14 14 const formatMoney = (amount: number) => `$${amount}`; 15 15 16 export default function ComponentBrowserDialog({ open, category, onClose}: any) {16 export default function ComponentBrowserDialog({ open, category, onClose }: any) { 17 17 const [components, setComponents] = useState<any[]>([]); 18 18 const [loading, setLoading] = useState(false); … … 30 30 setSortOrder('price_desc'); 31 31 32 onGetAllComponents({ componentType: category})32 onGetAllComponents({ componentType: category }) 33 33 .then((data) => { 34 34 setComponents(data); … … 70 70 maxWidth="xl" 71 71 fullWidth 72 sx={{height: '90vh'}}72 PaperProps={{ sx: { height: '90vh' } }} 73 73 > 74 <AppBar position="relative" sx={{ bgcolor: '#ff8201'}}>74 <AppBar position="relative" sx={{ bgcolor: '#ff8201' }}> 75 75 <Toolbar> 76 <Typography sx={{ ml: 2, flex: 1, textTransform: 'capitalize'}} variant="h6" component="div">76 <Typography sx={{ ml: 2, flex: 1, textTransform: 'capitalize' }} variant="h6" component="div"> 77 77 Browsing: <b>{category === 'gpu' ? 'Graphics Cards' : category?.toUpperCase()}</b> 78 78 </Typography> 79 79 <IconButton edge="start" color="inherit" onClick={onClose}> 80 <CloseIcon />80 <CloseIcon /> 81 81 </IconButton> 82 82 </Toolbar> 83 83 </AppBar> 84 84 85 <DialogContent sx={{p: 0, display: 'flex', height: '100%'}}> 86 <Box sx={{ 87 width: 300, 88 borderRight: '1px solid #ddd', 89 p: 3, 90 bgcolor: '#1e1e1e', 91 display: {xs: 'none', md: 'block'} 92 }}> 93 <Box sx={{display: 'flex', alignItems: 'center', mb: 2}}> 94 <SortIcon sx={{mr: 1}}/> 85 <DialogContent sx={{ p: 0, display: 'flex', height: '100%' }}> 86 <Box sx={{ width: 300, borderRight: '1px solid #ddd', p: 3, bgcolor: '#1e1e1e', display: { xs: 'none', md: 'block' } }}> 87 <Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}> 88 <SortIcon sx={{ mr: 1 }} /> 95 89 <Typography variant="h6">Sort By</Typography> 96 90 </Box> 97 <FormControl fullWidth size="small" sx={{ mb: 4}}>91 <FormControl fullWidth size="small" sx={{ mb: 4 }}> 98 92 <InputLabel>Price</InputLabel> 99 93 <Select … … 107 101 </FormControl> 108 102 109 <Divider sx={{ mb: 3}}/>110 111 <Box sx={{ display: 'flex', alignItems: 'center', mb: 2}}>112 <FilterListIcon sx={{ mr: 1}}/>103 <Divider sx={{ mb: 3 }} /> 104 105 <Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}> 106 <FilterListIcon sx={{ mr: 1 }} /> 113 107 <Typography variant="h6">Filters</Typography> 114 108 </Box> … … 121 115 min={0} 122 116 max={components.length > 0 ? Math.max(...components.map(c => Number(c.price))) : 2000} 123 sx={{ color: '#ff8201', mb: 2}}117 sx={{ color: '#ff8201', mb: 2}} 124 118 /> 125 <Box sx={{ display: 'flex', justifyContent: 'space-between', mb: 2}}>119 <Box sx={{ display: 'flex', justifyContent: 'space-between', mb: 2 }}> 126 120 <Typography variant="caption">{formatMoney(priceRange[0])}</Typography> 127 121 <Typography variant="caption">{formatMoney(priceRange[1])}</Typography> … … 139 133 {availableBrands.map((brand) => ( 140 134 <MenuItem key={brand} value={brand}> 141 <Checkbox checked={selectedBrands.indexOf(brand) > -1} />142 <ListItemText primary={brand} />135 <Checkbox checked={selectedBrands.indexOf(brand) > -1} /> 136 <ListItemText primary={brand} /> 143 137 </MenuItem> 144 138 ))} … … 147 141 </Box> 148 142 149 <Box sx={{ flex: 1, p: 3, overflowY: 'auto'}}>143 <Box sx={{ flex: 1, p: 3, overflowY: 'auto' }}> 150 144 {loading ? ( 151 <Box sx={{ display: 'flex', justifyContent: 'center', mt: 10}}>152 <CircularProgress sx={{ color: '#ff8201'}}/>145 <Box sx={{ display: 'flex', justifyContent: 'center', mt: 10 }}> 146 <CircularProgress sx={{ color: '#ff8201' }} /> 153 147 </Box> 154 148 ) : ( 155 <Grid container spacing={ 1}>149 <Grid container spacing={3}> 156 150 {processedComponents.map((comp) => ( 157 151 <Grid item xs={12} sm={6} md={4} lg={3} key={comp.id}> 158 <Card elevation={1} sx={{ 159 height: '100%', 160 display: 'flex', 161 flexDirection: 'column', 162 maxWidth: 220, 163 width: 220, 164 overflow: 'hidden', 165 whiteSpace: 'nowrap', 166 textOverflow: 'ellipsis' 167 }}> 152 <Card elevation={3} sx={{ height: '100%', display: 'flex', flexDirection: 'column' }}> 168 153 <CardMedia 169 154 component="img" 170 155 height="140" 171 // image={`https://placehold.co/400x400?text=${encodeURIComponent(comp.name)}`} 172 image={ comp.imgUrl}156 157 image={`https://placehold.co/400x400?text=${encodeURIComponent(comp.name)}`} 173 158 alt={comp.name} 174 sx={{ p: 2, objectFit: 'contain'}}159 sx={{ p: 2, objectFit: 'contain' }} 175 160 /> 176 <CardContent sx={{flexGrow: 1}}> 177 <Typography variant="caption" color="text.secondary" 178 sx={{textTransform: 'uppercase'}}> 161 <CardContent sx={{ flexGrow: 1 }}> 162 <Typography variant="caption" color="text.secondary" sx={{ textTransform: 'uppercase' }}> 179 163 {comp.brand} 180 164 </Typography> 181 <Typography variant="subtitle1" fontWeight="bold" sx={{ 182 lineHeight: 1.2, 183 mb: 1, 184 }}> 165 <Typography variant="subtitle1" fontWeight="bold" sx={{ lineHeight: 1.2, mb: 1 }}> 185 166 {comp.name} 186 167 </Typography> 187 168 188 <Box sx={{ 189 display: 'flex', 190 justifyContent: 'space-between', 191 alignItems: 'center', 192 mt: 2 193 }}> 169 <Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mt: 2 }}> 194 170 <Typography variant="h6" color="primary.main"> 195 171 {formatMoney(comp.price)} … … 197 173 </Box> 198 174 </CardContent> 199 <Box sx={{ p: 2, pt: 0}}>175 <Box sx={{ p: 2, pt: 0}}> 200 176 <Button 201 177 fullWidth 202 178 variant="outlined" 203 onClick={() => setSelectedComponent(comp)} 204 sx={{ 205 backgroundColor: '#ff8201', 206 color: 'white', 207 borderColor: '#ff8201', 208 onHover: {backgroundColor: '#e67300', borderColor: '#e67300'} 209 }} 179 onClick={()=> setSelectedComponent(comp)} 180 sx={{backgroundColor:'#ff8201', color: 'white', borderColor: '#ff8201', onHover: { backgroundColor: '#e67300', borderColor: '#e67300' } }} 210 181 > 211 182 Details … … 216 187 ))} 217 188 {processedComponents.length === 0 && ( 218 <Box sx={{ width: '100%', textAlign: 'center', mt: 5}}>189 <Box sx={{ width: '100%', textAlign: 'center', mt: 5 }}> 219 190 <Typography variant="h6" color="text.secondary">No components match.</Typography> 220 191 </Box>
Note:
See TracChangeset
for help on using the changeset viewer.
