Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update Dashboard.jsx
  • Loading branch information
JavaTypedScript authored Aug 30, 2025
commit 172a0462251ba49ba8bced5a2518fa6151983d98
31 changes: 23 additions & 8 deletions src/pages/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,34 @@ export default function Hero() {
const [messages, setMessages] = useState([]);
const [loading, setLoading] = useState(false);

const [results, setResults] = useState([]);

const fetchRecommendations = async () => {
const res = await fetch("http://127.0.0.1:8000/recommend", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: input, k: 5 }),
});
const data = await res.json();
setResults(data.recommendations);
setMessages((prev) => [...prev, { type: "ai", text: data.recommendations }]);
};

const handleSend = () => {
if (!input.trim()) return;

const userMessage = { type: "user", text: input };
setMessages((prev) => [...prev, userMessage]);
setInput("");
setLoading(true);



// Simulate AI response after 2s
setTimeout(() => {
const aiMessage = {
type: "ai",
text: `Maga, still under construction , ill recommend u once my boss activates me `,
};
setMessages((prev) => [...prev, aiMessage]);
setLoading(false);
fetchRecommendations();//Maga Api is heavy fast, so slowing it down to show animation
}, 1500);
setLoading(false);

};

return (
Expand Down Expand Up @@ -91,7 +102,11 @@ export default function Hero() {
<>
<SparklesIcon className="w-10 h-10 text-indigo-600" />
<div className="bg-white px-4 py-3 rounded-xl shadow w-full">
<p dangerouslySetInnerHTML={{ __html: msg.text }}></p>
<p>
{msg.text.map((item, idx) => (
<li key={idx}>{item.track_name}</li>
))}
</p>
</div>
</>
)}
Expand Down