Skip to content

Commit cf91749

Browse files
committed
fixed select display bug
1 parent f1dc245 commit cf91749

File tree

3 files changed

+13
-98
lines changed

3 files changed

+13
-98
lines changed

src/components/Events/PublishedScheduleTable.jsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const PublishedScheduleTable = ({ season, allSeasons }) => {
7777
>
7878
Stats
7979
</IconButton>
80-
80+
8181
<IconButton
8282
bgColor="blue.700"
8383
color="gray.50"
@@ -98,8 +98,9 @@ const PublishedScheduleTable = ({ season, allSeasons }) => {
9898
}
9999

100100
<AddDayModal isOpenDay={isOpenDay} onCloseDay={onCloseDay} setShouldDataRevalidate={setShouldDataRevalidate}/>
101-
102-
<StatModal isOpen={isOpenStats} onClose={onCloseStats} season={season} allSeasons={allSeasons}/>
101+
{ season && allSeasons &&
102+
<StatModal isOpen={isOpenStats} onClose={onCloseStats} season={season} allSeasons={allSeasons}/>
103+
}
103104

104105
<TableContainer borderWidth={1} borderRadius="10px">
105106
<Table variant="simple">

src/components/StatTable/StatTable.jsx

+7-86
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,16 @@ import { useState, useEffect } from 'react';
22
import React from 'react';
33
import PropTypes from 'prop-types';
44
import { NPOBackend } from '../../utils/auth_utils';
5-
import { Select } from '@chakra-ui/react';
5+
import { Box, Select } from '@chakra-ui/react';
66
import './StatTable.css';
77

88
const StatTable = ({ season, allSeasons }) => {
99
const [stats, setStats] = useState([]);
10-
// const currSeason = season.split(' ')[0];
11-
// const currYear = season.split(' ')[1];
12-
// const [selectedSeason, setSelectedSeason] = useState(currSeason.toLowerCase());
13-
// const [selectedYear, setSelectedYear] = useState(currYear);
14-
// const [allSeasons, setAllSeasons] = useState([]);
15-
const [selectedSeason, setSelectedSeason] = useState('');
16-
// const uniqueSeasons = Array.from(new Set(allSeasons.map(season => season.split(' ')[0])));
17-
// const uniqueYears = Array.from(new Set(allSeasons.map(seasonYear => seasonYear.split(' ')[1])));
18-
// const toast = useToast();
19-
20-
console.log(season, allSeasons);
21-
22-
// useEffect(() => {
23-
// const renderTable = async () => {
24-
// const { data } = await NPOBackend.get('/published-schedule/all-seasons');
25-
// if (data.indexOf(curSeason) == -1) {
26-
// data.unshift(curSeason);
27-
// }
28-
29-
// setSelectedSeason(curSeason);
30-
31-
// const seasonOrder = ['Fall', 'Summer', 'Spring'];
32-
// data.sort((a, b) => {
33-
// // Compare years first
34-
// if (a.split(' ')[1] !== b.split(' ')[1]) {
35-
// return b.split(' ')[1] - a.split(' ')[1];
36-
// } else {
37-
// return seasonOrder.indexOf(a.split(' ')[0]) - seasonOrder.indexOf(b.split(' ')[0]);
38-
// }
39-
// });
40-
41-
// setAllSeasons(data);
42-
43-
// };
44-
// renderTable();
45-
// }, [curSeason]);
10+
const [selectedSeason, setSelectedSeason] = useState(season);
4611

4712
useEffect(() => {
4813
const fetchStats = async () => {
4914
try {
50-
if (!selectedSeason) {
51-
setSelectedSeason(season);
52-
}
5315
const curSeason = selectedSeason.split(' ')[0];
5416
const curYear = selectedSeason.split(' ')[1];
5517
const response = await NPOBackend.get(`/published-schedule/stats?season=${curSeason.toLowerCase()}&year=${curYear}`);
@@ -63,30 +25,6 @@ const StatTable = ({ season, allSeasons }) => {
6325
fetchStats();
6426
}, [selectedSeason]);
6527

66-
// const showToast = (title, description) => {
67-
// toast({
68-
// title,
69-
// description,
70-
// status: 'success',
71-
// duration: 2000,
72-
// isClosable: true,
73-
// position: 'top',
74-
// colorScheme: 'blue'
75-
// });
76-
// };
77-
78-
// const handleSeasonChange = (event) => {
79-
// const newSeason = event.target.value;
80-
// setSelectedSeason(newSeason);
81-
// showToast('Season Changed', `${newSeason.toUpperCase()}`);
82-
// };
83-
84-
// const handleYearChange = (event) => {
85-
// const newYear = event.target.value;
86-
// setSelectedYear(newYear);
87-
// showToast('Year Changed', `Selected year changed to ${newYear}`);
88-
// };
89-
9028
const transformData = () => {
9129
const transformedData = {};
9230

@@ -108,30 +46,13 @@ const StatTable = ({ season, allSeasons }) => {
10846
const transformedStats = transformData();
10947

11048
return (
111-
<div className='container'>
112-
<div className='select-container'>
113-
{/* <Select variant='filled' size='md' width = '200px' marginTop='20px' marginRight='20px' transition='all 0.3s ease' value={selectedSeason} onChange={handleSeasonChange}>
114-
{uniqueSeasons.map((season) => (
115-
<option key={season} value={season.toLowerCase()}>
116-
{season}
117-
</option>
118-
))}
119-
</Select>
120-
<Select variant='filled' size='md' width='200px' marginTop='20px' value={selectedYear} onChange={handleYearChange}>
121-
{uniqueYears.map((seasonYear) => (
122-
<option key={seasonYear} value={seasonYear}>
123-
{seasonYear}
124-
</option>
125-
))}
126-
</Select> */}
49+
<Box>
50+
<Box mt="1rem">
12751
<Select
128-
mb="3vh"
129-
variant="unstyled"
13052
textColor="black"
131-
placeholder={allSeasons.indexOf(season) === -1 && season}
13253
value={selectedSeason}
13354
onChange={(e) => setSelectedSeason(e.target.value)}
134-
width="23%"
55+
width="max-content"
13556
>
13657
{allSeasons.map(item => (
13758
<option key={item} value={item}>
@@ -140,7 +61,7 @@ const StatTable = ({ season, allSeasons }) => {
14061
))
14162
}
14263
</Select>
143-
</div>
64+
</Box>
14465
<div className='table-container'>
14566
<table>
14667
<thead>
@@ -166,7 +87,7 @@ const StatTable = ({ season, allSeasons }) => {
16687
</tbody>
16788
</table>
16889
</div>
169-
</div>
90+
</Box>
17091
);
17192
};
17293

src/pages/PublishedSchedule/StatisticsModal.jsx

+2-9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import {
44
ModalOverlay,
55
ModalContent,
66
ModalBody,
7-
Button,
8-
Flex,
7+
ModalCloseButton,
98
} from '@chakra-ui/react';
109
import StatTable from '../../components/StatTable/StatTable';
1110

@@ -15,14 +14,8 @@ const StatModal = ({ isOpen, onClose, season, allSeasons }) => {
1514
<Modal isOpen={isOpen} onClose={onClose}>
1615
<ModalOverlay />
1716
<ModalContent maxWidth={'fit-content'}>
17+
<ModalCloseButton />
1818
<ModalBody>
19-
<Flex justifyContent="space-between" alignItems="center" marginBottom="0rem">
20-
<Button colorScheme="blue" onClick={onClose} variant="outline">
21-
Close
22-
</Button>
23-
<h1 style={{ textAlign: 'center', fontWeight:'normal', fontSize: '1.75rem', margin: '0 5rem 0 0' }}>Season Summary</h1>
24-
<div></div>
25-
</Flex>
2619
<StatTable season={season} allSeasons={allSeasons}/>
2720
</ModalBody>
2821
</ModalContent>

0 commit comments

Comments
 (0)