@@ -20,30 +20,39 @@ export const Questions = () => {
20
20
const addQuestion = ( qTitle , qDifficulty , qTopic , qDescription ) => {
21
21
// Add in Database and Upload into Storage
22
22
let newQuestion = new QuestionModel ( qId , qTitle , qDescription , qDifficulty , qTopic ) ;
23
- database . addQuestion ( newQuestion ) ;
23
+ let isAddedSuccessfully = database . addQuestion ( newQuestion ) ;
24
24
25
25
updateLocalDatabase ( ) ;
26
26
updateStates ( ) ;
27
27
28
- // setQs([...qs, {id: qId, title: qTitle, difficulty: qDifficulty,
29
- // topic: qTopic, description: qDescription }]);
28
+ console . log ( "Is Additon Successful: " + isAddedSuccessfully ) ;
29
+
30
+ return isAddedSuccessfully ;
30
31
}
31
32
32
33
// Delete a Question
33
34
const deleteQuestion = ( questionId ) => {
34
- database . deleteQuestion ( questionId ) ;
35
+ let isDeletedSuccessfully = database . deleteQuestion ( questionId ) ;
35
36
36
37
updateLocalDatabase ( ) ;
37
38
updateStates ( ) ;
39
+
40
+ console . log ( "Is Deletion Successful: " + isDeletedSuccessfully ) ;
41
+
42
+ return isDeletedSuccessfully ;
38
43
}
39
44
40
45
// Update an existing Question
41
46
const updateQuestion = ( qId , qTitle , qDescription , qDifficulty , qTopic ) => {
42
47
let updatedQuestion = new QuestionModel ( qId , qTitle , qDescription , qDifficulty , qTopic ) ;
43
- database . updateQuestion ( updatedQuestion ) ;
48
+ let isUpdateSuccessful = database . updateQuestion ( updatedQuestion ) ;
44
49
45
50
updateLocalDatabase ( ) ;
46
51
updateStates ( ) ;
52
+
53
+ console . log ( "Is Update Successful: " + isUpdateSuccessful ) ;
54
+
55
+ return isUpdateSuccessful ;
47
56
}
48
57
49
58
const updateLocalDatabase = ( ) => {
@@ -54,7 +63,7 @@ export const Questions = () => {
54
63
const updateStates = ( ) => {
55
64
// Update States
56
65
setQs ( Array . from ( database . database ) ) ;
57
- setQId ( Array . from ( database . database ) . length == 0 ? 0 : Array . from ( database . database ) . sort ( ( a , b ) => a [ 0 ] < b [ 0 ] ) . slice ( - 1 ) [ 0 ] [ 0 ] ) ;
66
+ setQId ( Array . from ( database . database ) . length === 0 ? 0 : Array . from ( database . database ) . sort ( ( a , b ) => a [ 0 ] < b [ 0 ] ) . slice ( - 1 ) [ 0 ] [ 0 ] ) ;
58
67
}
59
68
60
69
// To load data on mount
0 commit comments