@@ -37,7 +37,7 @@ export default function AskQuestion() {
3737 const [ name , setName ] = useState ( '' ) ;
3838 const [ andrewID , setAndrewID ] = useState ( '' ) ;
3939 const [ location , setLocation ] = useState ( '' ) ;
40- const [ topic , setTopic ] = useState ( null ) ;
40+ const [ topicId , setTopicId ] = useState ( '' ) ;
4141 const [ question , setQuestion ] = useState ( '' ) ;
4242
4343 const [ showCooldownOverlay , setShowCooldownOverlay ] = useState ( false ) ;
@@ -68,23 +68,24 @@ export default function AskQuestion() {
6868
6969 const topics = useMemo ( ( ) => {
7070 if ( queueData != null ) {
71- const newRows = [ ] ;
71+ const shownTopics = new Map ( ) ;
7272 queueData . topics . forEach ( ( topic ) => {
7373 if (
7474 new Date ( topic . start_date ) <= new Date ( ) &&
7575 new Date ( topic . end_date ) > new Date ( )
7676 ) {
77- newRows . push ( topic ) ;
77+ shownTopics . set ( topic . assignment_id , topic ) ;
7878 }
7979 } ) ;
80- newRows . push ( createData ( - 1 , 'Other' ) ) ;
8180
82- if ( newRows . length === 1 ) {
83- setTopic ( newRows [ 0 ] ) ;
81+ shownTopics . set ( - 1 , createData ( - 1 , 'Other' ) ) ;
82+
83+ if ( shownTopics . size === 1 ) {
84+ setTopicId ( shownTopics . keys ( ) . next ( ) . value ) ;
8485 }
8586
86- return newRows ;
87- } else return [ createData ( - 1 , 'Other' ) ] ;
87+ return shownTopics ;
88+ } else return new Map ( [ [ - 1 , createData ( - 1 , 'Other' ) ] ] ) ;
8889 } , [ queueData . topics ] ) ;
8990
9091 useEffect ( ( ) => {
@@ -107,7 +108,7 @@ export default function AskQuestion() {
107108 andrewID : andrewID ,
108109 question : question ,
109110 location : location ,
110- topic : topic ,
111+ topic : topics . get ( topicId ) ,
111112 } ) ,
112113 )
113114 . then ( ( res ) => {
@@ -144,7 +145,7 @@ export default function AskQuestion() {
144145 setName ( '' ) ;
145146 setAndrewID ( '' ) ;
146147 setLocation ( '' ) ;
147- setTopic ( null ) ;
148+ setTopicId ( '' ) ;
148149 setQuestion ( '' ) ;
149150 }
150151
@@ -214,14 +215,14 @@ export default function AskQuestion() {
214215 < Select
215216 labelId = "topic-select-label"
216217 id = "topic-select"
217- value = { topic ?? '' }
218+ value = { topicId ?? '' }
218219 label = "Topic"
219- onChange = { ( e ) => setTopic ( e . target . value ) }
220+ onChange = { ( e ) => setTopicId ( e . target . value ) }
220221 style = { { textAlign : 'left' } }
221222 >
222- { topics . map ( ( top ) => (
223- < MenuItem value = { top } key = { top . assignment_id } >
224- { top . name }
223+ { Array . from ( topics . values ( ) ) . map ( ( topic ) => (
224+ < MenuItem value = { topic . assignment_id } key = { topic . assignment_id } >
225+ { topic . name }
225226 </ MenuItem >
226227 ) ) }
227228 </ Select >
@@ -271,7 +272,7 @@ export default function AskQuestion() {
271272 andrewID = { andrewID }
272273 question = { question }
273274 location = { location }
274- topic = { topic }
275+ topic = { topics . get ( topicId ) }
275276 />
276277 </ div >
277278 ) ;
0 commit comments