(import kiss_spaced_rep.StudyEngine) (implements StudyEngine) (prop &mut :String content "") (defNew [] [&mut :String image "" &mut :Continuation cc null &mut :String->Void resolve null &mut :Dynamic connection null] (let [app (Express.call) port 3000 staticDir (#if STATIC_DIR (#value "STATIC_DIR") (Sys.getCwd))] (print "Using $staticDir for static file directory") (app.use "/static" (Express.static_.call staticDir)) (app.get "/" ->[req :Dynamic res next] (res.send content)) (app.get "/continue" ->[req res next] { (whenLet [_cc cc] (set cc null) (_cc)) (res.redirect "/") }) (app.get "/submit" ->[:Dynamic req :Dynamic res next] { (whenLet [_resolve resolve] (set resolve null) (_resolve req.query.value)) (res.redirect "/") }) (app.get "/restart" ->[req :Dynamic res next] { (res.redirect "/") (connection.close) (kiss_spaced_rep.Main_.main) }) (#unless test (set connection (app.listen port ->(print "kiss-express listening at http://localhost:$port")))))) (method :Void clear [] (set content "")) (method :Void print [text] (+= content text)) (method :Void println [text] (+= content text "
")) (method :Void showImage [path] (+= content "
")) (method :Void delayForUserInput [cc &opt :String text] (set this.cc cc) (unless text (set text "Next")) (+= content "
${text}
")) (method :Void getUserInput [resolve] (set this.resolve resolve) (+= content "