import { useState, useEffect } from "react"; import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { LineChart, Line, XAxis, YAxis, Tooltip, CartesianGrid } from "recharts"; import { ArrowUpCircle, ArrowDownCircle, RefreshCw } from "lucide-react"; import { motion } from "framer-motion"; export default function CryptoSentimentDashboard() { const [sentimentData, setSentimentData] = useState(null); const [loading, setLoading] = useState(true); const [history, setHistory] = useState([]); useEffect(() => { fetchSentiment(); const interval = setInterval(fetchSentiment, 60000); // Auto-refresh every 60 sec return () => clearInterval(interval); }, []); const fetchSentiment = async () => { try { const response = await fetch("https://www.dgtechnologies.co.za/news-sentiment.php"); const data = await response.json(); setSentimentData(data); setLoading(false); setHistory((prev) => [...prev.slice(-10), { time: new Date().toLocaleTimeString(), bullish: data.bullish_votes, bearish: data.bearish_votes }]); } catch (error) { console.error("Error fetching sentiment:", error); setLoading(false); } }; return (
Crypto Sentiment Dashboard XRP Sentiment {loading ? (

Loading...

) : (
{sentimentData?.bullish_votes} Bullish
{sentimentData?.bearish_votes} Bearish
Overall Sentiment: {sentimentData?.sentiment}
)}
{/* Sentiment Over Time Chart */}

Sentiment Over Time

); }