Skip to content

Commit

Permalink
Replaced lastScannedEmail session logic to set more directly, rather …
Browse files Browse the repository at this point in the history
…than by incremental ID queries
  • Loading branch information
maxxcrawford committed Apr 1, 2020
1 parent d32b6aa commit d45ce46
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
11 changes: 7 additions & 4 deletions public/js/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function doOauth(el, {emailWatch = false} = {}) {
// Preserve entire control function
if (!emailWatch) {
if (sessionStorage && sessionStorage.length > 0) {
const lastScannedEmail = sessionStorage.getItem(`scanned_${sessionStorage.length}`);

const lastScannedEmail = sessionStorage.getItem("lastScannedEmail");
if (lastScannedEmail) {
url.searchParams.append("email", lastScannedEmail);
}
Expand Down Expand Up @@ -93,7 +94,7 @@ function doOauth(el, {emailWatch = false} = {}) {

if (sessionStorage && sessionStorage.length > 0) {

const lastScannedEmail = sessionStorage.getItem(`scanned_${sessionStorage.length}`);
const lastScannedEmail = sessionStorage.getItem("lastScannedEmail");

if (email && lastScannedEmail) {
switch (email) {
Expand All @@ -104,7 +105,8 @@ function doOauth(el, {emailWatch = false} = {}) {
case !lastScannedEmail:
// The last saved email address and the current entry DIFFER, so create
// a new entry, launch a new FxA login session with new email prefilled.
sessionStorage.setItem(`scanned_${(sessionStorage.length + 1)}`, email);
sessionStorage.removeItem("lastScannedEmail");
sessionStorage.setItem("lastScannedEmail", email);
scannedEmailId.value = sessionStorage.length;
break;
}
Expand All @@ -116,7 +118,8 @@ function doOauth(el, {emailWatch = false} = {}) {
}
} else if (email && sessionStorage) {
// Applies to first time user in experiment has no previous FxA ties.
sessionStorage.setItem(`scanned_${(sessionStorage.length + 1)}`, email);
sessionStorage.removeItem("lastScannedEmail");
sessionStorage.setItem("lastScannedEmail", email);
scannedEmailId.value = sessionStorage.length;
}

Expand Down
10 changes: 8 additions & 2 deletions public/js/scan-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ async function hashEmailAndSend(emailFormSubmitEvent) {
// set unhashed email in client's sessionStorage and send key to server
// so we can pluck these out later in scan-results and not lose them on back clicks
if (sessionStorage) {
sessionStorage.setItem(`scanned_${(sessionStorage.length + 1)}`, userEmail);
emailForm.querySelector("input[name=scannedEmailId]").value = sessionStorage.length;

const lastScannedEmail = sessionStorage.getItem("lastScannedEmail");

if (!lastScannedEmail || lastScannedEmail !== userEmail) {
sessionStorage.removeItem("lastScannedEmail");
sessionStorage.setItem("lastScannedEmail", userEmail);
emailForm.querySelector("input[name=scannedEmailId]").value = sessionStorage.length;
}
}

// clear input, send ping, and submit
Expand Down
3 changes: 1 addition & 2 deletions public/js/scan-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
(() => {
if (document.getElementById("scannedEmail")) {
const scannedEmail = document.getElementById("scannedEmail");
const emailId = scannedEmail.dataset.scannedEmailId;
scannedEmail.textContent = sessionStorage.getItem(`scanned_${emailId}`);
scannedEmail.textContent = sessionStorage.getItem("lastScannedEmail");
}
})();

0 comments on commit d45ce46

Please sign in to comment.