@@ -22,46 +22,67 @@ textarea.addEventListener('keyup', (e) => {
2222 meetingText = e . target . value ;
2323} ) ;
2424
25+ async function getSummarizedText ( ) {
26+ const body = { email, text : meetingText , max_sentences : 2 } ;
27+ console . log ( body ) ;
28+
29+ const res = await fetch ( 'http://standnote.herokuapp.com/summarizer/' , {
30+ method : 'post' ,
31+ headers : {
32+ 'Content-Type' : 'application/json' ,
33+ } ,
34+ body : JSON . stringify ( body ) ,
35+ } ) ;
36+ const data = await res . json ( ) ;
37+ console . log ( data ) ;
38+
39+ return data ;
40+ }
41+
2542document
2643 . getElementById ( 'submit-meeting-details' )
27- . addEventListener ( 'submit' , ( e ) => {
28- e . preventDefault ( ) ;
29-
30- document . getElementById ( 'sendText' ) . disabled = true ;
31-
32- title = document . getElementById ( 'title' ) . value ;
33-
34- const body = {
35- email,
36- duration : meetingDuration ,
37- title,
38- content : meetingText ,
39- markdown : '' ,
40- score : window . confidenceScore ,
41- } ;
42-
43- console . log ( body ) ;
44-
45- fetch ( 'http://standnote.herokuapp.com/notes/' , {
46- method : 'post' ,
47- headers : {
48- 'Content-Type' : 'application/json' ,
49- } ,
50- body : JSON . stringify ( body ) ,
51- } )
52- . then ( ( res ) => {
53- if ( res . ok ) {
54- return res . json ( ) ;
55- } else {
56- throw new Error ( 'Something went wrong' ) ;
57- }
58- } )
59- . then ( ( ) => {
60- document . getElementsByClassName ( 'content' ) [ 0 ] . style . display = 'none' ;
61- document . getElementsByClassName ( 'message' ) [ 0 ] . style . display = 'block' ;
62- document . title = 'StandNote - Thanks for using StandNote' ;
63- } )
64- . catch ( ( err ) => {
65- document . getElementById ( 'sendText' ) . disabled = false ;
44+ . addEventListener ( 'submit' , async ( e ) => {
45+ try {
46+ e . preventDefault ( ) ;
47+
48+ document . getElementById ( 'error' ) . innerText = '' ;
49+ document . getElementById ( 'sendText' ) . disabled = true ;
50+
51+ const data = await getSummarizedText ( ) ;
52+
53+ title = document . getElementById ( 'title' ) . value ;
54+
55+ const body = {
56+ email,
57+ duration : meetingDuration ,
58+ title,
59+ content : meetingText ,
60+ markdown : data . summerised_text ,
61+ score : window . confidenceScore ,
62+ } ;
63+
64+ const res = await fetch ( 'http://standnote.herokuapp.com/notes/' , {
65+ method : 'post' ,
66+ headers : {
67+ 'Content-Type' : 'application/json' ,
68+ } ,
69+ body : JSON . stringify ( body ) ,
6670 } ) ;
71+
72+ if ( ! res . ok ) {
73+ throw new Error ( 'Something went Wrong!' ) ;
74+ }
75+
76+ const resData = await res . json ( ) ;
77+
78+ document . getElementsByClassName ( 'content' ) [ 0 ] . style . display = 'none' ;
79+ document . getElementsByClassName ( 'message' ) [ 0 ] . style . display = 'block' ;
80+ document . title = 'StandNote - Thanks for using StandNote' ;
81+ } catch ( err ) {
82+ console . log ( err ) ;
83+ document . getElementById ( 'sendText' ) . disabled = false ;
84+
85+ document . getElementById ( 'error' ) . innerText =
86+ 'Error while uploading the data!' ;
87+ }
6788 } ) ;
0 commit comments