@@ -7,60 +7,105 @@ import {
7
7
Typography ,
8
8
useTheme ,
9
9
} from "@mui/material" ;
10
- import { FunctionComponent , useEffect , useReducer } from "react" ;
10
+ import { useEffect , useState } from "react" ;
11
11
import { useParams } from "react-router-dom" ;
12
12
import Markdown from "markdown-to-jsx" ;
13
13
import AppMargin from "../../components/AppMargin" ;
14
- import reducer , {
15
- getQuestionById ,
16
- initialState ,
17
- } from "../../reducers/questionReducer" ;
18
14
import { grey } from "@mui/material/colors" ;
15
+ import classes from "./index.module.css" ;
16
+ import NotFound from "../../components/NotFound" ;
19
17
20
- const QuestionDetail : FunctionComponent = ( ) => {
18
+ type Question = {
19
+ title : string ;
20
+ description : string ;
21
+ complexity : string ;
22
+ categories : Array < string > ;
23
+ } ;
24
+
25
+ const QuestionDetail : React . FC = ( ) => {
21
26
const { questionId } = useParams < { questionId : string } > ( ) ;
22
- const [ state , dispatch ] = useReducer ( reducer , initialState ) ;
27
+ const [ question , setQuestion ] = useState < Question | null > ( null ) ;
28
+ const [ isLoading , setIsLoading ] = useState ( true ) ;
23
29
const theme = useTheme ( ) ;
24
30
25
31
useEffect ( ( ) => {
26
32
if ( ! questionId ) {
33
+ setIsLoading ( false ) ;
27
34
return ;
28
35
}
29
- getQuestionById ( questionId , dispatch ) ;
30
- // eslint-disable-next-line react-hooks/exhaustive-deps
36
+
37
+ // TODO: fetch question
38
+ const md =
39
+ "# Sample header 1\n" +
40
+ "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<br /><br />" +
41
+ "**Example ordered list:**\n" +
42
+ "1. Item 1\n" +
43
+ "2. `Item 2`\n\n" +
44
+ "*Example unordered list:*\n" +
45
+ "- Item 1\n" +
46
+ "- Item 2" ;
47
+ setQuestion ( {
48
+ title : "Test Question" ,
49
+ description : md ,
50
+ complexity : "Medium" ,
51
+ categories : [ "Category 1" , "Category 2" ] ,
52
+ } ) ;
53
+ setIsLoading ( false ) ;
31
54
} , [ ] ) ;
32
55
33
- if ( ! state . selectedQuestion ) {
34
- return ;
56
+ if ( ! question ) {
57
+ if ( isLoading ) {
58
+ return (
59
+ < AppMargin classname = { `${ classes . fullheight } ${ classes . center } ` } >
60
+ < NotFound
61
+ title = "Question not found..."
62
+ subtitle = "Unfortunately, we can't find what you're looking for 😥"
63
+ />
64
+ </ AppMargin >
65
+ ) ;
66
+ } else {
67
+ return ;
68
+ }
35
69
}
36
70
37
71
return (
38
72
< AppMargin >
39
- < Box sx = { { marginTop : theme . spacing ( 4 ) , marginBottom : theme . spacing ( 4 ) } } >
73
+ < Box
74
+ sx = { ( theme ) => ( {
75
+ marginTop : theme . spacing ( 4 ) ,
76
+ marginBottom : theme . spacing ( 4 ) ,
77
+ } ) }
78
+ >
40
79
< Box
41
- sx = { { marginTop : theme . spacing ( 4 ) , marginBottom : theme . spacing ( 4 ) } }
80
+ sx = { ( theme ) => ( {
81
+ marginTop : theme . spacing ( 4 ) ,
82
+ marginBottom : theme . spacing ( 4 ) ,
83
+ } ) }
42
84
>
43
85
< Typography component = { "h1" } variant = "h3" >
44
- { state . selectedQuestion . title }
86
+ { question . title }
45
87
</ Typography >
46
- < Stack direction = { "row" } sx = { { marginTop : theme . spacing ( 2 ) } } >
88
+ < Stack
89
+ direction = { "row" }
90
+ sx = { ( theme ) => ( { marginTop : theme . spacing ( 2 ) } ) }
91
+ >
47
92
< Chip
48
- key = { state . selectedQuestion . complexity }
49
- label = { state . selectedQuestion . complexity }
93
+ key = { question . complexity }
94
+ label = { question . complexity }
50
95
color = "primary"
51
- sx = { {
96
+ sx = { ( theme ) => ( {
52
97
marginLeft : theme . spacing ( 1 ) ,
53
98
marginRight : theme . spacing ( 1 ) ,
54
- } }
99
+ } ) }
55
100
/>
56
- { state . selectedQuestion . categories . map ( ( cat ) => (
101
+ { question . categories . map ( ( cat ) => (
57
102
< Chip
58
103
key = { cat }
59
104
label = { cat }
60
- sx = { {
105
+ sx = { ( theme ) => ( {
61
106
marginLeft : theme . spacing ( 1 ) ,
62
107
marginRight : theme . spacing ( 1 ) ,
63
- } }
108
+ } ) }
64
109
/>
65
110
) ) }
66
111
</ Stack >
@@ -119,7 +164,7 @@ const QuestionDetail: FunctionComponent = () => {
119
164
} ,
120
165
} }
121
166
>
122
- { state . selectedQuestion . description }
167
+ { question . description }
123
168
</ Markdown >
124
169
</ Box >
125
170
</ AppMargin >
0 commit comments