@@ -15,6 +15,9 @@ const baseUrl = process.env.NEXT_PUBLIC_API_URL;
1515
1616export default function id ( ) {
1717 const [ open , setOpen ] = useState ( false ) ;
18+
19+
20+
1821 const router = useRouter ( ) ;
1922 const [ assignment , setAssignment ] = useState ( null ) ;
2023 const [ submission , setSubmission ] = useState ( null ) ;
@@ -23,9 +26,18 @@ export default function id() {
2326
2427 const [ formattedDate , setFormattedDate ] = useState ( null ) ;
2528 const [ loading , setLoading ] = useState ( true ) ;
29+ const [ isLoading , setIsLoading ] = useState ( true ) ;
2630 const [ player , setPlayer ] = useState ( null ) ;
2731 const [ kanaLog , setKanaLog ] = useState ( [ ] ) ;
2832
33+ const [ role , setRole ] = useState ( null ) ;
34+
35+ const [ kanaError , setKanaError ] = useState ( false ) ;
36+
37+
38+ const [ submissions , setSubmissions ] = useState ( [ ] ) ;
39+
40+
2941 console . log ( submission ) ;
3042
3143 // fetch kana log
@@ -130,6 +142,8 @@ export default function id() {
130142 events [ i ] . seconds = convert ( events [ i ] . timestamp ) ;
131143 }
132144
145+ setKanaError ( true ) ;
146+
133147 setKanaLog ( events ) ; // []
134148 } catch ( err ) {
135149 console . log ( err ) ;
@@ -139,6 +153,12 @@ export default function id() {
139153 useEffect ( ( ) => {
140154 if ( ! loading ) {
141155 getJson ( ) ;
156+ console . log ( "penguins" )
157+ console . log ( router . query . key )
158+ if ( router . query . key == "t" ) {
159+ setRole ( "t" ) ;
160+ }
161+
142162 }
143163 } , [ loading ] ) ;
144164
@@ -176,6 +196,93 @@ export default function id() {
176196 fetchSubmission ( ) ;
177197 } , [ ] ) ;
178198
199+ useEffect ( ( ) => {
200+ if ( assignment === null ) {
201+ getAssignment ( ) ;
202+ }
203+ } , [ ] ) ;
204+
205+
206+ // NEW SUBMISSION LOGIC
207+
208+ const parseDate = ( dateString ) => {
209+ const date = new Date ( dateString ) ;
210+ const offsetInMinutes = date . getTimezoneOffset ( ) ;
211+ date . setMinutes ( date . getMinutes ( ) + offsetInMinutes ) ;
212+ function to12HourFormat ( hour , minute ) {
213+ let period = hour >= 12 ? "PM" : "AM" ;
214+ hour = hour % 12 ;
215+ hour = hour ? hour : 12 ; // the hour '0' should be '12'
216+ return hour + ":" + minute . toString ( ) . padStart ( 2 , '0' ) + " " + period ;
217+ }
218+ const day = date . getDate ( ) ;
219+ const month = date . getMonth ( ) + 1 ; // Months are 0-based in JavaScript
220+ const year = date . getFullYear ( ) . toString ( ) . slice ( - 2 ) ;
221+ const hour = date . getHours ( ) ;
222+ const minute = date . getMinutes ( ) ;
223+ const time = to12HourFormat ( hour , minute ) ;
224+ const formattedDate = `${ month } /${ day } /${ year } ${ time } ` ;
225+ return formattedDate ;
226+ } ;
227+
228+ const getAssignment = async ( ) => {
229+ const params = window . location . href . split ( '/' ) ;
230+ if ( params . length < 5 ) {
231+ return ;
232+ }
233+ const url = `${ baseUrl } /classroom-assignments/fetch-assignment/${ params [ 4 ] } ` ;
234+ const data = await request ( url , 'GET' , null ) ;
235+ if ( data && data . success ) {
236+ const isAuth = await authenticate ( data . body ) ;
237+ if ( isAuth ) {
238+ setAssignment ( data . body ) ;
239+ getChallenge ( data . body ) ;
240+ await getSubmissions ( data . body ) ;
241+ } else {
242+ console . log ( 'You are not apart of this class' ) ;
243+ window . location . href = '/groups' ;
244+ }
245+ }
246+ } ;
247+
248+ const routeToSubmission = ( id ) => {
249+ console . log ( "going to submission" + id ) ;
250+ window . location . href = `/assignments/${ assignment . id } /submissions/${ id } ?key=t` ;
251+ } ;
252+
253+
254+
255+ const getSubmissions = async ( assignment ) => {
256+ const url = `${ baseUrl } /submission/getSubmissionsForTeachers/${ assignment . classroom . id } /${ assignment . id } ` ;
257+ const data = await request ( url , 'GET' , null ) ;
258+ if ( data && data . success ) {
259+ setSubmissions ( data . body ) ;
260+ setIsLoading ( false ) ;
261+ console . log ( 'Submissions:' , data . body ) ;
262+ } else {
263+ console . log ( 'Unable to get submissions' ) ;
264+ }
265+ } ;
266+
267+ const authenticate = async ( assignment ) => {
268+ const url = `${ baseUrl } /classroom/inClass/${ assignment . classroom . id } ` ;
269+ const data = await request ( url , 'GET' , null ) ;
270+ return data . success ;
271+ } ;
272+
273+ const getChallenge = async ( assignment ) => {
274+ try {
275+ const url = `${ baseUrl } /challenges/${ assignment . challenge . id } ?assignmentId=${ assignment . id } ` ;
276+ const data = await request ( url , 'GET' , null ) ;
277+ if ( data . success ) {
278+ setChallenge ( data . body ) ;
279+ }
280+ } catch ( err ) {
281+ console . log ( err ) ;
282+ }
283+ } ;
284+
285+
179286
180287 return (
181288 < >
@@ -203,7 +310,7 @@ export default function id() {
203310 </ a >
204311
205312 < div className = "w-full bg-gradient-to-r from-blue-800 via-blue-900 to-blue-800 px-4 py-4 " >
206- < div className = "mx-auto max-w-6xl " >
313+ < div className = "mx-auto px-2 " >
207314 < div className = "flex" >
208315 < div >
209316 < h1 className = "text-3xl font-semibold text-white" >
@@ -213,7 +320,18 @@ export default function id() {
213320 }
214321 </ h1 >
215322
216- < h1 className = "text-white" > Submitted at { formattedDate } </ h1 >
323+ < h1 className = "text-white mb-4" > Submitted at { formattedDate } </ h1 >
324+
325+ { /* go back */ }
326+ { assignment && (
327+ < a
328+ href = { `/assignments/teacher/${ assignment . id } ` }
329+ className = "text-blue-600 mt-4 px-3 font-semibold bg-white text-center rounded-lg hover:text-blue-600 hover:bg-gray-100 cursor-pointer"
330+ >
331+ Back to Assignment View
332+ </ a >
333+ ) }
334+
217335 </ div >
218336
219337 < div className = "ml-auto" >
@@ -226,10 +344,53 @@ export default function id() {
226344 </ div >
227345 </ div >
228346 </ div >
229- < div className = "mx-auto mt-4 max-w-6xl " >
347+ < div className = "mx-auto mt-4 px-4 " >
230348 < div className = "" >
231- < div className = "grid grid-cols-4 gap-x-8" >
232- < div className = "col-span-3" >
349+ < div className = "grid grid-cols-4 gap-x-8" >
350+
351+ { role === 't' && (
352+ < div className = 'col-span-1 mx-auto w-full' >
353+ { isLoading ? (
354+ < div >
355+ < i class = "fas fa-spinner fa-spin text-white text-3xl mx-auto text-center w-full mt-20" > </ i >
356+ < p className = 'text-white text-lg text-center mx-auto' > Fetching submissions...</ p >
357+ </ div >
358+ ) : (
359+ submissions . length === 0 && (
360+ < div style = { { color : 'white' } } >
361+ No students have completed this assignment yet.
362+ </ div >
363+ )
364+ ) }
365+ { submissions . map ( ( submission , idx ) => (
366+ < div
367+ key = { idx }
368+ className = "cursor-pointer rounded-lg bg-neutral-800 px-4 py-3 mb-2 text-white hover:bg-neutral-800/40"
369+ onClick = { ( ) => routeToSubmission ( submission . subId ) }
370+ >
371+ < h1 className = "flex" >
372+ { submission . name } { ' ' }
373+ { submission . submitted ? (
374+ < div className = "ml-auto" >
375+ < i
376+ title = "Completed!"
377+ className = "fas fa-check text-green-500"
378+ > </ i >
379+ </ div >
380+ ) : (
381+ < div className = "ml-auto" >
382+ < i
383+ title = "Incomplete!"
384+ className = " fas fa-clock text-red-400 "
385+ > </ i >
386+ </ div >
387+ ) }
388+ </ h1 >
389+ </ div >
390+ ) ) }
391+ </ div >
392+ ) }
393+ < div className = { role !== 't' ? "col-span-3" : "col-span-2" } >
233394 < div
234395 className = "h-1/2 w-full border border-neutral-800"
235396 id = "demo"
@@ -247,8 +408,8 @@ export default function id() {
247408 onClick = { ( ) => seekToTime ( item . seconds ) }
248409 className = "clickable cursor-pointer mb-10 ms-4 p-4 hover:bg-neutral-800"
249410 >
250- < div className = "absolute -start-1.5 mt-1.5 h-3 w-3 rounded-full border border-white bg- neutral-200 dark:border-neutral-900 dark: bg-neutral-700 " > </ div >
251- < time className = "mb-1 text-sm font-normal leading-none text-neutral-400 dark:text-neutral-500 " >
411+ < div className = "absolute -start-1.5 mt-1.5 h-3 w-3 rounded-full border border-neutral-800 bg-blue-500 " > </ div >
412+ < time className = "mb-1 text-sm font-normal leading-none text-neutral-400 " >
252413 { item . timestamp }
253414 </ time >
254415 < h3 className = "text-md font-semibold text-blue-400 " >
@@ -263,6 +424,20 @@ export default function id() {
263424 }
264425
265426 </ ol >
427+
428+
429+
430+ {
431+ ( kanaLog && kanaLog . length === 0 ) && (
432+ < div className = 'text-white text-lg text-center mx-auto bg-neutral-800 rounded-lg px-2 py-4' >
433+ < i class = "fas fa-spinner text-2xl fa-spin" > </ i >
434+ < h1 > We're still processing this session.</ h1 >
435+ < p className = 'text-sm' > You can still view the session recording.</ p >
436+ </ div >
437+ )
438+ }
439+
440+
266441 </ div >
267442
268443
0 commit comments