@@ -12,40 +12,33 @@ import {
12
12
stopAudio ,
13
13
createAudio ,
14
14
createUserRecipe ,
15
- cacheData ,
16
- CACHE_NAME_URL ,
17
- CACHE_NAME_AUDIO ,
18
15
audioElement ,
19
- alert_message
16
+ alert_message ,
20
17
} from "./js_utilities/functions_and_variables.js" ;
21
18
22
19
import {
23
20
mainElement ,
24
21
backgroundImg ,
25
22
gptResponseElement ,
26
23
headline ,
27
- lactoseIntolerant ,
28
24
loadingContainer ,
29
25
allergies ,
30
26
darkLightButton ,
31
27
userWantAnotherRecipe ,
32
28
tryAgainBtn ,
33
29
recipeButtons ,
34
30
sendRecipeToUserInboxBtn ,
35
- loadingText ,
36
31
recording ,
37
32
userEmail ,
38
33
emailSection ,
39
34
sendToUserInboxBtn ,
40
35
dietaryRequirements ,
41
36
otherDietaryRequirements ,
42
37
userText ,
43
- pictureSection ,
44
38
video ,
45
39
canvas ,
46
40
takePicture ,
47
41
context ,
48
- constraint ,
49
42
chatGptVisionText ,
50
43
videoBtnCanvas ,
51
44
pictureSectionHeadline ,
@@ -54,7 +47,7 @@ import {
54
47
pictureEmailSection ,
55
48
previousPage ,
56
49
sendToUserInbox ,
57
- emailUserRecipeSection ,
50
+ wrapper ,
58
51
} from "./js_utilities/query_selector.js" ;
59
52
60
53
let currentCameraIndex = 0 ;
@@ -143,7 +136,6 @@ sendToUserInbox.addEventListener("click", () => {
143
136
} ) ;
144
137
145
138
sendToUserInboxBtn . addEventListener ( "click" , ( ) => {
146
- // console.log(`userEmail ${userEmail.value}`);
147
139
console . log ( emailObject ) ;
148
140
fetch ( `/email?${ createQuery ( emailObject ) } ` )
149
141
. then ( ( response ) => response . json ( ) )
@@ -196,39 +188,14 @@ recipeButtons.forEach((button) => {
196
188
if ( eventData . image ) {
197
189
data . image = eventData . image ;
198
190
}
199
- // console.log("cacheObject", data);
191
+
200
192
console . log ( "data.audio" , eventData . audio ) ;
201
193
console . log ( "data.image" , eventData . image ) ;
202
194
203
195
if ( data . audio && data . image ) {
204
- console . log ( typeof data . image ) ;
205
- removeElements ( [ loadingContainer ] ) ;
206
- const imageUrl = data . image . data [ 0 ] . url ;
207
- console . log ( `imageURL ${ imageUrl } ` ) ;
208
- // await cacheData(imageUrl, CACHE_NAME_URL, "image");
209
- backgroundImg . src = imageUrl ;
210
- backgroundImg . onload = ( ) => {
211
- console . log ( "Image loaded successfully" ) ;
212
-
213
- } ;
214
- backgroundImg . onerror = ( ) => {
215
- console . error ( "Error loading image" ) ;
216
- } ;
217
-
218
- ///
219
- console . log ( data . audio ) ;
220
- const audio_data = createAudio ( data . audio ) ;
221
- console . log ( `line 261: ${ audio_data } ` ) ;
222
- await cacheData ( audio_data , CACHE_NAME_AUDIO , "audio" ) ;
223
- displayElementsFlex ( [ recording ] ) ;
224
- displayElements ( [ sendRecipeToUserInboxBtn , userWantAnotherRecipe ] ) ;
225
- const speechBtns = Array . from ( document . querySelectorAll ( ".fa-solid" ) ) ;
226
- const speedBtn = document . querySelector ( "#speed" ) ;
227
- audioElement . src = createAudio ( data . audio ) ;
228
- audioElement . stop = function ( ) {
229
- this . pause ( ) ;
230
- this . currentTime = 0 ;
231
- } ;
196
+ createImage ( data ) ;
197
+
198
+ const { speedBtn, speechBtns } = createTextToSpeech ( data ) ;
232
199
233
200
userWantAnotherRecipe . addEventListener ( "click" , ( ) => {
234
201
displayElements ( [ headline , allergies , ...recipeButtons , mainElement ] ) ;
@@ -257,27 +224,31 @@ recipeButtons.forEach((button) => {
257
224
} ) ;
258
225
} ) ;
259
226
}
260
-
261
- // if (data.image) {
262
- // console.log(typeof data.image);
263
- // removeElements([loadingContainer]);
264
- // const imageUrl = data.image.data[0].url;
265
- // console.log(`imageURL ${imageUrl}`);
266
- // // await cacheData(imageUrl, CACHE_NAME_URL, "image");
267
- // backgroundImg.src = imageUrl;
268
- // backgroundImg.onload = () => {
269
- // console.log("Image loaded successfully");
270
- // };
271
- // backgroundImg.onerror = () => {
272
- // console.error("Error loading image");
273
- // };
274
- // }
275
227
} ;
276
228
} ) ;
277
229
} ) ;
278
230
279
- // Picture section
231
+ function createImage ( param ) {
232
+ removeElements ( [ loadingContainer ] ) ;
233
+ const imageUrl = param . image . data [ 0 ] . url ;
234
+ backgroundImg . src = imageUrl ;
235
+ return backgroundImg ;
236
+ }
280
237
238
+ function createTextToSpeech ( param ) {
239
+ displayElementsFlex ( [ recording ] ) ;
240
+ displayElements ( [ sendRecipeToUserInboxBtn , userWantAnotherRecipe ] ) ;
241
+ const speechBtns = Array . from ( document . querySelectorAll ( ".fa-solid" ) ) ;
242
+ const speedBtn = document . querySelector ( "#speed" ) ;
243
+ audioElement . src = createAudio ( param . audio ) ;
244
+ audioElement . stop = function ( ) {
245
+ this . pause ( ) ;
246
+ this . currentTime = 0 ;
247
+ } ;
248
+ return { speedBtn, speechBtns } ;
249
+ }
250
+
251
+ // Picture section
281
252
async function getVideoDevices ( ) {
282
253
const devices = await navigator . mediaDevices . enumerateDevices ( ) ;
283
254
return devices . filter ( ( device ) => device . kind === "videoinput" ) ;
@@ -328,16 +299,6 @@ async function initializeCamera() {
328
299
329
300
initializeCamera ( ) ;
330
301
331
- // navigator.mediaDevices
332
- // .getUserMedia(constraint)
333
- // .then((stream) => {
334
- // video.srcObject = stream;
335
- // video.play();
336
- // })
337
- // .catch((error) => {
338
- // console.error("Error accessing camera:", error);
339
- // });
340
-
341
302
function capturePhoto ( ) {
342
303
context . drawImage ( video , 0 , 0 , 400 , 100 ) ;
343
304
}
@@ -375,8 +336,7 @@ takePicture.addEventListener("click", () => {
375
336
376
337
// Menu icon toggle
377
338
const menuIcon = document . querySelector ( ".menu-icon" ) ;
378
- const container = document . querySelector ( ".container" ) ;
379
339
380
340
menuIcon . addEventListener ( "click" , ( ) => {
381
- container . classList . toggle ( "change" ) ;
341
+ wrapper . classList . toggle ( "change" ) ;
382
342
} ) ;
0 commit comments