@@ -18,18 +18,45 @@ export const Questions = () => {
18
18
return i
19
19
}
20
20
21
+ // Add a new Question
21
22
const addQuestion = ( qTitle , qDifficulty , qTopic , qDescription ) => {
22
23
// Add in Database and Upload into Storage
23
24
let newQuestion = new QuestionModel ( qId , qTitle , qDescription , qDifficulty , qTopic ) ;
24
25
database . addQuestion ( newQuestion ) ;
26
+
27
+ updateLocalDatabase ( ) ;
28
+ updateStates ( ) ;
29
+
30
+ // setQs([...qs, {id: qId, title: qTitle, difficulty: qDifficulty,
31
+ // topic: qTopic, description: qDescription }]);
32
+ }
33
+
34
+ // Delete a Question
35
+ const deleteQuestion = ( questionId ) => {
36
+ database . deleteQuestion ( questionId ) ;
37
+
38
+ updateLocalDatabase ( ) ;
39
+ updateStates ( ) ;
40
+ }
41
+
42
+ // Update an existing Question
43
+ const updateQuestion = ( qId , qTitle , qDescription , qDifficulty , qTopic ) => {
44
+ let updatedQuestion = new QuestionModel ( qId , qTitle , qDescription , qDifficulty , qTopic ) ;
45
+ database . updateQuestion ( updatedQuestion ) ;
46
+
47
+ updateLocalDatabase ( ) ;
48
+ updateStates ( ) ;
49
+ }
50
+
51
+ const updateLocalDatabase = ( ) => {
52
+ // Updating Database in Local Storageß
25
53
updateLocalQuestionDatabase ( database ) ;
54
+ }
26
55
56
+ const updateStates = ( ) => {
27
57
// Update States
28
58
setQs ( Array . from ( database . database ) ) ;
29
59
setQId ( Array . from ( database . database ) . length ) ;
30
-
31
- // setQs([...qs, {id: qId, title: qTitle, difficulty: qDifficulty,
32
- // topic: qTopic, description: qDescription }]);
33
60
}
34
61
35
62
// To load data on mount
0 commit comments