From f0d83291fceed43159ef1e2fafb44101930c4e7f Mon Sep 17 00:00:00 2001 From: Ankit Singh Date: Thu, 29 May 2025 23:09:00 +0530 Subject: [PATCH] Create askques.jsx --- frontend/src/components/askques.jsx | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 frontend/src/components/askques.jsx diff --git a/frontend/src/components/askques.jsx b/frontend/src/components/askques.jsx new file mode 100644 index 0000000..2a97dde --- /dev/null +++ b/frontend/src/components/askques.jsx @@ -0,0 +1,60 @@ +import React, { useState } from 'react'; + +const AskQuestion = ({ summary }) => { + const [question, setQuestion] = useState(''); + const [answer, setAnswer] = useState(''); + const [loading, setLoading] = useState(false); + + const handleAsk = async () => { + if (!question.trim()) { + alert('Please enter a question.'); + return; + } + setLoading(true); + setAnswer(''); + + try { + const res = await fetch('https://gistify-snowy.vercel.app/ask-question', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ summary, question }), + }); + + const data = await res.json(); + setAnswer(data.answer || 'No answer received.'); + } catch (err) { + console.error(err); + setAnswer('❌ Failed to fetch answer.'); + } + + setLoading(false); + }; + + return ( +
+

Ask a Question About the Summary

+ setQuestion(e.target.value)} + placeholder="Type your question..." + style={{ width: '100%', padding: '10px', marginTop: '8px' }} + /> + + {loading ? ( +

Thinking...

+ ) : ( + answer &&

Answer: {answer}

+ )} +
+ ); +}; + +export default AskQuestion;