mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-07 22:23:45 +08:00
added email sending to the command line
email sending is no longer using a function, just simply pushes to the database
This commit is contained in:
parent
056525d244
commit
cd6c3ac114
8 changed files with 206 additions and 20 deletions
|
@ -1,5 +1,5 @@
|
|||
const functions = require('firebase-functions');
|
||||
|
||||
const cors = require('cors');
|
||||
const admin = require('firebase-admin');
|
||||
admin.initializeApp();
|
||||
|
||||
|
@ -12,19 +12,21 @@ admin.initializeApp();
|
|||
// });
|
||||
|
||||
|
||||
exports.sendEmailNotification = functions.https.onRequest(async (request, response) => {
|
||||
admin.firestore().collection('mail').add({
|
||||
to: "bartnikjack@gmail.com",
|
||||
message: {
|
||||
subject: request.query.subject,
|
||||
html: request.query.body,
|
||||
}
|
||||
}).then(() => {
|
||||
console.log('Email queued');
|
||||
return response.send('Email queued');
|
||||
}).catch((e) => {
|
||||
console.log('Error adding email to queue ' + e);
|
||||
return response.send('Error adding email to queue ' + e);
|
||||
exports.sendEmailNotification = functions.https.onRequest(async (req, res) => {
|
||||
return cors(req, res, () => {
|
||||
|
||||
admin.firestore().collection('mail').add({
|
||||
to: "bartnikjack@gmail.com",
|
||||
message: {
|
||||
subject: req.query.subject,
|
||||
html: req.query.body,
|
||||
}
|
||||
}).then(() => {
|
||||
console.log('Email queued');
|
||||
return res.send('Email queued');
|
||||
}).catch((e) => {
|
||||
console.log('Error adding email to queue ' + e);
|
||||
return res.send('Error adding email to queue ' + e);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -22,6 +22,10 @@
|
|||
<div class="suggestions">
|
||||
</div>
|
||||
</div>
|
||||
<div id="commandInput" class="hidden">
|
||||
<textarea type="text" class="input" placeholder="input"></textarea>
|
||||
<div class="shiftEnter">Shift + Enter to send</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="timerWrapper">
|
||||
<div id="timer"></div>
|
||||
|
|
|
@ -94,6 +94,34 @@ a:hover {
|
|||
padding: 5rem 0;
|
||||
}
|
||||
|
||||
#commandLineWrapper #commandInput {
|
||||
width: 50vw;
|
||||
background: var(--bg-color);
|
||||
border-radius: var(--roundness);
|
||||
}
|
||||
|
||||
#commandLineWrapper #commandInput textarea {
|
||||
background: var(--bg-color);
|
||||
padding: 1rem;
|
||||
color: var(--main-color);
|
||||
border: none;
|
||||
outline: none;
|
||||
font-size: 1rem;
|
||||
font-family: "Roboto Mono";
|
||||
width: 100%;
|
||||
border-radius: var(--roundness);
|
||||
resize: vertical;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
#commandLineWrapper #commandInput .shiftEnter {
|
||||
padding: 0.5rem 1rem;
|
||||
font-size: 0.75rem;
|
||||
line-height: 0.75rem;
|
||||
color: var(--sub-color);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#commandLineWrapper #commandLine {
|
||||
width: 50vw;
|
||||
background: var(--bg-color);
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -65,6 +65,31 @@ a:hover {
|
|||
justify-content: center;
|
||||
align-items: start;
|
||||
padding: 5rem 0;
|
||||
#commandInput{
|
||||
width: 50vw;
|
||||
background: var(--bg-color);
|
||||
border-radius: var(--roundness);
|
||||
textarea {
|
||||
background: var(--bg-color);
|
||||
padding: 1rem;
|
||||
color: var(--main-color);
|
||||
border: none;
|
||||
outline: none;
|
||||
font-size: 1rem;
|
||||
font-family: "Roboto Mono";
|
||||
width: 100%;
|
||||
border-radius: var(--roundness);
|
||||
resize: vertical;
|
||||
height: 200px;
|
||||
}
|
||||
.shiftEnter{
|
||||
padding: 0.5rem 1rem;
|
||||
font-size: 0.75rem;
|
||||
line-height: 0.75rem;
|
||||
color: var(--sub-color);
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
#commandLine {
|
||||
width: 50vw;
|
||||
background: var(--bg-color);
|
||||
|
|
|
@ -77,10 +77,49 @@ let commands = {
|
|||
currentCommands = commandsWordCount;
|
||||
showCommandLine();
|
||||
}
|
||||
},
|
||||
{
|
||||
id: "sendDevMessage",
|
||||
display: "Send a message ( bug report / feature request / feedback )...",
|
||||
subgroup: true,
|
||||
exec: () => {
|
||||
currentCommands = commandsSendDevMessage;
|
||||
showCommandLine();
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
let commandsSendDevMessage = {
|
||||
title: "Send a message...",
|
||||
list: [
|
||||
{
|
||||
id: "sendBugReport",
|
||||
display: "Bug report",
|
||||
input: true,
|
||||
exec: (txt) => {
|
||||
db_addEmailToQueue('bug', txt);
|
||||
}
|
||||
},
|
||||
{
|
||||
id: "sendFeatureRequest",
|
||||
display: "Feature request",
|
||||
input: true,
|
||||
exec: (txt) => {
|
||||
db_addEmailToQueue('feature', txt);
|
||||
}
|
||||
},
|
||||
{
|
||||
id: "sendFeedback",
|
||||
display: "Other feedback",
|
||||
input: true,
|
||||
exec: (txt) => {
|
||||
db_addEmailToQueue('feedback', txt);
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
let commandsWordCount = {
|
||||
title: "Change word count...",
|
||||
|
@ -242,19 +281,45 @@ $(document).ready(e => {
|
|||
})
|
||||
})
|
||||
|
||||
$("#commandInput textarea").keydown((e) => {
|
||||
if (e.keyCode == 13 && e.shiftKey) {
|
||||
//enter
|
||||
e.preventDefault();
|
||||
let command = $("#commandInput textarea").attr("command");
|
||||
let value = $("#commandInput textarea").val();
|
||||
$.each(currentCommands.list, (i, obj) => {
|
||||
if (obj.id == command) {
|
||||
obj.exec(value);
|
||||
subgroup = obj.subgroup;
|
||||
}
|
||||
});
|
||||
firebase.analytics().logEvent('usedCommandLine', {
|
||||
command: command
|
||||
});
|
||||
hideCommandLine();
|
||||
}
|
||||
return;
|
||||
});
|
||||
|
||||
$("#commandLine input").keydown((e) => {
|
||||
if (e.keyCode == 13) {
|
||||
//enter
|
||||
e.preventDefault();
|
||||
let command = $(".suggestions .entry.active").attr("command");
|
||||
let subgroup = false;
|
||||
let input = false;
|
||||
$.each(currentCommands.list, (i, obj) => {
|
||||
if (obj.id == command) {
|
||||
obj.exec();
|
||||
subgroup = obj.subgroup;
|
||||
if (obj.input) {
|
||||
input = true;
|
||||
showCommandInput(obj.id, obj.display);
|
||||
} else {
|
||||
obj.exec();
|
||||
subgroup = obj.subgroup;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!subgroup) {
|
||||
if (!subgroup && !input) {
|
||||
firebase.analytics().logEvent('usedCommandLine', {
|
||||
command: command
|
||||
});
|
||||
|
@ -290,13 +355,13 @@ $("#commandLine input").keydown((e) => {
|
|||
hoverId = $(entries[activenum]).attr('command');
|
||||
}
|
||||
}
|
||||
try{
|
||||
try {
|
||||
$.each(currentCommands.list, (index, obj) => {
|
||||
if (obj.id == hoverId) {
|
||||
obj.hover();
|
||||
}
|
||||
});
|
||||
}catch(e){}
|
||||
} catch (e) { }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -321,6 +386,8 @@ function hideCommandLine() {
|
|||
}
|
||||
|
||||
function showCommandLine() {
|
||||
$("#commandLine").removeClass('hidden');
|
||||
$("#commandInput").addClass('hidden');
|
||||
if ($("#commandLineWrapper").hasClass("hidden")) {
|
||||
$("#commandLineWrapper")
|
||||
.stop(true, true)
|
||||
|
@ -338,6 +405,17 @@ function showCommandLine() {
|
|||
$("#commandLine input").focus();
|
||||
}
|
||||
|
||||
function showCommandInput(command, placeholder) {
|
||||
$("#commandLineWrapper").removeClass('hidden');
|
||||
$("#commandLine").addClass('hidden');
|
||||
$("#commandInput").removeClass('hidden');
|
||||
$("#commandInput textarea").attr('placeholder', placeholder);
|
||||
$("#commandInput textarea").val('');
|
||||
$("#commandInput textarea").focus();
|
||||
$("#commandInput textarea").attr('command', '');
|
||||
$("#commandInput textarea").attr('command', command);
|
||||
}
|
||||
|
||||
function updateSuggestedCommands() {
|
||||
let inputVal = $("#commandLine input").val().toLowerCase().split(" ");
|
||||
if (inputVal[0] == "") {
|
||||
|
|
|
@ -57,3 +57,51 @@ async function db_getUserHighestWpm(mode, mode2) {
|
|||
return retval;
|
||||
|
||||
}
|
||||
|
||||
function db_addEmailToQueue(type, body) {
|
||||
|
||||
let from = 'Annonymous';
|
||||
let subject = '';
|
||||
if (type == 'bug') {
|
||||
subject = 'New Bug Report';
|
||||
} else if (type == 'feature') {
|
||||
subject = 'New Feature Request';
|
||||
} else if (type == 'feedback') {
|
||||
subject = 'New Feedback';
|
||||
} else {
|
||||
showNotification('Error: Unsupported type',3000);
|
||||
return;
|
||||
}
|
||||
|
||||
if (firebase.auth().currentUser != null) {
|
||||
from = firebase.auth().currentUser.email;
|
||||
}
|
||||
|
||||
// $.get("https://us-central1-monkey-type.cloudfunctions.net/sendEmailNotification",
|
||||
// {
|
||||
// subject: "New " + subject,
|
||||
// body: body
|
||||
// })
|
||||
// .done(data => {
|
||||
// if (data == 'Email queued') {
|
||||
// showNotification("Message sent. Thanks!", 3000);
|
||||
// } else {
|
||||
// showNotification("Unknown error", 3000);
|
||||
// }
|
||||
// }).fail(error => {
|
||||
// showNotification("Unexpected error", 3000);
|
||||
// });
|
||||
|
||||
db.collection('mail').add({
|
||||
to: "bartnikjack@gmail.com",
|
||||
message: {
|
||||
subject: subject,
|
||||
html: body + "<br><br>From: " + from,
|
||||
}
|
||||
}).then(() => {
|
||||
showNotification('Email sent',3000);
|
||||
}).catch((e) => {
|
||||
showNotification('Error while sending email: ' + e,5000);
|
||||
});
|
||||
|
||||
}
|
|
@ -708,6 +708,7 @@ function swapElements(el1, el2, totalDuration, callback = function(){ return; })
|
|||
|
||||
}
|
||||
|
||||
|
||||
function updateAccountLoginButton() {
|
||||
if (firebase.auth().currentUser != null) {
|
||||
swapElements($("#menu .button.login"), $("#menu .button.account"), 250);
|
||||
|
|
Loading…
Add table
Reference in a new issue