Ignore:
Timestamp:
12/28/25 00:07:22 (7 months ago)
Author:
Mihail <mihail2.naumov@…>
Branches:
main
Children:
9c87509
Parents:
f7c0b0d
Message:

Added frontend elements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pages/dashboard/user/+Page.tsx

    rf7c0b0d re599341  
    99    Button,
    1010    CircularProgress,
    11     Card,
    12     CardContent,
    13     CardActionArea,
    14     IconButton
     11    IconButton,
     12    Grid,
     13    Dialog,
     14    DialogTitle,
     15    DialogContent,
     16    DialogActions
    1517} from '@mui/material';
    16 import Grid from '@mui/material/Grid';
    17 import {Dialog, DialogTitle, DialogContent, DialogActions} from '@mui/material';
    1818import CloseIcon from '@mui/icons-material/Close';
    1919
     
    2121import ComputerIcon from '@mui/icons-material/Computer';
    2222import FavoriteIcon from '@mui/icons-material/Favorite';
    23 import DeleteIcon from '@mui/icons-material/Delete';
    24 import EditIcon from '@mui/icons-material/Edit';
    2523
    2624import {getUserInfoAndData, onDeleteBuild} from "./userDashboard.telefunc";
     25import {onCloneBuild} from "../../+Layout.telefunc";
     26
     27import BuildCard from "../../../components/BuildCard";
     28import BuildDetailsDialog from "../../../components/BuildDetailsDialog";
    2729
    2830type DashboardData = {
     
    3638    const [loading, setLoading] = useState(true);
    3739    const [error, setError] = useState<string | null>(null);
     40
    3841    const [openMyBuildsDialog, setOpenMyBuildsDialog] = useState(false);
     42    const [openFavoritesDialog, setOpenFavoritesDialog] = useState(false);
     43
     44    const [selectedBuildId, setSelectedBuildId] = useState<number | null>(null);
    3945
    4046    const loadData = () => {
     
    6066            await onDeleteBuild({buildId});
    6167            loadData();
     68            setSelectedBuildId(null);
    6269        } catch (e) {
    6370            alert("Failed to delete build");
     
    6572    };
    6673
     74    const handleCloneWrapper = async (buildId: number) => {
     75        if (!data?.user) return alert("Please login to clone builds!");
     76        if (confirm(`Clone this build to your dashboard?`)) {
     77            await onCloneBuild({buildId});
     78            alert("Build cloned! Check your dashboard.");
     79            setSelectedBuildId(null);
     80            loadData();
     81        }
     82    };
     83
    6784    if (loading) return <Box sx={{display: 'flex', justifyContent: 'center', mt: 10}}><CircularProgress/></Box>;
    6885    if (error || !data) return <Container sx={{mt: 5, textAlign: 'center'}}><Typography color="error"
    6986                                                                                        variant="h6">{error}</Typography><Button
    7087        href="/auth/login" variant="contained">Login</Button></Container>;
    71 
    72     // @ts-ignore
     88    // console.log("Current User ID passed to dialog:", data?.user?.id);
     89
    7390    return (
    7491        <Container maxWidth="xl" sx={{mt: 4, mb: 4, color: 'white'}}>
    7592            <Grid container spacing={3}>
    76 
    7793                <Grid item xs={12} md={3}>
    7894                    <Paper elevation={3}
     
    8399                        <Typography variant="body2" color="text.secondary" gutterBottom>{data.user.email}</Typography>
    84100                        <Divider sx={{width: '100%', my: 2}}/>
    85                         {/*<Button variant="outlined" fullWidth color="primary" sx={{mb: 1}}>Edit Profile</Button>*/}
    86101                    </Paper>
    87102                </Grid>
     
    92107                        <Grid item xs={12}>
    93108                            <Paper elevation={3} sx={{p: 3, minHeight: '300px', bgcolor: '#1e1e1e'}}>
    94                                 <Box sx={{display: 'flex', alignItems: 'center', mb: 2}}>
    95                                     <FavoriteIcon color="error" sx={{mr: 1}}/>
    96                                     <Typography variant="h6" fontWeight="bold">Favorited Builds</Typography>
     109                                <Box sx={{
     110                                    display: 'flex',
     111                                    alignItems: 'center',
     112                                    justifyContent: 'space-between',
     113                                    mb: 2
     114                                }}>
     115                                    <Box sx={{display: 'flex', alignItems: 'center'}}>
     116                                        <FavoriteIcon color="error" sx={{mr: 1}}/>
     117                                        <Typography variant="h6" fontWeight="bold">Favorited Builds</Typography>
     118                                    </Box>
     119
     120                                    {data.favoriteBuilds.length > 4 && (
     121                                        <Button
     122                                            variant="outlined"
     123                                            size="small"
     124                                            onClick={() => setOpenFavoritesDialog(true)}
     125                                        >
     126                                            See All ({data.favoriteBuilds.length})
     127                                        </Button>
     128                                    )}
    97129                                </Box>
    98130                                <Divider sx={{mb: 2}}/>
     
    103135                                ) : (
    104136                                    <Grid container spacing={2}>
    105                                         {data.favoriteBuilds.map((build: any) => (
     137                                        {data.favoriteBuilds.slice(0, 4).map((build: any) => (
    106138                                            <Grid item xs={12} sm={6} md={4} key={build.id}>
    107                                                 <BuildCard build={build}/>
     139                                                <BuildCard
     140                                                    build={build}
     141                                                    onClick={() => setSelectedBuildId(build.id)}
     142                                                />
    108143                                            </Grid>
    109144                                        ))}
     
    148183                                ) : (
    149184                                    <Grid container spacing={2}>
    150                                         {data.userBuilds.slice(0, 3).map((build: any) => (
    151                                             <Grid item xs={12} sm={6} md={3} key={build.id}>
     185                                        {data.userBuilds.slice(0, 4).map((build: any) => (
     186                                            <Grid item xs={12} sm={6} md={4} key={build.id}>
    152187                                                <BuildCard
    153188                                                    build={build}
    154                                                     onDelete={() => handleDelete(build.id)}
    155                                                     isOwner={true}
     189                                                    onClick={() => setSelectedBuildId(build.id)}
    156190                                                />
    157191                                            </Grid>
     
    162196                        </Grid>
    163197
    164                         <Dialog open={openMyBuildsDialog} onClose={() => setOpenMyBuildsDialog(false)} maxWidth="md"
     198                        <Dialog open={openMyBuildsDialog} onClose={() => setOpenMyBuildsDialog(false)} maxWidth="lg"
    165199                                fullWidth>
    166                             <DialogTitle sx={{display: 'flex', justifyContent: 'space-between', alignItems: 'center'}}>All
    167                                 My Builds
     200                            <DialogTitle sx={{display: 'flex', justifyContent: 'space-between', alignItems: 'center'}}>
     201                                All My Builds
    168202                                <IconButton onClick={() => setOpenMyBuildsDialog(false)}>
    169203                                    <CloseIcon/>
     
    176210                                            <BuildCard
    177211                                                build={build}
    178                                                 onDelete={() => handleDelete(build.id)}
    179                                                 isOwner={true}
     212                                                onClick={() => {
     213                                                    setOpenMyBuildsDialog(false);
     214                                                    setSelectedBuildId(build.id);
     215                                                }}
    180216                                            />
    181217                                        </Grid>
     
    183219                                </Grid>
    184220                            </DialogContent>
    185 
    186221                            <DialogActions>
    187222                                <Button onClick={() => setOpenMyBuildsDialog(false)}>Close</Button>
     
    189224                        </Dialog>
    190225
     226                        <Dialog open={openFavoritesDialog} onClose={() => setOpenFavoritesDialog(false)} maxWidth="lg"
     227                                fullWidth>
     228                            <DialogTitle sx={{display: 'flex', justifyContent: 'space-between', alignItems: 'center'}}>
     229                                All Favorited Builds
     230                                <IconButton onClick={() => setOpenFavoritesDialog(false)}>
     231                                    <CloseIcon/>
     232                                </IconButton>
     233                            </DialogTitle>
     234                            <DialogContent dividers>
     235                                <Grid container spacing={2} sx={{mt: 1}}>
     236                                    {data.favoriteBuilds.map((build: any) => (
     237                                        <Grid item xs={12} sm={6} md={4} key={build.id}>
     238                                            <BuildCard
     239                                                build={build}
     240                                                onClick={() => {
     241                                                    setOpenFavoritesDialog(false);
     242                                                    setSelectedBuildId(build.id);
     243                                                }}
     244                                            />
     245                                        </Grid>
     246                                    ))}
     247                                </Grid>
     248                            </DialogContent>
     249                            <DialogActions>
     250                                <Button onClick={() => setOpenFavoritesDialog(false)}>Close</Button>
     251                            </DialogActions>
     252                        </Dialog>
     253
    191254                    </Grid>
    192255                </Grid>
    193256            </Grid>
     257
     258            <BuildDetailsDialog
     259                open={!!selectedBuildId}
     260                buildId={selectedBuildId}
     261                currentUser={data?.user?.id ? Number(data.user.id) : undefined}
     262                onClose={() => {
     263                    setSelectedBuildId(null);
     264                    loadData();
     265                }}
     266                onClone={handleCloneWrapper}
     267            />
    194268        </Container>
    195269    );
    196270}
    197 
    198 function BuildCard({build, onDelete, isOwner}: { build: any, onDelete?: () => void, isOwner?: boolean }) {
    199     return (
    200         <Card sx={{height: '100%', display: 'flex', flexDirection: 'column'}}>
    201             <CardActionArea href={`/build/${build.id}`} sx={{flexGrow: 1}}>
    202                 <CardContent>
    203                     <Typography variant="subtitle1" fontWeight="bold" noWrap>
    204                         {build.name || `Build #${build.id}`}
    205                     </Typography>
    206                     <Typography variant="body2" color="text.secondary">
    207                         Created: {build.createdAt ? new Date(build.createdAt).toLocaleDateString() : 'Unknown'}
    208                     </Typography>
    209                 </CardContent>
    210             </CardActionArea>
    211 
    212             {isOwner && (
    213                 <Box sx={{display: 'flex', justifyContent: 'flex-end', p: 1, borderTop: '1px solid #eee'}}>
    214                     <IconButton size="small" href={`/build/edit/${build.id}`} color="primary">
    215                         <EditIcon fontSize="small"/>
    216                     </IconButton>
    217                     <IconButton size="small" onClick={onDelete} color="error">
    218                         <DeleteIcon fontSize="small"/>
    219                     </IconButton>
    220                 </Box>
    221             )}
    222         </Card>
    223     );
    224 }
Note: See TracChangeset for help on using the changeset viewer.