Ali2206 commited on
Commit
5dcd1ab
·
1 Parent(s): ba1858c

Add loading states to all agent generate buttons with proper try-catch blocks

Browse files
AIDesign/app/static/index.html CHANGED
@@ -127,6 +127,13 @@
127
  const toneSel = document.getElementById('tone');
128
  form.addEventListener('submit', async (e)=>{
129
  e.preventDefault();
 
 
 
 
 
 
 
130
  wire.innerHTML = '(loading)';
131
  mm.textContent = '(loading)';
132
  mmSvg.style.display='none';
@@ -196,6 +203,11 @@
196
  }
197
  }
198
  }catch(err){ wire.textContent=String(err); mm.textContent=''; raw.textContent=''; }
 
 
 
 
 
199
  });
200
  openNew.addEventListener('click', ()=>{
201
  if (!lastWireHtml) {
 
127
  const toneSel = document.getElementById('tone');
128
  form.addEventListener('submit', async (e)=>{
129
  e.preventDefault();
130
+
131
+ // Set loading state
132
+ const submitBtn = form.querySelector('button[type="submit"]');
133
+ const originalText = submitBtn.textContent;
134
+ submitBtn.textContent = 'Generating...';
135
+ submitBtn.disabled = true;
136
+
137
  wire.innerHTML = '(loading)';
138
  mm.textContent = '(loading)';
139
  mmSvg.style.display='none';
 
203
  }
204
  }
205
  }catch(err){ wire.textContent=String(err); mm.textContent=''; raw.textContent=''; }
206
+ finally {
207
+ // Reset button state
208
+ submitBtn.textContent = originalText;
209
+ submitBtn.disabled = false;
210
+ }
211
  });
212
  openNew.addEventListener('click', ()=>{
213
  if (!lastWireHtml) {
AIIntegration/app/static/index.html CHANGED
@@ -61,6 +61,11 @@
61
  // no inline key input: rely on stored key
62
 
63
  elBtn.addEventListener('click', async () => {
 
 
 
 
 
64
  const payload = {
65
  question: elQ.value.trim(),
66
  channel: elC.value.trim() || null,
@@ -100,6 +105,10 @@
100
  `;
101
  } catch (e) {
102
  elOut.innerHTML = `<div style="color:#b91c1c;">Error: ${String(e)}</div>`;
 
 
 
 
103
  }
104
  });
105
  </script>
 
61
  // no inline key input: rely on stored key
62
 
63
  elBtn.addEventListener('click', async () => {
64
+ // Set loading state
65
+ const originalText = elBtn.textContent;
66
+ elBtn.textContent = 'Searching...';
67
+ elBtn.disabled = true;
68
+
69
  const payload = {
70
  question: elQ.value.trim(),
71
  channel: elC.value.trim() || null,
 
105
  `;
106
  } catch (e) {
107
  elOut.innerHTML = `<div style="color:#b91c1c;">Error: ${String(e)}</div>`;
108
+ } finally {
109
+ // Reset button state
110
+ elBtn.textContent = originalText;
111
+ elBtn.disabled = false;
112
  }
113
  });
114
  </script>
AIReadiness/app/static/index.html CHANGED
@@ -75,18 +75,26 @@
75
  }).join('');
76
  form.addEventListener('submit', async (e)=>{
77
  e.preventDefault();
 
 
 
 
 
 
 
78
  out.innerHTML = '(loading)';
79
  raw.textContent = '(loading)';
80
- const answers = questions.map((q,i)=>({ id: i+1, question: q, answer: (document.getElementById('q_'+(i+1)).value||'').trim() }));
81
- const body = { company: (company.value||'').trim() || undefined, industry: (industry.value||'').trim() || undefined, answers, api_key: (function(){ try { return (localStorage.getItem('OPENAI_API_KEY')||'').trim(); } catch(e){ return ''; } })() || null };
82
- const savedKey = (function(){ try { return (localStorage.getItem('OPENAI_API_KEY')||'').trim(); } catch(e){ return ''; } })();
83
- const r = await fetch('/audit/score', { method:'POST', headers:{'Content-Type':'application/json', 'Authorization': savedKey ? ('Bearer ' + savedKey) : undefined, 'x-openai-key': savedKey || ''}, body: JSON.stringify(body) });
84
- const text = await r.text();
85
- let data={};
86
- try{ data = text ? JSON.parse(text) : {}; }catch{ data = { error:text } }
87
- raw.textContent = JSON.stringify(data, null, 2);
88
- if(!r.ok){ out.textContent = 'Error generating scorecard'; return; }
89
- out.innerHTML = `
 
90
  <div class="card">
91
  <h2>${data.company || 'Your organization'}</h2>
92
  <p><strong>Overall readiness:</strong> ${data.overall_score}/100</p>
@@ -107,6 +115,13 @@
107
  <p><strong>Next steps</strong></p>
108
  <ul>${(data.next_steps||[]).map(x=>`<li>${x}</li>`).join('')}</ul>
109
  </div>`;
 
 
 
 
 
 
 
110
  });
111
  </script>
112
  </body>
 
75
  }).join('');
76
  form.addEventListener('submit', async (e)=>{
77
  e.preventDefault();
78
+
79
+ // Set loading state
80
+ const submitBtn = form.querySelector('button[type="submit"]');
81
+ const originalText = submitBtn.textContent;
82
+ submitBtn.textContent = 'Generating Scorecard...';
83
+ submitBtn.disabled = true;
84
+
85
  out.innerHTML = '(loading)';
86
  raw.textContent = '(loading)';
87
+ try {
88
+ const answers = questions.map((q,i)=>({ id: i+1, question: q, answer: (document.getElementById('q_'+(i+1)).value||'').trim() }));
89
+ const body = { company: (company.value||'').trim() || undefined, industry: (industry.value||'').trim() || undefined, answers, api_key: (function(){ try { return (localStorage.getItem('OPENAI_API_KEY')||'').trim(); } catch(e){ return ''; } })() || null };
90
+ const savedKey = (function(){ try { return (localStorage.getItem('OPENAI_API_KEY')||'').trim(); } catch(e){ return ''; } })();
91
+ const r = await fetch('/audit/score', { method:'POST', headers:{'Content-Type':'application/json', 'Authorization': savedKey ? ('Bearer ' + savedKey) : undefined, 'x-openai-key': savedKey || ''}, body: JSON.stringify(body) });
92
+ const text = await r.text();
93
+ let data={};
94
+ try{ data = text ? JSON.parse(text) : {}; }catch{ data = { error:text } }
95
+ raw.textContent = JSON.stringify(data, null, 2);
96
+ if(!r.ok){ out.textContent = 'Error generating scorecard'; return; }
97
+ out.innerHTML = `
98
  <div class="card">
99
  <h2>${data.company || 'Your organization'}</h2>
100
  <p><strong>Overall readiness:</strong> ${data.overall_score}/100</p>
 
115
  <p><strong>Next steps</strong></p>
116
  <ul>${(data.next_steps||[]).map(x=>`<li>${x}</li>`).join('')}</ul>
117
  </div>`;
118
+ } catch(err) {
119
+ out.textContent = 'Error: ' + err.message;
120
+ } finally {
121
+ // Reset button state
122
+ submitBtn.textContent = originalText;
123
+ submitBtn.disabled = false;
124
+ }
125
  });
126
  </script>
127
  </body>
AISolutions/app/static/index.html CHANGED
@@ -65,6 +65,13 @@
65
  // no inline key input: rely on stored key
66
  form.addEventListener('submit', async (e) => {
67
  e.preventDefault();
 
 
 
 
 
 
 
68
  const industry = document.getElementById('industry').value.trim();
69
  const pains = document.getElementById('pains').value.split(',').map(p=>p.trim()).filter(Boolean);
70
  const engine = 'agent';
@@ -90,6 +97,10 @@
90
  summaryEl.textContent = 'Error: ' + String(e);
91
  cardsEl.innerHTML = '';
92
  jsonEl.textContent = '';
 
 
 
 
93
  }
94
  });
95
  function renderLoading(){ summaryEl.textContent='Loading...'; cardsEl.innerHTML=''; jsonEl.textContent='(loading)'; }
 
65
  // no inline key input: rely on stored key
66
  form.addEventListener('submit', async (e) => {
67
  e.preventDefault();
68
+
69
+ // Set loading state
70
+ const submitBtn = form.querySelector('button[type="submit"]');
71
+ const originalText = submitBtn.textContent;
72
+ submitBtn.textContent = 'Finding Opportunities...';
73
+ submitBtn.disabled = true;
74
+
75
  const industry = document.getElementById('industry').value.trim();
76
  const pains = document.getElementById('pains').value.split(',').map(p=>p.trim()).filter(Boolean);
77
  const engine = 'agent';
 
97
  summaryEl.textContent = 'Error: ' + String(e);
98
  cardsEl.innerHTML = '';
99
  jsonEl.textContent = '';
100
+ } finally {
101
+ // Reset button state
102
+ submitBtn.textContent = originalText;
103
+ submitBtn.disabled = false;
104
  }
105
  });
106
  function renderLoading(){ summaryEl.textContent='Loading...'; cardsEl.innerHTML=''; jsonEl.textContent='(loading)'; }