@@ -5,12 +5,12 @@ import moment from "moment";
55const moduleName = "Quiz" ;
66
77function parseDateResponse ( dateResponse ) {
8- const timeSplit = dateResponse . split ( ',' ) ;
8+ const timeSplit = dateResponse . split ( "," ) ;
99 let daysString = "0 days" ;
1010 let timeString = "0:0:0" ;
1111
1212 if ( timeSplit . length == 1 ) {
13- // returning only timeString
13+ // returning only timeString
1414 timeString = timeSplit [ 0 ] ;
1515 } else if ( timeSplit . length == 2 ) {
1616 // returning days and timeString
@@ -20,11 +20,15 @@ function parseDateResponse(dateResponse) {
2020 throw new Error ( "Unexpected error with time response" ) ;
2121 }
2222 const days = parseInt ( daysString ) ;
23- const time = timeString . split ( ':' ) ;
23+ const time = timeString . split ( ":" ) ;
2424 const hours = time [ 0 ] ;
2525 const minutes = time [ 1 ] ;
2626 const seconds = time [ 2 ] ;
27- return moment ( ) . add ( days , "days" ) . add ( hours , "hours" ) . add ( minutes , "minutes" ) . add ( seconds , "seconds" ) ;
27+ return moment ( )
28+ . add ( days , "days" )
29+ . add ( hours , "hours" )
30+ . add ( minutes , "minutes" )
31+ . add ( seconds , "seconds" ) ;
2832}
2933
3034function getDefaultState ( ) {
@@ -38,7 +42,9 @@ function getDefaultState() {
3842 maxRank : 0 ,
3943 isLastQuestion : false ,
4044 hints : [ "" , "" ] ,
41- wrongCount : ! ! localStorage . getItem ( "wrongCount" ) ? parseInt ( localStorage . getItem ( "wrongCount" ) ) : 0 ,
45+ wrongCount : localStorage . getItem ( "wrongCount" )
46+ ? parseInt ( localStorage . getItem ( "wrongCount" ) )
47+ : 0 ,
4248 quizHasStarted : false ,
4349 quizHasEnded : false ,
4450 awaitNextQuestion : false
@@ -64,15 +70,18 @@ const actions = {
6470 try {
6571 const rank = await quiz . getRank ( ) ;
6672 commit ( "maxRank" , rank . maxRank ) ;
67- commit ( "quizStartedMoment" , moment ( rank . startsOn + "+0000" , "MM/DD/YYYY HH:mm Z" ) ) ;
73+ commit (
74+ "quizStartedMoment" ,
75+ moment ( rank . startsOn + "+0000" , "MM/DD/YYYY HH:mm Z" )
76+ ) ;
6877 if ( rank . rank < 0 ) {
6978 commit ( "quizHasStarted" , false ) ;
7079 commit ( "awaitNextQuestion" , false ) ;
7180 commit ( "question" , "" ) ;
7281 commit ( "asset" , "" ) ;
7382 commit ( "rank" , 0 ) ;
7483 commit ( "hints" , [ "" , "" ] ) ;
75- commit ( "nextUnlockMoment" , parseDateResponse ( rank . timeUntilNextRank ) )
84+ commit ( "nextUnlockMoment" , parseDateResponse ( rank . timeUntilNextRank ) ) ;
7685 return ;
7786 }
7887 commit ( "quizHasStarted" , true ) ;
@@ -85,7 +94,7 @@ const actions = {
8594 throw new Error ( err ) ;
8695 }
8796
88- // get current question and see if question is even unlocked
97+ // get current question and see if question is even unlocked
8998 try {
9099 const response = await quiz . getQuestion ( ) ;
91100 commit ( "awaitNextQuestion" , false ) ;
@@ -102,15 +111,17 @@ const actions = {
102111 commit ( "asset" , "" ) ;
103112 commit ( "rank" , 0 ) ;
104113 commit ( "hints" , [ "" , "" ] ) ;
105- commit ( "nextUnlockMoment" , parseDateResponse ( err . data . timeUntilNextRank ) ) ;
114+ commit (
115+ "nextUnlockMoment" ,
116+ parseDateResponse ( err . data . timeUntilNextRank )
117+ ) ;
106118 } else if ( err . status === 401 ) {
107119 commit ( "question" , "" ) ;
108120 commit ( "asset" , "" ) ;
109121 commit ( "rank" , 0 ) ;
110122 commit ( "hints" , [ "" , "" ] ) ;
111123 } else {
112- console . error ( "An unexpected error occurred" ) ;
113- console . error ( err ) ;
124+ return Promise . reject ( err ) ;
114125 }
115126 }
116127 }
0 commit comments