Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #66 added user/progress mock endpoint #129

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions public/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,40 @@ const keyToId = {
// this tracks when we started asking for the current key command
let questionStartMS = 0;

$(document).ready(function() {
$(document).ready(function () {
//$("#retryButton").toggleClass("on");
//alert($('li[data-keycode="test"]').attr('id'));
fetch('scripts/shortcuts.json')
.then(response => response.json())
.then(data => {
allData=data
if(localStorage.getItem("questionNo")==null)
{
localStorage.setItem("questionNo", "1");
localStorage.setItem("totalCount", Object.keys(allData).length);
}
readText()
updateTimingDisplay()
fetch('scripts/shortcuts.json')
.then(response => response.json()).then(data => {
allData = data
return getUserProgress()
}).then(response => {
if (!response.ok) {
const message = `An error has occured: ${response.status}`;
console.error(message)
return 1
Comment on lines +49 to +52
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you missed the other PR comment but the return 1 won't work because the next step is expecting a userProgress object

}
return response.json()
})
.then(userProgress => {
if (localStorage.getItem("questionNo") == null) {
localStorage.setItem("questionNo", userProgress.currentQuestionNumber);
localStorage.setItem("totalCount", Object.keys(allData).length);
}
readText()
updateTimingDisplay()
});

$('.container').css('height', $(window).height());
$(window).on('resize', function () {
$('.container').css('height', $(window).height());
Comment on lines +65 to +67
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines were deleted in a merge, but git must not have detected it, so please remove from this PR.

});
});

function getUserProgress() {
return fetch('user/progress')
}

function nextQuestion() {
if(localStorage.getItem("questionNo")!=null){
if(parseInt(localStorage.getItem("questionNo"))<parseInt(localStorage.getItem("totalCount"))){
Expand Down
4 changes: 4 additions & 0 deletions routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ router.get('/cheatsheet', (req,res) => {
res.render('cheatsheet');
})

router.get('/user/progress', (req, res) => {
res.send({ "userId": null,"currentQuestionNumber": 1})
})

router.post('/user/answers/question/:questionNumber', (req, res) => {
if(req.body.id) {
return res.status(400).json({'message': 'ID should not be provided'});
Expand Down