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 score screen errors when linked from profile #14

Merged
merged 1 commit into from
Oct 12, 2018
Merged
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
36 changes: 18 additions & 18 deletions src/js/controllers/ctrl-scores.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ app.controller('scorePageController', function(Please, $scope, $q, $timeout, wid
}

default:
console.warn('Invalid postMessage source or no source provided')
console.warn('Invalid postMessage source or no source provided')
return false
}
} else {
Expand Down Expand Up @@ -181,8 +181,7 @@ app.controller('scorePageController', function(Please, $scope, $q, $timeout, wid
}

const _getScoreDetails = () => {
const deferred = $q.defer()
scoresLoadPromise = deferred
scoresLoadPromise = $q.defer()
if (isPreview) {
currentAttempt = 1
scoreSrv.getWidgetInstancePlayScores(null, widgetInstance.id, _displayDetails)
Expand All @@ -192,21 +191,22 @@ app.controller('scorePageController', function(Please, $scope, $q, $timeout, wid
// get the current attempt from the url
const hash = getAttemptNumberFromHash()
if (currentAttempt === hash) {
return
Copy link
Member Author

Choose a reason for hiding this comment

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

this would prevent the promise from resolving, causing _getScoreDetails()->then() to not exist

}
currentAttempt = hash
play_id = $scope.attempts[$scope.attempts.length - currentAttempt]['id']

// display existing data or get more from the server
if (details[$scope.attempts.length - currentAttempt] != null) {
_displayDetails(details[$scope.attempts.length - currentAttempt])
scoresLoadPromise.resolve()
} else {
scoreSrv.getWidgetInstancePlayScores(play_id, null, _displayDetails)
currentAttempt = hash
play_id = $scope.attempts[$scope.attempts.length - currentAttempt]['id']

// display existing data or get more from the server
if (details[$scope.attempts.length - currentAttempt] != null) {
_displayDetails(details[$scope.attempts.length - currentAttempt])
} else {
scoreSrv.getWidgetInstancePlayScores(play_id, null, _displayDetails)
}
}
}

Please.$apply()
return deferred.promise
return scoresLoadPromise.promise
}

const _displayWidgetInstance = () => {
Expand Down Expand Up @@ -511,8 +511,8 @@ app.controller('scorePageController', function(Please, $scope, $q, $timeout, wid
} else {
qset = data
}
return scoresLoadPromise.resolve()

return scoresLoadPromise.resolve()
})
}
else {
Expand Down Expand Up @@ -563,9 +563,9 @@ app.controller('scorePageController', function(Please, $scope, $q, $timeout, wid
}

const getAttemptNumberFromHash = () => {
const hashStr = window.location.hash.split('-')[1]
Copy link
Member Author

Choose a reason for hiding this comment

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

this can match things it shouldn't

if (hashStr != null && !isNaN(hashStr)) {
return hashStr
const match = window.location.hash.match(/^#attempt-(\d+)/)
if(match && match[1] != null && !isNaN(match[1])){
return match[1]
}
return $scope.attempts.length
}
Expand Down