Add a special page with progress bar for email sending

Also a new "Wheee!" page when the email-sending is done 😉
This commit is contained in:
Badri Sunderarajan 2021-05-29 00:11:07 +05:30
parent 9b630ae021
commit b1f69e16f6
5 changed files with 328 additions and 15 deletions

BIN
public/assets/cookies.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View file

@ -38,6 +38,8 @@ app.ws('/hit-send', (ws, request) => {
console.log(`From: ${message.from}\nTo:${message.to}\n\n${message.text}`)
console.log(`\n--------------------------- END EMAIL ---------------------------`)
// TODO: actually send the email
setTimeout(() => {
ws.send(JSON.stringify({
success: true,

View file

@ -196,8 +196,21 @@
step -= 1
}
function stepOne() {
step = 1
}
function stepTwo() {
step = 2
}
// This is to display which email is sending next
let nowSending
// And this is for the progress bar, mainly
let emailsSoFar = 0
let emailsToSend = 0
/**
* Hit Send
*
@ -229,6 +242,9 @@
})
}
// keep track of how many we had to start witth
emailsToSend = emails.length
emailsSoFar = 0
// okay, now let's open a socket to the server!
let socketProtocol = (window.location.protocol === 'https:' ? 'wss:' : 'ws:')
@ -236,7 +252,7 @@
let socket = new WebSocket(socketUrl)
socket.onopen = function() {
nowSending = emails.pop()
nowSending = emails.shift()
socket.send(JSON.stringify(nowSending))
}
@ -252,13 +268,16 @@
console.log(`${message.to}'s email sent successfully!`)
// send the next one
nowSending = emails.pop()
nowSending = emails.shift()
if (!!nowSending) {
socket.send(JSON.stringify(nowSending))
console.log(`Sending: ${nowSending.to}`)
// update the counter for the progress bar
emailsSoFar += 1
} else {
socket.close()
step = 2
step = 5
}
} else {
console.error('Something went wrong :(')
@ -353,21 +372,30 @@
{/if}
{#if step == 4}
<div class="instructions">
{#if !!nowSending }
<div class="cookie-preview">
<div class="preview-header">
<p>From: {nowSending.from || '[NOBODY!!!]'}</p>
<p>To: {nowSending.to || '[NOBODY!!!]'}</p>
<hr />
{@html nowSending.html}
</div>
<img src="/assets/email-baking.png" class="main-pic" alt="Email Oven with cookies inside"/>
<h1><span class={emailsSoFar % 2 == 0 ? 'highlight' : ''}>Chip</span> <span class={emailsSoFar % 2 == 0 ? '' : 'highlight'}>Choc</span></h1>
<h2>Your cookies are being cut...</h2>
<progress value={emailsSoFar} max={emailsToSend}>{emailsToSend ? emailsSoFar/emailsToSend*100 : 0} %</progress>
{#if !!nowSending }
<div class="cookie-preview">
<div class="preview-header">
<p>From: {nowSending.from || '[NOBODY!!!]'}</p>
<p>To: {nowSending.to || '[NOBODY!!!]'}</p>
<hr />
{@html nowSending.html}
</div>
{/if}
<h1>Chip <span class="highlight">Choc</span></h1>
<h2>Your cookies are being cut...</h2>
</div>
{/if}
{/if}
{#if step == 5}
<img src="/assets/cookies.png" class="main-pic" alt="A Pile of Cookies"/>
<h1>Wheee<span class="highlight">!</span></h1>
<h2>All emails sent successfully.</h2>
<button on:click={stepTwo}>Back to Draft</button>
<button on:click={stepOne}>Start Over</button>
{/if}
</main>
@ -431,4 +459,16 @@
padding: 1em;
border: 1px solid black;
}
progress {
width: 100%;
max-width: 640px;
margin: 1em;
color: #800020;
}
progress::-moz-progress-bar,
progress::-webkit-progress-value {
background-color: #800020;
}
</style>

271
src/pics/email-baking.svg Normal file
View file

@ -0,0 +1,271 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
id="Capa_1"
enable-background="new 0 0 512 512"
height="512"
viewBox="0 0 512 512"
width="512"
version="1.1"
sodipodi:docname="email-baking.svg"
inkscape:version="1.0.2 (e86c870879, 2021-01-15, custom)">
<metadata
id="metadata51">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs49" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1280"
inkscape:window-height="745"
id="namedview47"
showgrid="false"
inkscape:zoom="0.7664927"
inkscape:cx="140.81788"
inkscape:cy="384.75287"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="Capa_1"
inkscape:document-rotation="0" />
<g
fill="#447d99"
id="g6">
<path
d="m 94.25,436 h -30 c -11.046,0 -20,-8.954 -20,-20 v -10 h 70 v 10 c 0,11.046 -8.954,20 -20,20 z"
id="path2" />
<path
d="m 447.75,436 h -30 c -11.046,0 -20,-8.954 -20,-20 v -10 h 70 v 10 c 0,11.046 -8.954,20 -20,20 z"
id="path4" />
</g>
<path
d="m 489.5,406 h -467 c -8.284,0 -15,-6.716 -15,-15 V 91 c 0,-8.284 6.716,-15 15,-15 h 467 c 8.284,0 15,6.716 15,15 v 300 c 0,8.285 -6.716,15 -15,15 z"
fill="#548eb5"
id="path8"
sodipodi:nodetypes="sssssssss" />
<path
d="m 92.5,406 h -70 c -8.28,0 -15,-6.72 -15,-15 V 91 c 0,-8.28 6.72,-15 15,-15 h 70 c -8.28,0 -15,6.72 -15,15 v 300 c 0,8.28 6.72,15 15,15 z"
fill="#447d99"
id="path10"
sodipodi:nodetypes="csssscssc" />
<path
d="M 320.75205,123.18238 335.5,134.5 V 241 339.5 L 320.23573,358.45784 307.5,366 H 69.5 L 53.409407,359.11941 41.5,345 39.5,144.5 54.799733,123.527 69.5,116 h 238 z"
fill="#c9ebfa"
id="path12"
sodipodi:nodetypes="cccccccccccccc" />
<path
d="M 38.799733,145.527 77.5,116 V 366 L 39.409407,335.11941 Z"
fill="#a0ddf3"
id="path14"
sodipodi:nodetypes="ccccc" />
<path
d="m 47.5,319.84 h 280 l -6.78805,40.61094 -261.71637,-2.90716 z"
fill="#3dc6ef"
id="path16"
sodipodi:nodetypes="ccccc" />
<path
d="m 39.5,319.84 h 38 V 366 L 45.409407,349.11941 Z"
fill="#08a9f1"
id="path18"
sodipodi:nodetypes="ccccc" />
<path
d="m 411,116 h 50 v 90 h -50 z"
fill="#01d0fb"
id="path20"
sodipodi:nodetypes="ccccc" />
<circle
cx="436"
cy="266"
fill="#c9ebfa"
r="25"
id="circle22" />
<g
id="g42">
<path
d="M 489.5,68.5 H 122.34 c -4.143,0 -7.5,3.357 -7.5,7.5 0,4.143 3.357,7.5 7.5,7.5 H 360 v 50.6 c 0,4.143 3.357,7.5 7.5,7.5 4.143,0 7.5,-3.357 7.5,-7.5 V 83.5 h 114.5 c 4.136,0 7.5,3.364 7.5,7.5 v 300 c 0,4.136 -3.364,7.5 -7.5,7.5 H 375 V 166.79 c 0,-4.143 -3.357,-7.5 -7.5,-7.5 -4.143,0 -7.5,3.357 -7.5,7.5 V 398.5 H 22.5 C 18.364,398.5 15,395.136 15,391 V 91 c 0,-4.136 3.364,-7.5 7.5,-7.5 h 67.16 c 4.143,0 7.5,-3.357 7.5,-7.5 0,-4.143 -3.357,-7.5 -7.5,-7.5 H 22.5 C 10.094,68.5 0,78.594 0,91 v 300 c 0,12.406 10.094,22.5 22.5,22.5 h 14.25 v 2.5 c 0,15.163 12.337,27.5 27.5,27.5 h 30 c 15.163,0 27.5,-12.337 27.5,-27.5 v -2.5 h 268.5 v 2.5 c 0,15.163 12.337,27.5 27.5,27.5 h 30 c 15.163,0 27.5,-12.337 27.5,-27.5 v -2.5 h 14.25 c 12.406,0 22.5,-10.094 22.5,-22.5 V 91 C 512,78.594 501.906,68.5 489.5,68.5 Z M 106.75,416 c 0,6.893 -5.607,12.5 -12.5,12.5 h -30 c -6.893,0 -12.5,-5.607 -12.5,-12.5 v -2.5 h 55 z m 353.5,0 c 0,6.893 -5.607,12.5 -12.5,12.5 h -30 c -6.893,0 -12.5,-5.607 -12.5,-12.5 v -2.5 h 55 z"
id="path26" />
<path
d="m 461,213.5 c 4.143,0 7.5,-3.357 7.5,-7.5 v -90 c 0,-4.143 -3.357,-7.5 -7.5,-7.5 h -50 c -4.143,0 -7.5,3.357 -7.5,7.5 v 90 c 0,4.143 3.357,7.5 7.5,7.5 z m -42.5,-90 h 35 v 75 h -35 z"
id="path30" />
<path
d="m 436,298.5 c 17.921,0 32.5,-14.579 32.5,-32.5 0,-17.921 -14.579,-32.5 -32.5,-32.5 -17.921,0 -32.5,14.579 -32.5,32.5 0,17.921 14.579,32.5 32.5,32.5 z m 0,-50 c 9.649,0 17.5,7.851 17.5,17.5 0,9.649 -7.851,17.5 -17.5,17.5 -9.649,0 -17.5,-7.851 -17.5,-17.5 0,-9.649 7.851,-17.5 17.5,-17.5 z"
id="path32" />
<path
d="m 411,337.34 h 50 c 4.143,0 7.5,-3.357 7.5,-7.5 0,-4.143 -3.357,-7.5 -7.5,-7.5 h -50 c -4.143,0 -7.5,3.357 -7.5,7.5 0,4.143 3.357,7.5 7.5,7.5 z"
id="path34" />
<path
d="m 411,373.5 h 50 c 4.143,0 7.5,-3.357 7.5,-7.5 0,-4.143 -3.357,-7.5 -7.5,-7.5 h -50 c -4.143,0 -7.5,3.357 -7.5,7.5 0,4.143 3.357,7.5 7.5,7.5 z"
id="path36" />
</g>
<g
id="g1272"
transform="matrix(0.3589639,0,0,0.3589639,82.48301,165.85735)">
<path
d="M 352,74.667 384,64 h 24 l 16,32 h -72 z"
fill="#91591c"
id="path1157" />
<path
d="m 288,96 h 136 a 64,64 0 0 1 64,64 v 24 H 224 v -24 a 64,64 0 0 1 64,-64 z"
fill="#e6a565"
id="path1159" />
<path
d="m 288,96 32,-32 h 32 l 16,32 z"
fill="#b1712c"
id="path1161" />
<path
d="m 224,360 h 200 a 64,64 0 0 1 64,64 v 24 H 224 Z"
fill="#c7894c"
id="path1163" />
<path
d="m 224,272 h 200 a 64,64 0 0 1 64,64 v 24 H 224 Z"
fill="#e6a565"
id="path1165" />
<path
d="m 288,184 h 136 a 64,64 0 0 1 64,64 v 24 H 224 v -24 a 64,64 0 0 1 64,-64 z"
fill="#c7894c"
id="path1167" />
<circle
cx="152"
cy="320"
fill="#f5b97d"
r="128"
id="circle1169" />
<path
d="m 72,368 24,24 24,-16 8,-24 -32,-8 z"
fill="#a36522"
id="path1171" />
<path
d="m 104,288 16,16 24,-16 v -24 h -24 z"
fill="#b1712c"
id="path1173" />
<path
d="m 160,368 -8,24 24,24 24,-16 -8,-24 z"
fill="#b1712c"
id="path1175" />
<path
d="m 168,240 8,24 24,8 8,-24 -8,-16 z"
fill="#a36522"
id="path1177" />
<path
d="m 216,344 16,-8 h 16 v 24 h -24 z"
fill="#91591c"
id="path1179" />
<path
d="m 129.94043,344.23877 -32,-8 a 8.00279,8.00279 0 0 0 -7.59717,2.10449 l -24,24 a 7.99915,7.99915 0 0 0 0,11.31348 l 24,24 a 7.99922,7.99922 0 0 0 10.09424,0.99951 l 24,-16 a 7.99892,7.99892 0 0 0 3.15186,-4.12646 l 8,-24 a 8.00035,8.00035 0 0 0 -5.64893,-10.291 z M 113.27832,370.86621 97.01953,381.70557 83.31348,368 98.4541,352.85986 l 19.22461,4.80616 z"
id="path1181" />
<path
d="m 114.34326,309.65674 a 7.99922,7.99922 0 0 0 10.09424,0.99951 l 24,-16 A 7.99943,7.99943 0 0 0 152,288 v -24 a 7.99977,7.99977 0 0 0 -8,-8 h -24 a 7.99943,7.99943 0 0 0 -6.65625,3.5625 l -16,24 a 7.99946,7.99946 0 0 0 0.99951,10.09424 z M 124.28125,272 H 136 v 11.71875 l -14.98047,9.98682 -6.7251,-6.7251 z"
id="path1183" />
<path
d="m 199.58936,373.47021 a 8.00044,8.00044 0 0 0 -5.64893,-5.23144 l -32,-8 a 8.00073,8.00073 0 0 0 -9.52979,5.23144 l -8,24 a 7.99941,7.99941 0 0 0 1.93262,8.18653 l 24,24 a 7.99922,7.99922 0 0 0 10.09424,0.99951 l 24,-16 a 7.999,7.999 0 0 0 3.15186,-9.186 z m -22.56983,32.23536 -15.8667,-15.86621 4.09375,-12.28125 20.55274,5.13769 4.67871,14.03711 z"
id="path1185" />
<path
d="m 63.351,300 h 25.298 v 16 H 63.351 Z"
transform="matrix(0.949,-0.316,0.316,0.949,-93.498,39.839)"
id="path1187" />
<path
d="m 160,308.686 h 16 v 22.627 h -16 z"
transform="matrix(0.707,-0.707,0.707,0.707,-177.068,212.52)"
id="path1189" />
<path
d="m 429.04224,88.19629 -13.887,-27.77393 A 7.99924,7.99924 0 0 0 408,56 h -24 a 7.99908,7.99908 0 0 0 -2.52979,0.41064 l -20.84643,6.94874 -1.46851,-2.937 A 7.99924,7.99924 0 0 0 352,56 h -32 a 7.99877,7.99877 0 0 0 -5.65674,2.34326 L 284.60034,88.08618 A 72.085,72.085 0 0 0 216,160 v 24 a 7.99977,7.99977 0 0 0 8,8 h 18.76831 A 72.00943,72.00943 0 0 0 228.4281,207.56494 135.22391,135.22391 0 0 0 152,184 c -74.99072,0 -136,61.00928 -136,136 0,74.99072 61.00928,136 136,136 a 135.15724,135.15724 0 0 0 64,-16.03052 V 448 a 7.99977,7.99977 0 0 0 8,8 h 264 a 7.99977,7.99977 0 0 0 8,-8 V 424 A 71.88434,71.88434 0 0 0 469.18506,368 H 488 a 7.99977,7.99977 0 0 0 8,-8 V 336 A 71.88434,71.88434 0 0 0 469.18506,280 H 488 a 7.99977,7.99977 0 0 0 8,-8 V 248 A 71.88434,71.88434 0 0 0 469.18506,192 H 488 a 7.99977,7.99977 0 0 0 8,-8 V 160 A 72.07975,72.07975 0 0 0 429.04224,88.19629 Z M 385.29834,72 h 17.75732 l 8.00013,16 h -38.1117 l -5.09228,-10.18457 z m -61.98486,0 h 23.74218 l 8.00013,16 H 307.31348 Z M 32,320 A 120,120 0 1 1 152,440 120.13623,120.13623 0 0 1 32,320 Z m 448,104 v 16 H 232 v -10.0907 a 136.701,136.701 0 0 0 46.957,-61.15576 C 281.93628,368.27051 424,368 424,368 a 56.06353,56.06353 0 0 1 56,56 z m 0,-88 v 16 H 284.1875 a 136.1716,136.1716 0 0 0 -2.09424,-71.66724 C 284.05115,280.12756 424,280 424,280 a 56.06353,56.06353 0 0 1 56,56 z m 0,-88 v 16 H 275.929 A 136.731,136.731 0 0 0 241.12382,217.356 56.0767,56.0767 0 0 1 288,192 h 136 a 56.06353,56.06353 0 0 1 56,56 z m 0,-72 H 232 v -16 a 56.06353,56.06353 0 0 1 56,-56 h 136 a 56.06353,56.06353 0 0 1 56,56 z"
id="path1191" />
<path
d="m 168.41064,266.52979 a 8.001,8.001 0 0 0 5.05957,5.05957 l 24,8 a 7.99212,7.99212 0 0 0 10.11915,-5.05957 l 8,-24 a 7.99839,7.99839 0 0 0 -0.43409,-6.10743 l -8,-16 a 8.00059,8.00059 0 0 0 -9.0957,-4.18359 l -32,8 a 8.00035,8.00035 0 0 0 -5.64893,10.291 z m 27.30372,-25.21241 3.64843,7.29639 -4.42236,13.26709 -12.61572,-4.20557 -4.00342,-12.00929 z"
id="path1193" />
<path
d="m 200,300.686 h 16 v 22.627 h -16 z"
transform="matrix(0.707,-0.707,0.707,0.707,-159.696,238.461)"
id="path1195" />
<path
d="m 116.686,216 h 22.627 v 16 h -22.627 z"
transform="matrix(0.707,-0.707,0.707,0.707,-120.902,156.118)"
id="path1197" />
<path
d="m 256,360 v -24 a 7.99977,7.99977 0 0 0 -8,-8 h -16 a 7.99583,7.99583 0 0 0 -3.57764,0.84473 l -16,8 a 7.99926,7.99926 0 0 0 -3.57763,10.73291 l 8,16 A 7.99924,7.99924 0 0 0 224,368 h 24 a 7.99977,7.99977 0 0 0 8,-8 z m -16,-8 H 228.94434 L 226.73291,347.57764 233.88867,344 H 240 Z"
id="path1199" />
<path
d="m 263.056,140 h 17.889 v 16 h -17.889 z"
transform="matrix(0.894,-0.447,0.447,0.894,-37.472,137.267)"
id="path1201" />
<path
d="m 316,121.578 h 16 v 28.844 h -16 z"
transform="matrix(0.555,-0.832,0.832,0.555,31.118,330.145)"
id="path1203" />
<path
d="m 383.056,140 h 17.889 v 16 h -17.889 z"
transform="matrix(0.894,-0.447,0.447,0.894,-24.803,190.933)"
id="path1205" />
<path
d="m 428,121.578 h 16 v 28.844 h -16 z"
transform="matrix(0.555,-0.832,0.832,0.555,80.992,423.335)"
id="path1207" />
<path
d="m 316,209.578 h 16 v 28.844 h -16 z"
transform="matrix(0.555,-0.832,0.832,0.555,-42.102,369.331)"
id="path1209" />
<path
d="m 383.056,228 h 17.889 v 16 h -17.889 z"
transform="matrix(0.894,-0.447,0.447,0.894,-64.158,200.223)"
id="path1211" />
<path
d="m 428,209.578 h 16 v 28.844 h -16 z"
transform="matrix(0.555,-0.832,0.832,0.555,7.771,462.521)"
id="path1213" />
<path
d="m 316,297.578 h 16 v 28.844 h -16 z"
transform="matrix(0.555,-0.832,0.832,0.555,-115.323,408.518)"
id="path1215" />
<path
d="m 383.056,316 h 17.889 v 16 h -17.889 z"
transform="matrix(0.894,-0.447,0.447,0.894,-103.513,209.513)"
id="path1217" />
<path
d="m 428,297.578 h 16 v 28.844 h -16 z"
transform="matrix(0.555,-0.832,0.832,0.555,-65.449,501.707)"
id="path1219" />
<path
d="m 263.056,404 h 17.889 v 16 h -17.889 z"
transform="matrix(0.894,-0.447,0.447,0.894,-155.536,165.138)"
id="path1221" />
<path
d="m 316,385.578 h 16 v 28.844 h -16 z"
transform="matrix(0.555,-0.832,0.832,0.555,-188.543,447.704)"
id="path1223" />
<path
d="m 383.056,404 h 17.889 v 16 h -17.889 z"
transform="matrix(0.894,-0.447,0.447,0.894,-142.867,218.804)"
id="path1225" />
<path
d="m 428,385.578 h 16 v 28.844 h -16 z"
transform="matrix(0.555,-0.832,0.832,0.555,-138.669,540.894)"
id="path1227" />
</g>
<path
d="M 301.13526,113.84447 H 73.061449 c -19.24896,0 -34.90926,15.6603 -34.90926,34.90926 v 28.79723 l 128.111741,95.29122 c 6.23072,4.6342 13.53257,6.95159 20.83442,6.95159 7.30186,0 14.60371,-2.31681 20.83443,-6.95159 l 128.11174,-95.29122 v -28.79723 c 0,-19.24896 -15.6603,-34.90926 -34.90926,-34.90926 z m 11.63642,52.01247 -118.72813,88.31111 c -4.1542,3.09005 -9.73619,3.09005 -13.88981,0 L 61.425029,165.85694 v -17.10321 c 0,-6.41632 5.2201,-11.63642 11.63642,-11.63642 H 301.13526 c 6.41632,0 11.63642,5.2201 11.63642,11.63642 z m 0,58.00929 23.27284,-17.31033 v 126.41683 c 0,19.24897 -15.6603,34.90926 -34.90926,34.90926 H 73.061449 c -19.24896,0 -34.90926,-15.66029 -34.90926,-34.90926 V 206.5559 l 23.27284,17.31033 v 109.1065 c 0,6.41632 5.2201,11.63642 11.63642,11.63642 H 301.13526 c 6.41632,0 11.63642,-5.2201 11.63642,-11.63642 z"
id="path1330"
style="stroke-width:0.582;stroke-miterlimit:4;stroke-dasharray:none"
sodipodi:nodetypes="sssccsccssccccsssscccssssccssssc" />
</svg>

After

Width:  |  Height:  |  Size: 14 KiB