Skip to content

Commit

Permalink
Feature: transfer list, conference filter now works on committed team
Browse files Browse the repository at this point in the history
  • Loading branch information
esmalleydev committed May 8, 2024
1 parent e0ea988 commit 8a79df7
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 13 deletions.
20 changes: 20 additions & 0 deletions app/cbb/ranking/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ async function getData(searchParams) {
}
});

const team_season_conferences = await useServerAPI({
'class': 'team_season_conference',
'function': 'read',
'arguments': {
'season': season,
'team_id': Object.values(teams).map(team => team.team_id),
}
});

const team_id_x_team_season_conference_id = {};
for (let team_season_conference_id in team_season_conferences) {
const row = team_season_conferences[team_season_conference_id];
team_id_x_team_season_conference_id[row.team_id] = team_season_conference_id;
}

const player_id_x_cbb_transfer_player_season = {}
for (let cbb_transfer_player_season_id in cbb_transfer_player_seasons) {
player_id_x_cbb_transfer_player_season[cbb_transfer_player_seasons[cbb_transfer_player_season_id].player_id] = cbb_transfer_player_seasons[cbb_transfer_player_season_id];
Expand All @@ -106,6 +121,11 @@ async function getData(searchParams) {
data[id].committed = player_id_x_cbb_transfer_player_season[data[id].player_id].committed;
data[id].committed_team_id = player_id_x_cbb_transfer_player_season[data[id].player_id].committed_team_id;
data[id].committed_team_name = (data[id].committed_team_id in teams ? teams[data[id].committed_team_id].alt_name : '-');
data[id].committed_conference = (
data[id].committed_team_id && data[id].committed_team_id in team_id_x_team_season_conference_id ?
team_season_conferences[team_id_x_team_season_conference_id[data[id].committed_team_id]].conference :
null
);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/cbb/ranking/ranking-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ const Ranking = (props) => {
const orderBy = useAppSelector(state => state.rankingReducer.orderBy);
const hideCommitted = useAppSelector(state => state.rankingReducer.hideCommitted);
const hideUnderTwoMPG = useAppSelector(state => state.rankingReducer.hideUnderTwoMPG);
const filterCommittedConf = useAppSelector(state => state.rankingReducer.filterCommittedConf);
const filterOriginalConf = useAppSelector(state => state.rankingReducer.filterOriginalConf);
const tableScrollTop = useAppSelector(state => state.rankingReducer.tableScrollTop);

interface TableComponentsType {
Expand Down Expand Up @@ -263,7 +265,7 @@ const Ranking = (props) => {

const headCells = getHeaderColumns({rankView});

const rowsData = getRowsData({ data, rankView, conferences, positions, hideCommitted, hideUnderTwoMPG });
const rowsData = getRowsData({ data, rankView, conferences, positions, hideCommitted, hideUnderTwoMPG, filterCommittedConf, filterOriginalConf });
let rows = rowsData.rows;
let lastUpdated = rowsData.lastUpdated;

Expand Down
20 changes: 19 additions & 1 deletion app/cbb/ranking/rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,38 @@ interface rowDatatype {
opponent_efficiency_rating_rank: number;
};

export const getRowsData = ({ data, rankView, conferences, positions, hideCommitted, hideUnderTwoMPG }) => {
export const getRowsData = ({ data, rankView, conferences, positions, hideCommitted, hideUnderTwoMPG, filterCommittedConf, filterOriginalConf }) => {
let rows: rowDatatype[] = [];
let lastUpdated: string | null = null;

for (let id in data) {
let row = data[id];

if (
rankView !== 'transfer' &&
conferences.length &&
conferences.indexOf(row.conference) === -1
) {
continue;
}

// if transfer and conference is not in original or new conf conference, remove them
if (
rankView === 'transfer' &&
conferences.length &&
(
(
filterOriginalConf && filterCommittedConf && (conferences.indexOf(row.conference) === -1 && conferences.indexOf(row.committed_conference) === -1)
) ||
(
(!filterCommittedConf && filterOriginalConf && conferences.indexOf(row.conference) === -1) || (!filterOriginalConf && filterCommittedConf && conferences.indexOf(row.committed_conference) === -1)
)
)
) {
continue;
}


// transfers
if (hideCommitted && +row.committed === 1) {
continue;
Expand Down
2 changes: 2 additions & 0 deletions components/generic/CBB/ConferencePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
import { useAppDispatch, useAppSelector } from '@/redux/hooks';
import { updateConferences } from '@/redux/features/display-slice';

// todo put these in url?

const ConferencePicker = () => {
const dispatch = useAppDispatch();
const conferences = useAppSelector(state => state.displayReducer.conferences);
Expand Down
43 changes: 33 additions & 10 deletions components/generic/CBB/Ranking/AdditionalOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import IconButton from '@mui/material/IconButton';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';

import { ListItemIcon, ListItemText, Tooltip } from '@mui/material';
import { Divider, ListItemIcon, ListItemText, Tooltip } from '@mui/material';
import { useAppDispatch, useAppSelector } from '@/redux/hooks';
import { setHideCommitted, setHideUnderTwoMPG } from '@/redux/features/ranking-slice';
import BackdropLoader from '@/components/generic/BackdropLoader';
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
import ConferenceFilterOptions from './ConferenceFilterOptions';

const AdditionalOptions = ({ view }: {view: string}) => {
const router = useRouter();
Expand All @@ -22,6 +23,7 @@ const AdditionalOptions = ({ view }: {view: string}) => {
const [isPending, startTransition] = useTransition();
const [spin, setSpin] = useState(false);
const [anchor, setAnchor] = useState(null);
const [confOptionsOpen, setConfOptionsOpen] = useState(false);
const open = Boolean(anchor);

const dispatch = useAppDispatch();
Expand Down Expand Up @@ -71,6 +73,11 @@ const AdditionalOptions = ({ view }: {view: string}) => {
});
};

const handleConferenceFilter = () => {
handleClose();
setConfOptionsOpen(true);
};

const getMenuItems = () => {
const menuItems: React.JSX.Element[] = [];

Expand Down Expand Up @@ -100,6 +107,21 @@ const AdditionalOptions = ({ view }: {view: string}) => {
);
}

if (view === 'transfer') {
menuItems.push(<Divider />);

menuItems.push(
<MenuItem key='conf-picker-options' onClick={() => {
handleConferenceFilter();
}}>
<ListItemIcon>
<SettingsIcon fontSize='small' />
</ListItemIcon>
<ListItemText>Conference filter</ListItemText>
</MenuItem>
);
}

return menuItems;
};

Expand All @@ -117,15 +139,16 @@ const AdditionalOptions = ({ view }: {view: string}) => {
>
<SettingsIcon />
</IconButton>
</Tooltip>
<Menu
id="long-menu"
anchorEl={anchor}
open={open}
onClose={handleClose}
>
{getMenuItems()}
</Menu>
</Tooltip>
<Menu
id="long-menu"
anchorEl={anchor}
open={open}
onClose={handleClose}
>
{getMenuItems()}
</Menu>
<ConferenceFilterOptions open={confOptionsOpen} onClose = {() => setConfOptionsOpen(false)} />
</div>
);
}
Expand Down
78 changes: 78 additions & 0 deletions components/generic/CBB/Ranking/ConferenceFilterOptions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React, { useState, useTransition } from 'react';

import CloseIcon from '@mui/icons-material/Close';
import Dialog from '@mui/material/Dialog';
import DialogContent from '@mui/material/DialogContent';
import DialogTitle from '@mui/material/DialogTitle';
import { FormControlLabel, FormGroup, IconButton, Switch } from '@mui/material';
import { useAppDispatch, useAppSelector } from '@/redux/hooks';
import { setFilterCommittedConf, setFilterOriginalConf } from '@/redux/features/ranking-slice';
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
import BackdropLoader from '@/components/generic/BackdropLoader';

const ConferenceFilterOptions = ({ open, onClose }) => {
const router = useRouter();
const pathName = usePathname();
const searchParams = useSearchParams();
const [isPending, startTransition] = useTransition();
const [spin, setSpin] = useState(false);

const dispatch = useAppDispatch();
const filterCommittedConf = useAppSelector(state => state.rankingReducer.filterCommittedConf);
const filterOriginalConf = useAppSelector(state => state.rankingReducer.filterOriginalConf);

const handleOrginalConfSwitch = (event: React.ChangeEvent<HTMLInputElement>) => {
const newValue: boolean = event.target.checked;
setSpin(true);
startTransition(() => {
if (newValue !== filterOriginalConf) {
const current = new URLSearchParams(Array.from(searchParams.entries()));
current.set('filterOriginalConf', (+newValue).toString());
const search = current.toString();
const query = search ? `?${search}` : "";
router.replace(`${pathName}${query}`);
dispatch(setFilterOriginalConf(newValue));
}
setSpin(false);
});
};

const handleCommittedConfSwitch = (event: React.ChangeEvent<HTMLInputElement>) => {
const newValue: boolean = event.target.checked;
setSpin(true);
startTransition(() => {
if (newValue !== filterCommittedConf) {
const current = new URLSearchParams(Array.from(searchParams.entries()));
current.set('filterCommittedConf', (+newValue).toString());
const search = current.toString();
const query = search ? `?${search}` : "";
router.replace(`${pathName}${query}`);
dispatch(setFilterCommittedConf(newValue));
}
setSpin(false);
});
};

return (
<>
<Dialog
open={open}
onClose={onClose}
>
<BackdropLoader open = {spin} />
<DialogTitle id="alert-dialog-title">
{'Conference filter options'}
{<IconButton aria-label="close" onClick={onClose}><CloseIcon /></IconButton>}
</DialogTitle>
<DialogContent>
<FormGroup>
<FormControlLabel control={<Switch checked = {filterOriginalConf} onChange={handleOrginalConfSwitch} />} label = 'Include Previous team' />
<FormControlLabel control={<Switch checked = {filterCommittedConf} onChange={handleCommittedConfSwitch} />} label = 'Include New team' />
</FormGroup>
</DialogContent>
</Dialog>
</>
);
}

export default ConferenceFilterOptions;
20 changes: 19 additions & 1 deletion redux/features/ranking-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type InitialState = {
orderBy: string,
hideCommitted: boolean,
hideUnderTwoMPG: boolean,
filterCommittedConf: boolean,
filterOriginalConf: boolean,
tableScrollTop: number,
};

Expand All @@ -23,6 +25,8 @@ const initialState = {
orderBy: 'composite_rank',
hideCommitted: false,
hideUnderTwoMPG: false,
filterCommittedConf: true,
filterOriginalConf: true,
tableScrollTop: 0,
} as InitialState;

Expand All @@ -33,6 +37,8 @@ const updateStateFromUrlParams = (state: InitialState) => {
const urlParams = new URLSearchParams(window.location.search);
const hideCommitted = urlParams.get('hideCommitted');
const hideUnderTwoMPG = urlParams.get('hideUnderTwoMPG');
const filterCommittedConf = urlParams.get('filterCommittedConf');
const filterOriginalConf = urlParams.get('filterOriginalConf');
// const view = urlParams.get('view');

// Update state if URL parameters are present
Expand All @@ -42,6 +48,12 @@ const updateStateFromUrlParams = (state: InitialState) => {
if (hideUnderTwoMPG !== null) {
state.hideUnderTwoMPG = (+hideUnderTwoMPG === 1);
}
if (filterCommittedConf !== null) {
state.filterCommittedConf = (+filterCommittedConf === 1);
}
if (filterOriginalConf !== null) {
state.filterOriginalConf = (+filterOriginalConf === 1);
}

// if (view !== null) {
// state.view = view;
Expand All @@ -64,6 +76,12 @@ export const ranking = createSlice({
setHideUnderTwoMPG: (state, action: PayloadAction<boolean>) => {
state.hideUnderTwoMPG = action.payload;
},
setFilterCommittedConf: (state, action: PayloadAction<boolean>) => {
state.filterCommittedConf = action.payload;
},
setFilterOriginalConf: (state, action: PayloadAction<boolean>) => {
state.filterOriginalConf = action.payload;
},
setTableScrollTop: (state, action: PayloadAction<number>) => {
state.tableScrollTop = action.payload;
},
Expand All @@ -73,7 +91,7 @@ export const ranking = createSlice({
}
});

export const { setOrder, setOrderBy, setHideCommitted, setHideUnderTwoMPG, setTableScrollTop } = ranking.actions;
export const { setOrder, setOrderBy, setHideCommitted, setHideUnderTwoMPG, setFilterCommittedConf, setFilterOriginalConf, setTableScrollTop } = ranking.actions;
export default ranking.reducer;

updateStateFromUrlParams(initialState);

0 comments on commit 8a79df7

Please sign in to comment.