From f1dc2452906f2b229fb97e3d5894590544fb8ab2 Mon Sep 17 00:00:00 2001 From: ThatMegamind Date: Fri, 26 Apr 2024 12:54:00 -0700 Subject: [PATCH] changed double dropdown to single dropdown, visibility issue --- src/components/StatTable/StatTable.jsx | 126 +++++++++++++++++-------- 1 file changed, 88 insertions(+), 38 deletions(-) diff --git a/src/components/StatTable/StatTable.jsx b/src/components/StatTable/StatTable.jsx index 42008b7..0b3852a 100644 --- a/src/components/StatTable/StatTable.jsx +++ b/src/components/StatTable/StatTable.jsx @@ -2,23 +2,57 @@ import { useState, useEffect } from 'react'; import React from 'react'; import PropTypes from 'prop-types'; import { NPOBackend } from '../../utils/auth_utils'; -import { Select, useToast } from '@chakra-ui/react'; +import { Select } from '@chakra-ui/react'; import './StatTable.css'; const StatTable = ({ season, allSeasons }) => { const [stats, setStats] = useState([]); - const currSeason = season.split(' ')[0]; - const currYear = season.split(' ')[1] - const [selectedSeason, setSelectedSeason] = useState(currSeason.toLowerCase()); - const [selectedYear, setSelectedYear] = useState(currYear); - const uniqueSeasons = Array.from(new Set(allSeasons.map(season => season.split(' ')[0]))); - const uniqueYears = Array.from(new Set(allSeasons.map(seasonYear => seasonYear.split(' ')[1]))); - const toast = useToast(); + // const currSeason = season.split(' ')[0]; + // const currYear = season.split(' ')[1]; + // const [selectedSeason, setSelectedSeason] = useState(currSeason.toLowerCase()); + // const [selectedYear, setSelectedYear] = useState(currYear); + // const [allSeasons, setAllSeasons] = useState([]); + const [selectedSeason, setSelectedSeason] = useState(''); + // const uniqueSeasons = Array.from(new Set(allSeasons.map(season => season.split(' ')[0]))); + // const uniqueYears = Array.from(new Set(allSeasons.map(seasonYear => seasonYear.split(' ')[1]))); + // const toast = useToast(); + + console.log(season, allSeasons); + + // useEffect(() => { + // const renderTable = async () => { + // const { data } = await NPOBackend.get('/published-schedule/all-seasons'); + // if (data.indexOf(curSeason) == -1) { + // data.unshift(curSeason); + // } + + // setSelectedSeason(curSeason); + + // const seasonOrder = ['Fall', 'Summer', 'Spring']; + // data.sort((a, b) => { + // // Compare years first + // if (a.split(' ')[1] !== b.split(' ')[1]) { + // return b.split(' ')[1] - a.split(' ')[1]; + // } else { + // return seasonOrder.indexOf(a.split(' ')[0]) - seasonOrder.indexOf(b.split(' ')[0]); + // } + // }); + + // setAllSeasons(data); + + // }; + // renderTable(); + // }, [curSeason]); useEffect(() => { const fetchStats = async () => { try { - const response = await NPOBackend.get(`/published-schedule/stats?season=${selectedSeason}&year=${selectedYear}`); + if (!selectedSeason) { + setSelectedSeason(season); + } + const curSeason = selectedSeason.split(' ')[0]; + const curYear = selectedSeason.split(' ')[1]; + const response = await NPOBackend.get(`/published-schedule/stats?season=${curSeason.toLowerCase()}&year=${curYear}`); const data = response.data; setStats(data); } catch (error) { @@ -27,31 +61,31 @@ const StatTable = ({ season, allSeasons }) => { }; fetchStats(); - }, [selectedSeason, selectedYear]); - - const showToast = (title, description) => { - toast({ - title, - description, - status: 'success', - duration: 2000, - isClosable: true, - position: 'top', - colorScheme: 'blue' - }); - }; - - const handleSeasonChange = (event) => { - const newSeason = event.target.value; - setSelectedSeason(newSeason); - showToast('Season Changed', `${newSeason.toUpperCase()}`); - }; - - const handleYearChange = (event) => { - const newYear = event.target.value; - setSelectedYear(newYear); - showToast('Year Changed', `Selected year changed to ${newYear}`); - }; + }, [selectedSeason]); + + // const showToast = (title, description) => { + // toast({ + // title, + // description, + // status: 'success', + // duration: 2000, + // isClosable: true, + // position: 'top', + // colorScheme: 'blue' + // }); + // }; + + // const handleSeasonChange = (event) => { + // const newSeason = event.target.value; + // setSelectedSeason(newSeason); + // showToast('Season Changed', `${newSeason.toUpperCase()}`); + // }; + + // const handleYearChange = (event) => { + // const newYear = event.target.value; + // setSelectedYear(newYear); + // showToast('Year Changed', `Selected year changed to ${newYear}`); + // }; const transformData = () => { const transformedData = {}; @@ -76,7 +110,7 @@ const StatTable = ({ season, allSeasons }) => { return (
- {uniqueSeasons.map((season) => ( ))} + */} +
@@ -98,7 +148,7 @@ const StatTable = ({ season, allSeasons }) => { Event Type {Object.keys(transformedStats).length > 0 && Object.keys(transformedStats[Object.keys(transformedStats)[0]]).map(subject => ( - {subject} + {subject} ))} @@ -106,9 +156,9 @@ const StatTable = ({ season, allSeasons }) => { {Object.keys(transformedStats).map((eventType) => ( - {eventType} + {eventType} {Object.keys(transformedStats[eventType]).map(subject => ( - {transformedStats[eventType][subject]} + {transformedStats[eventType][subject]} ))}