@@ -14,6 +14,56 @@ import { AllStudentsContext } from '../../../contexts/AllStudentsContext';
1414import { socketSubscribeTo } from '../../../services/SocketsService' ;
1515import { QueueDataContext } from '../../../contexts/QueueDataContext' ;
1616
17+ const Filter = ( {
18+ filteredLocations,
19+ filteredTopics,
20+ setFilteredLocations,
21+ setFilteredTopics,
22+ } ) => {
23+ const [ anchorEl , setAnchorEl ] = useState ( null ) ;
24+
25+ const handleFilterDialog = ( event ) => {
26+ setAnchorEl ( event . currentTarget ) ;
27+ } ;
28+
29+ const handleFilterClose = ( ) => {
30+ setAnchorEl ( null ) ;
31+ } ;
32+
33+ const openFilterDialog = Boolean ( anchorEl ) ;
34+
35+ return (
36+ < div >
37+ < Button
38+ variant = "contained"
39+ startIcon = { < FilterListIcon /> }
40+ sx = { { fontWeight : 'bold' , mr : 1 } }
41+ onClick = { handleFilterDialog }
42+ aria-describedby = { 'popover' }
43+ >
44+ Filter
45+ </ Button >
46+ < Popover
47+ id = { 'popover' }
48+ open = { openFilterDialog }
49+ anchorEl = { anchorEl }
50+ onClose = { handleFilterClose }
51+ anchorOrigin = { {
52+ vertical : 'bottom' ,
53+ horizontal : 'left' ,
54+ } }
55+ >
56+ < FilterOptions
57+ filteredLocations = { filteredLocations }
58+ filteredTopics = { filteredTopics }
59+ setFilteredLocations = { setFilteredLocations }
60+ setFilteredTopics = { setFilteredTopics }
61+ />
62+ </ Popover >
63+ </ div >
64+ ) ;
65+ } ;
66+
1767export default function StudentEntries ( props ) {
1868 const { setQueueData } = useContext ( QueueDataContext ) ;
1969 const { userData } = useContext ( UserDataContext ) ;
@@ -75,48 +125,18 @@ export default function StudentEntries(props) {
75125 return newFiltered ;
76126 } , [ allStudents , filteredLocations , filteredTopics ] ) ;
77127
78- const Filter = ( ) => {
79- const handleFilterDialog = ( event ) => {
80- setAnchorEl ( event . currentTarget ) ;
81- } ;
82-
83- const [ anchorEl , setAnchorEl ] = useState ( null ) ;
84- const handleFilterClose = ( ) => {
85- setAnchorEl ( null ) ;
86- } ;
87- const openFilterDialog = Boolean ( anchorEl ) ;
88-
89- return (
90- < div >
91- < Button
92- variant = "contained"
93- startIcon = { < FilterListIcon /> }
94- sx = { { fontWeight : 'bold' , mr : 1 } }
95- onClick = { handleFilterDialog }
96- aria-describedby = { 'popover' }
97- >
98- Filter
99- </ Button >
100- < Popover
101- id = { 'popover' }
102- open = { openFilterDialog }
103- anchorEl = { anchorEl }
104- onClose = { handleFilterClose }
105- anchorOrigin = { {
106- vertical : 'bottom' ,
107- horizontal : 'left' ,
108- } }
109- >
110- < FilterOptions
111- filteredLocations = { filteredLocations }
112- filteredTopics = { filteredTopics }
113- setFilteredLocations = { setFilteredLocations }
114- setFilteredTopics = { setFilteredTopics }
115- />
116- </ Popover >
117- </ div >
128+ const FilterWithProps = useMemo ( ( ) => {
129+ return ( props ) => (
130+ < Filter
131+ filteredLocations = { filteredLocations }
132+ filteredTopics = { filteredTopics }
133+ setFilteredLocations = { setFilteredLocations }
134+ setFilteredTopics = { setFilteredTopics }
135+ { ...props }
136+ />
118137 ) ;
119- } ;
138+ } , [ filteredLocations , filteredTopics , setFilteredLocations , setFilteredTopics ] ) ;
139+
120140 /* END FILTER LOGIC (the actual filtering is in QUEUE LOGIC)*/
121141
122142 /* BEGIN QUEUE LOGIC */
@@ -228,7 +248,7 @@ export default function StudentEntries(props) {
228248 /* END QUEUE LOGIC */
229249
230250 return (
231- < BaseTable title = "Students" HeaderTailComp = { Filter } >
251+ < BaseTable title = "Students" HeaderTailComp = { FilterWithProps } >
232252 { filteredStudents . map ( ( student , index ) => (
233253 < StudentEntry
234254 isHelping = { isHelping }
0 commit comments