@@ -18,6 +18,9 @@ const userEmail = document.querySelector("#user-email");
1818const sendEmailButton = document . querySelector ( ".send-email-btn" ) ;
1919const emailSection = document . querySelector ( ".email-section" ) ;
2020const paperPlane = document . querySelector ( ".fa-paper-plane" ) ;
21+ const sendToUserInboxBtn = document . querySelector ( ".send-to-user-inbox-btn" ) ;
22+ console . log ( sendToUserInboxBtn ) ;
23+
2124const dietaryRequirements = Array . from (
2225 document . querySelectorAll ( ".dietary-requirements" )
2326) ;
@@ -29,7 +32,8 @@ let textContent;
2932let imageUrl ;
3033let isLactoseIntolerant ;
3134let dishOriginCountry ;
32- let currentChar
35+ let currentChar ;
36+
3337const defaultRecipe = `
3438Apologies, but our AI Recipe-Making expert is unavailable. Please try again later. In the meantime, please find one of our favourite recipes below.
3539
@@ -170,7 +174,7 @@ darkLightButton.addEventListener("change", () => {
170174 } ) ;
171175} ) ;
172176
173- paperPlane . addEventListener ( "click" , ( ) => {
177+ sendToUserInboxBtn . addEventListener ( "click" , ( ) => {
174178 let emailOBject = {
175179 [ userEmail . name ] : userEmail . value ,
176180 } ;
@@ -264,9 +268,9 @@ recipeButtons.forEach((button) => {
264268 textContent = data . text . choices [ 0 ] . message . content ;
265269 gptResponseElement . innerHTML = `
266270 <div class="recording">
267- <i class="fa-solid fa-microphone"></i>
268- <i class="fa-solid fa-pause"></i>
269- <i class="fa-solid fa-stop"></i>
271+ <i class="fa-solid fa-microphone" name="microphone" ></i>
272+ <i class="fa-solid fa-pause" name="pause" ></i>
273+ <i class="fa-solid fa-stop" name="stop" ></i>
270274 <div class="speed-wrapper">
271275 <label for="speed">Speed</label>
272276 <input type="number" name="speed" id="speed" min="0.25" max="2" step="0.25" value="1">
@@ -282,11 +286,18 @@ recipeButtons.forEach((button) => {
282286
283287 const utterance = new SpeechSynthesisUtterance ( ) ;
284288
289+ const speechBtns = Array . from (
290+ document . querySelectorAll ( ".fa-solid" )
291+ ) ;
292+ const speedBtn = document . querySelector ( "#speed" ) ;
293+
294+ console . log ( speechBtns ) ;
295+
285296 function readRecipe ( recipe ) {
286- if ( speechSynthesis . paused && speechSynthesis . speaking ) {
297+ if ( speechSynthesis . paused && speechSynthesis . speaking ) {
287298 return speechSynthesis . resume ( ) ;
288299 }
289- if ( speechSynthesis . speaking ) return
300+ if ( speechSynthesis . speaking ) return ;
290301 utterance . text = recipe ;
291302 utterance . rate = speedBtn . value || 1 ;
292303 speechSynthesis . speak ( utterance ) ;
@@ -300,32 +311,18 @@ recipeButtons.forEach((button) => {
300311 speechSynthesis . cancel ( ) ;
301312 }
302313
303- const microphoneBtn = document . querySelector ( ".fa-microphone" ) ;
304- const pauseBtn = document . querySelector ( ".fa-pause" ) ;
305- const stopBtn = document . querySelector ( ".fa-stop" ) ;
306- const speedBtn = document . querySelector ( "#speed" ) ;
307-
308- console . log ( speedBtn ) ;
309-
310- // speedBtn.addEventListener("input", () => {
311- // stopREeading();
312- // readRecipe(utterance.text.substring(currentChar));
313-
314- // console.log("speed has been incremented")
315- // })
316-
317- // utterance.addEventListener("boundary", (e) => {
318- // currentChar = e.charIndex;
319- // })
320-
321- stopBtn . addEventListener ( "click" , stopREeading ) ;
322-
323- pauseBtn . addEventListener ( "click" , pauseReading ) ;
324-
325-
326-
327- microphoneBtn . addEventListener ( "click" , ( ) => {
328- readRecipe ( `${ textContent } ` ) ;
314+ speechBtns . forEach ( ( speechBtn ) => {
315+ speechBtn . addEventListener ( "click" , ( ) => {
316+ const btnName = speechBtn . getAttribute ( "name" ) ;
317+ if ( btnName === "microphone" ) {
318+ console . log ( btnName ) ;
319+ readRecipe ( `${ textContent } ` ) ;
320+ } else if ( btnName === "pause" ) {
321+ pauseReading ( ) ;
322+ } else if ( btnName === "stop" ) {
323+ stopREeading ( ) ;
324+ }
325+ } ) ;
329326 } ) ;
330327 } )
331328 . catch ( ( error ) => {
0 commit comments