Changes in components/ComponentDialog.tsx [a932c9e:6ce6739]
- File:
-
- 1 edited
-
components/ComponentDialog.tsx (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
components/ComponentDialog.tsx
ra932c9e r6ce6739 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 PaperProps={{ sx: { height: '90vh' }}}72 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={{ 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 }} /> 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}}/> 89 95 <Typography variant="h6">Sort By</Typography> 90 96 </Box> 91 <FormControl fullWidth size="small" sx={{ mb: 4}}>97 <FormControl fullWidth size="small" sx={{mb: 4}}> 92 98 <InputLabel>Price</InputLabel> 93 99 <Select … … 101 107 </FormControl> 102 108 103 <Divider sx={{ mb: 3 }}/>104 105 <Box sx={{ display: 'flex', alignItems: 'center', mb: 2}}>106 <FilterListIcon sx={{ mr: 1 }}/>109 <Divider sx={{mb: 3}}/> 110 111 <Box sx={{display: 'flex', alignItems: 'center', mb: 2}}> 112 <FilterListIcon sx={{mr: 1}}/> 107 113 <Typography variant="h6">Filters</Typography> 108 114 </Box> … … 115 121 min={0} 116 122 max={components.length > 0 ? Math.max(...components.map(c => Number(c.price))) : 2000} 117 sx={{ color: '#ff8201', mb: 2}}123 sx={{color: '#ff8201', mb: 2}} 118 124 /> 119 <Box sx={{ display: 'flex', justifyContent: 'space-between', mb: 2}}>125 <Box sx={{display: 'flex', justifyContent: 'space-between', mb: 2}}> 120 126 <Typography variant="caption">{formatMoney(priceRange[0])}</Typography> 121 127 <Typography variant="caption">{formatMoney(priceRange[1])}</Typography> … … 133 139 {availableBrands.map((brand) => ( 134 140 <MenuItem key={brand} value={brand}> 135 <Checkbox checked={selectedBrands.indexOf(brand) > -1} />136 <ListItemText primary={brand} />141 <Checkbox checked={selectedBrands.indexOf(brand) > -1}/> 142 <ListItemText primary={brand}/> 137 143 </MenuItem> 138 144 ))} … … 141 147 </Box> 142 148 143 <Box sx={{ flex: 1, p: 3, overflowY: 'auto'}}>149 <Box sx={{flex: 1, p: 3, overflowY: 'auto'}}> 144 150 {loading ? ( 145 <Box sx={{ display: 'flex', justifyContent: 'center', mt: 10}}>146 <CircularProgress sx={{ color: '#ff8201' }}/>151 <Box sx={{display: 'flex', justifyContent: 'center', mt: 10}}> 152 <CircularProgress sx={{color: '#ff8201'}}/> 147 153 </Box> 148 154 ) : ( 149 <Grid container spacing={ 3}>155 <Grid container spacing={1}> 150 156 {processedComponents.map((comp) => ( 151 157 <Grid item xs={12} sm={6} md={4} lg={3} key={comp.id}> 152 <Card elevation={3} sx={{ height: '100%', display: 'flex', flexDirection: 'column' }}> 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 }}> 153 168 <CardMedia 154 169 component="img" 155 170 height="140" 156 157 image={ `https://placehold.co/400x400?text=${encodeURIComponent(comp.name)}`}171 // image={`https://placehold.co/400x400?text=${encodeURIComponent(comp.name)}`} 172 image={comp.imgUrl} 158 173 alt={comp.name} 159 sx={{ p: 2, objectFit: 'contain'}}174 sx={{p: 2, objectFit: 'contain'}} 160 175 /> 161 <CardContent sx={{ flexGrow: 1 }}> 162 <Typography variant="caption" color="text.secondary" sx={{ textTransform: 'uppercase' }}> 176 <CardContent sx={{flexGrow: 1}}> 177 <Typography variant="caption" color="text.secondary" 178 sx={{textTransform: 'uppercase'}}> 163 179 {comp.brand} 164 180 </Typography> 165 <Typography variant="subtitle1" fontWeight="bold" sx={{ lineHeight: 1.2, mb: 1 }}> 181 <Typography variant="subtitle1" fontWeight="bold" sx={{ 182 lineHeight: 1.2, 183 mb: 1, 184 }}> 166 185 {comp.name} 167 186 </Typography> 168 187 169 <Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mt: 2 }}> 188 <Box sx={{ 189 display: 'flex', 190 justifyContent: 'space-between', 191 alignItems: 'center', 192 mt: 2 193 }}> 170 194 <Typography variant="h6" color="primary.main"> 171 195 {formatMoney(comp.price)} … … 173 197 </Box> 174 198 </CardContent> 175 <Box sx={{ p: 2, pt: 0}}>199 <Box sx={{p: 2, pt: 0}}> 176 200 <Button 177 201 fullWidth 178 202 variant="outlined" 179 onClick={()=> setSelectedComponent(comp)} 180 sx={{backgroundColor:'#ff8201', color: 'white', borderColor: '#ff8201', onHover: { backgroundColor: '#e67300', borderColor: '#e67300' } }} 203 onClick={() => setSelectedComponent(comp)} 204 sx={{ 205 backgroundColor: '#ff8201', 206 color: 'white', 207 borderColor: '#ff8201', 208 onHover: {backgroundColor: '#e67300', borderColor: '#e67300'} 209 }} 181 210 > 182 211 Details … … 187 216 ))} 188 217 {processedComponents.length === 0 && ( 189 <Box sx={{ width: '100%', textAlign: 'center', mt: 5}}>218 <Box sx={{width: '100%', textAlign: 'center', mt: 5}}> 190 219 <Typography variant="h6" color="text.secondary">No components match.</Typography> 191 220 </Box>
Note:
See TracChangeset
for help on using the changeset viewer.
