1import { Card, Divider, Link, Typography } from '@mui/material';
2import CircularProgress from '@mui/material/CircularProgress';
3import makeStyles from '@mui/styles/makeStyles';
4
5import Date from '../../components/Date';
6
7import { useGetBugsByUserQuery } from './GetBugsByUser.generated';
8
9const useStyles = makeStyles((theme) => ({
10 main: {
11 ...theme.typography.body2,
12 },
13 bugLink: {
14 ...theme.typography.button,
15 },
16 cards: {
17 backgroundColor: theme.palette.background.default,
18 color: theme.palette.info.contrastText,
19 padding: theme.spacing(1),
20 margin: theme.spacing(1),
21 },
22}));
23
24type Props = {
25 id: string;
26};
27
28function BugList({ id }: Props) {
29 const classes = useStyles();
30 const { loading, error, data } = useGetBugsByUserQuery({
31 variables: {
32 query: 'author:' + id + ' sort:creation',
33 },
34 });
35
36 if (loading) return <CircularProgress />;
37 if (error) return <p>Error: {error}</p>;
38 const bugs = data?.repository?.allBugs.nodes;
39
40 return (
41 <div className={classes.main}>
42 {bugs?.map((bug, index) => {
43 return (
44 <Card className={classes.cards} key={index}>
45 <Typography variant="overline" component="h2">
46 <Link
47 className={classes.bugLink}
48 href={'/bug/' + bug.id}
49 color={'inherit'}
50 underline="hover"
51 >
52 {bug.title}
53 </Link>
54 </Typography>
55 <Divider />
56 <Typography variant="subtitle2">
57 Created
58 <Date date={bug.createdAt} />
59 </Typography>
60 <Typography variant="subtitle2">
61 Last edited
62 <Date date={bug.createdAt} />
63 </Typography>
64 </Card>
65 );
66 })}
67 {bugs?.length === 0 && <p>No authored bugs by this user found.</p>}
68 </div>
69 );
70}
71
72export default BugList;