Created
November 18, 2017 20:29
-
-
Save drFabio/b554feb8424fd2c287b0cfa08803d51c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="questionsContainer"> | |
<label for="question">Qual sua pergunta, <span id="userName"></span>?</label> | |
<input id="question" onfocus="clearMessage()" onKeyUp="checkEnter(event)"></input> | |
<p id="feedBack"></p> | |
<button id="sendButton" onClick="sendMessage()">Enviar</button> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkEnter (event) { | |
if (event.key === "Enter") { | |
sendMessage() | |
} | |
} | |
function clearMessage () { | |
feedBack.innerHTML = '' | |
feedBack.className = '' | |
} | |
function sendMessage () { | |
idleButton() | |
newMessageRef = databaseRef.push() | |
var displayName = userAuthData.user.displayName | |
var email = userAuthData.user.email | |
newMessageRef.set({question, createdAt, displayName, email}, (err) => { | |
sending = false | |
if (!err) { | |
setSuccessFeedback('Pergunta enviada!') | |
} else { | |
setError('Algo deu errado, tente novamente mais tarde ;)') | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment