Skip to content

Commit

Permalink
Merge pull request #22 from LearnTeachCode/issue8
Browse files Browse the repository at this point in the history
Close #8, add updateCurrentGistView condition.

  - Client-side code now checks if turnData.gist exists before updating
the Gist view UI, inside handleUpdateState() and handleTurnChange()
  • Loading branch information
LearningNerd authored Jun 28, 2017
2 parents 86522d2 + 518aea6 commit fd57f8c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions public/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function handleTurnChange (turnData) {
updateCurrentTurnView(turnData.current.name);
updateNextTurnView(turnData.next.name);
toggleMyTurnHighlight();
updateCurrentGistView(turnData.gist);
if (turnData.gist != null) updateCurrentGistView(turnData.gist);
}

// When receiving updateState event from server,
Expand Down Expand Up @@ -358,8 +358,8 @@ function handleUpdateState (turnData) {
updateTimeLeftView(turnData.millisRemaining);
updateCurrentTurnView(turnData.current.name);
updateNextTurnView(turnData.next.name);
toggleMyTurnHighlight();
updateCurrentGistView(turnData.gist);
toggleMyTurnHighlight();
if (turnData.gist != null) updateCurrentGistView(turnData.gist);
}


Expand All @@ -368,7 +368,6 @@ function handleNewGistLink (gistData) {
// Update local state
console.log("called handleNewGist at " + new Date().toString().substring(16,25), 'color: green; font-weight: bold;');
console.log(gistData);

// Update views
updateCurrentGistView(gistData);
}
Expand Down Expand Up @@ -519,7 +518,7 @@ function updateNextTurnView (playerName) {
}

// Append to a list of gist links for this game
function updateCurrentGistView (gistData) {
function updateCurrentGistView (gistData) {
currentGistView.innerHTML = '<strong>Latest code:</strong> <a href="' + gistData.url + '">' + gistData.url + '</a>';
}

Expand All @@ -544,10 +543,11 @@ function handleCreateNewGist() {

postWithGitHubToken('https://api.github.com/gists', gistObject).then(function(responseText){
//console.log(responseText);
console.log('handleCreateNewGist: response received at ' + new Date().toString().substring(16,25), 'color: red; font-weight: bold;');
console.dir(gistObject);
console.log('handleCreateNewGist: response received at ' + new Date().toString().substring(16,25), 'color: red; font-weight: bold;');

var gistObject = JSON.parse(responseText);

console.dir(gistObject);

// Save new gist ID and URL locally
currentGist = {id: gistObject.id, url: gistObject.html_url};
Expand Down Expand Up @@ -579,7 +579,7 @@ function editGist(gistId, codeEditorContent) {
postWithGitHubToken('https://api.github.com/gists/' + gistId, gistObject).then(function(responseText){
//console.log(responseText);
console.log('editGist: response received at ' + new Date().toString().substring(16,25), 'color: orange; font-weight: bold;');
console.dir(gistObject);
console.dir(JSON.parse(responseText));

}, handleError);

Expand All @@ -599,6 +599,7 @@ function forkAndEditGist(gistId, codeEditorContent) {
console.log('forkAndEditGist: response received at ' + new Date().toString().substring(16,25), 'color: red; font-weight: bold;');

var gistObject = JSON.parse(responseText);
console.dir(gistObject);

// Send new gist data to server
socket.emit('newGistLink', {id: gistObject.id, url: gistObject.html_url});
Expand Down

0 comments on commit fd57f8c

Please sign in to comment.