89 lines
2.5 KiB
TypeScript
89 lines
2.5 KiB
TypeScript
import {
|
|
Button,
|
|
Card,
|
|
CardActions,
|
|
CardContent,
|
|
Grid,
|
|
TextField,
|
|
Typography,
|
|
} from '@mui/material';
|
|
import React from 'react';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { Context } from '../data/Context';
|
|
import { Competiton } from '../models/Competition';
|
|
|
|
/**
|
|
*
|
|
* @return {JSX.Element} calendar page
|
|
*/
|
|
export default function CalendarPage() {
|
|
const [competitions, setCompetitions] = React.useState<Competiton[]>([]);
|
|
const { api } = React.useContext(Context);
|
|
const navigate = useNavigate();
|
|
|
|
React.useEffect(() => {
|
|
api.getCompetitions('GER').then(result => {
|
|
console.log(result.competitions.filter);
|
|
setCompetitions(
|
|
result.competitions.filter(competition =>
|
|
competition.discipline?.includes('speed'),
|
|
),
|
|
);
|
|
});
|
|
}, []);
|
|
|
|
const openCompetition = (competitionId: string, categoryId: string) => {
|
|
navigate(`/speed-flowchart/${competitionId}/${categoryId}`);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Grid container spacing={2}>
|
|
<Grid item xs={12}>
|
|
<TextField
|
|
label='search for competition'
|
|
variant='outlined'
|
|
fullWidth
|
|
/>
|
|
</Grid>
|
|
{competitions.map(competition => (
|
|
<Grid item key={`competition-card-${competition.WetId}`} xs={12}>
|
|
<Card>
|
|
<CardContent>
|
|
<Typography gutterBottom variant='h5' component='div'>
|
|
{competition.name}
|
|
</Typography>
|
|
<Typography variant='body2' color='text.secondary'>
|
|
{competition.date_span}
|
|
</Typography>
|
|
</CardContent>
|
|
<CardActions>
|
|
<Grid container spacing={2}>
|
|
{competition.cats.map(category => (
|
|
<Grid
|
|
item
|
|
key={`competition-card-${competition.WetId}-category-button-${category.GrpId}`}
|
|
xs
|
|
>
|
|
<Button
|
|
size='small'
|
|
fullWidth
|
|
sx={{ width: '100%' }}
|
|
onClick={() =>
|
|
openCompetition(competition.WetId, category.GrpId)
|
|
}
|
|
>
|
|
{category.name}
|
|
</Button>
|
|
</Grid>
|
|
))}
|
|
</Grid>
|
|
</CardActions>
|
|
</Card>
|
|
</Grid>
|
|
))}
|
|
</Grid>
|
|
</>
|
|
);
|
|
}
|