@@ -2,7 +2,7 @@ import { withRouter } from "react-router-dom";
2
2
import React , { useEffect , useState } from "react" ;
3
3
import { Button , ListGroupItem , Input , ListGroup , Col , Container } from "reactstrap" ;
4
4
import { TitleAndBreadcrumb } from "../../elements/TitleAndBreadcrumb" ;
5
- import { isEventLeaderOrStaff , isTutorOrAbove , siteSpecific } from "../../../services" ;
5
+ import { isEventLeaderOrStaff , isLoggedIn , isTutorOrAbove , siteSpecific } from "../../../services" ;
6
6
import { QuizSummaryDTO } from "../../../../IsaacApiTypes" ;
7
7
import { ShowLoading } from "../../handlers/ShowLoading" ;
8
8
import { useGetAvailableQuizzesQuery } from "../../../state/slices/api/quizApi" ;
@@ -11,23 +11,26 @@ import { Spacer } from "../../elements/Spacer";
11
11
import { Link } from "react-router-dom" ;
12
12
import { PageFragment } from "../../elements/PageFragment" ;
13
13
import { MainContent , PracticeQuizzesSidebar , SidebarLayout } from "../../elements/layout/SidebarLayout" ;
14
+ import { useUrlPageTheme } from "../../../services/pageContext" ;
15
+ import { selectors , useAppSelector } from "../../../state" ;
14
16
15
- const PracticeQuizzesComponent = ( { user } : QuizzesPageProps ) => {
17
+ const PracticeQuizzesComponent = ( props : QuizzesPageProps ) => {
16
18
const { data : quizzes } = useGetAvailableQuizzesQuery ( 0 ) ;
17
19
const [ filterText , setFilterText ] = useState < string > ( "" ) ;
18
20
const [ copied , setCopied ] = useState ( false ) ;
19
21
22
+ const user = useAppSelector ( selectors . user . orNull ) ;
23
+
24
+ const pageContext = useUrlPageTheme ( ) ;
25
+
20
26
useEffect ( ( ) => {
21
27
if ( location . search . includes ( "filter" ) ) {
22
28
setFilterText ( new URLSearchParams ( location . search ) . get ( "filter" ) || "" ) ;
23
29
}
24
30
} , [ ] ) ;
25
31
26
- if ( ! user ) {
27
- return < p > You must be logged in to view practice tests.</ p > ;
28
- }
29
-
30
32
const showQuiz = ( quiz : QuizSummaryDTO ) => {
33
+ if ( ! user || ! isLoggedIn ( user ) ) return false ;
31
34
switch ( user . role ) {
32
35
case "STUDENT" :
33
36
case "TUTOR" :
@@ -47,46 +50,49 @@ const PracticeQuizzesComponent = ({user}: QuizzesPageProps) => {
47
50
{ isTutorOrAbove ( user ) && ( ( quiz . hiddenFromRoles && ! quiz . hiddenFromRoles ?. includes ( "STUDENT" ) ) || quiz . visibleToStudents ) && < div className = "small text-muted d-block ms-2" > visible to students</ div > }
48
51
</ > ;
49
52
50
- return < Container >
53
+ return < Container { ... ( pageContext ?. subject && { "data-bs-theme" : pageContext . subject } ) } >
51
54
< TitleAndBreadcrumb currentPageTitle = { siteSpecific ( "Practice Tests" , "Practice tests" ) } />
52
55
< SidebarLayout >
53
56
< PracticeQuizzesSidebar />
54
57
< MainContent >
55
58
< PageFragment fragmentId = "help_toptext_practice_tests" />
56
- < ShowLoading until = { quizzes } >
57
- { quizzes && < >
58
- { quizzes . length === 0 && < p > < em > There are no practice tests currently available.</ em > </ p > }
59
- < Col xs = { 12 } className = "mb-4" >
60
- < Input type = "text" placeholder = "Filter tests by name..." value = { filterText } onChange = { ( e ) => setFilterText ( e . target . value ) } />
61
- < button className = { `copy-test-filter-link m-0 ${ copied ? "clicked" : "" } ` } tabIndex = { - 1 } onClick = { ( ) => {
62
- if ( filterText . trim ( ) ) {
63
- navigator . clipboard . writeText ( `${ window . location . host } ${ window . location . pathname } ?filter=${ filterText . trim ( ) } #practice` ) ;
64
- }
65
- setCopied ( true ) ;
66
- } } onMouseLeave = { ( ) => setCopied ( false ) } />
67
- </ Col >
68
- < ListGroup className = "mb-3 quiz-list" >
69
- { quizzes . filter ( ( quiz ) => showQuiz ( quiz ) && quiz . title ?. toLowerCase ( ) . includes ( filterText . toLowerCase ( ) ) ) . map ( quiz => < ListGroupItem className = "p-0 bg-transparent" key = { quiz . id } >
70
- < div className = "d-flex flex-grow-1 flex-column flex-sm-row align-items-center p-3" >
71
- < div >
72
- < span className = "mb-2 mb-sm-0 pe-2" > { quiz . title } </ span >
73
- { roleVisibilitySummary ( quiz ) }
74
- { quiz . summary && < div className = "small text-muted d-none d-md-block" > { quiz . summary } </ div > }
59
+ { ! user
60
+ ? < b > You must be logged in to view practice tests.</ b >
61
+ : < ShowLoading until = { quizzes } >
62
+ { quizzes && < >
63
+ { quizzes . length === 0 && < p > < em > There are no practice tests currently available.</ em > </ p > }
64
+ < Col xs = { 12 } className = "mb-4" >
65
+ < Input type = "text" placeholder = "Filter tests by name..." value = { filterText } onChange = { ( e ) => setFilterText ( e . target . value ) } />
66
+ < button className = { `copy-test-filter-link m-0 ${ copied ? "clicked" : "" } ` } tabIndex = { - 1 } onClick = { ( ) => {
67
+ if ( filterText . trim ( ) ) {
68
+ navigator . clipboard . writeText ( `${ window . location . host } ${ window . location . pathname } ?filter=${ filterText . trim ( ) } #practice` ) ;
69
+ }
70
+ setCopied ( true ) ;
71
+ } } onMouseLeave = { ( ) => setCopied ( false ) } />
72
+ </ Col >
73
+ < ListGroup className = "mb-3 quiz-list" >
74
+ { quizzes . filter ( ( quiz ) => showQuiz ( quiz ) && quiz . title ?. toLowerCase ( ) . includes ( filterText . toLowerCase ( ) ) ) . map ( quiz => < ListGroupItem className = "p-0 bg-transparent" key = { quiz . id } >
75
+ < div className = "d-flex flex-grow-1 flex-column flex-sm-row align-items-center p-3" >
76
+ < div >
77
+ < span className = "mb-2 mb-sm-0 pe-2" > { quiz . title } </ span >
78
+ { roleVisibilitySummary ( quiz ) }
79
+ { quiz . summary && < div className = "small text-muted d-none d-md-block" > { quiz . summary } </ div > }
80
+ </ div >
81
+ < Spacer />
82
+ { isTutorOrAbove ( user ) && < div className = "d-none d-md-flex align-items-center me-4" >
83
+ < Link to = { { pathname : `/test/preview/${ quiz . id } ` } } >
84
+ < span > Preview</ span >
85
+ </ Link >
86
+ </ div > }
87
+ < Button tag = { Link } to = { { pathname : `/test/attempt/${ quiz . id } ` } } >
88
+ { siteSpecific ( "Take Test" , "Take test" ) }
89
+ </ Button >
75
90
</ div >
76
- < Spacer />
77
- { isTutorOrAbove ( user ) && < div className = "d-none d-md-flex align-items-center me-4" >
78
- < Link to = { { pathname : `/test/preview/${ quiz . id } ` } } >
79
- < span > Preview</ span >
80
- </ Link >
81
- </ div > }
82
- < Button tag = { Link } to = { { pathname : `/test/attempt/${ quiz . id } ` } } >
83
- { siteSpecific ( "Take Test" , "Take test" ) }
84
- </ Button >
85
- </ div >
86
- </ ListGroupItem > ) }
87
- </ ListGroup >
88
- </ > }
89
- </ ShowLoading >
91
+ </ ListGroupItem > ) }
92
+ </ ListGroup >
93
+ </ > }
94
+ </ ShowLoading >
95
+ }
90
96
</ MainContent >
91
97
</ SidebarLayout >
92
98
</ Container > ;
0 commit comments