@@ -15,6 +15,8 @@ var session = require('../session');
1515var plugin = new Plugin ( 10 , 'leetcode' , '' ,
1616 'Plugin to talk with leetcode APIs.' ) ;
1717
18+ var spin ;
19+
1820// update options with user credentials
1921function signOpts ( opts , user ) {
2022 opts . headers . Cookie = 'LEETCODE_SESSION=' + user . sessionId +
@@ -49,7 +51,6 @@ function checkError(e, resp, expectedStatus) {
4951
5052plugin . getProblems = function ( cb ) {
5153 log . debug ( 'running leetcode.getProblems' ) ;
52-
5354 var problems = [ ] ;
5455 var doTask = function ( category , taskDone ) {
5556 plugin . getCategoryProblems ( category , function ( e , _problems ) {
@@ -63,7 +64,9 @@ plugin.getProblems = function(cb) {
6364 } ) ;
6465 } ;
6566
67+ spin = h . spin ( 'Downloading problems' ) ;
6668 queue . run ( config . sys . categories , doTask , function ( e ) {
69+ spin . stop ( ) ;
6770 return cb ( e , problems ) ;
6871 } ) ;
6972} ;
@@ -72,6 +75,7 @@ plugin.getCategoryProblems = function(category, cb) {
7275 log . debug ( 'running leetcode.getCategoryProblems: ' + category ) ;
7376 var opts = makeOpts ( config . sys . urls . problems . replace ( '$category' , category ) ) ;
7477
78+ spin . text = 'Downloading category ' + category ;
7579 request ( opts , function ( e , resp , body ) {
7680 e = checkError ( e , resp , 200 ) ;
7781 if ( e ) return cb ( e ) ;
@@ -140,7 +144,9 @@ plugin.getProblem = function(problem, cb) {
140144 operationName : 'getQuestionDetail'
141145 } ;
142146
147+ spin = h . spin ( 'Downloading ' + problem . slug ) ;
143148 request . post ( opts , function ( e , resp , body ) {
149+ spin . stop ( ) ;
144150 e = checkError ( e , resp , 200 ) ;
145151 if ( e ) return cb ( e ) ;
146152
@@ -175,7 +181,9 @@ function runCode(opts, problem, cb) {
175181 typed_code : h . getFileData ( problem . file )
176182 } ) ;
177183
184+ spin = h . spin ( 'Sending code to judge' ) ;
178185 request ( opts , function ( e , resp , body ) {
186+ spin . stop ( ) ;
179187 e = checkError ( e , resp , 200 ) ;
180188 if ( e ) return cb ( e ) ;
181189
@@ -207,7 +215,9 @@ function verifyResult(opts, jobs, results, cb) {
207215 opts . method = 'GET' ;
208216 opts . url = config . sys . urls . verify . replace ( '$id' , jobs [ 0 ] . id ) ;
209217
218+ spin = h . spin ( 'Waiting for judge result' ) ;
210219 request ( opts , function ( e , resp , body ) {
220+ spin . stop ( ) ;
211221 e = checkError ( e , resp , 200 ) ;
212222 if ( e ) return cb ( e ) ;
213223
@@ -366,7 +376,9 @@ plugin.getFavorites = function(cb) {
366376
367377plugin . signin = function ( user , cb ) {
368378 log . debug ( 'running leetcode.signin' ) ;
379+ spin = h . spin ( 'Signing in leetcode.com' ) ;
369380 request ( config . sys . urls . login , function ( e , resp , body ) {
381+ spin . stop ( ) ;
370382 e = checkError ( e , resp , 200 ) ;
371383 if ( e ) return cb ( e ) ;
372384
0 commit comments