'use client'; import { useState, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Music, Code, Monitor, MessageSquare, Send, X } from 'lucide-react'; interface ActivityData { activity: { type: 'coding' | 'listening' | 'watching'; details: string; timestamp: string; } | null; music: { isPlaying: boolean; track: string; artist: string; platform: 'spotify' | 'apple'; } | null; watching: { title: string; platform: 'youtube' | 'netflix'; } | null; } export const ActivityFeed = () => { const [data, setData] = useState(null); const [showChat, setShowChat] = useState(false); const [chatMessage, setChatMessage] = useState(''); const [chatHistory, setChatHistory] = useState<{ role: 'user' | 'ai'; text: string; }[]>([ { role: 'ai', text: 'Hi! I am Dennis\'s AI assistant. Ask me anything about him!' } ]); useEffect(() => { const fetchData = async () => { try { const res = await fetch('/api/n8n/status'); if (res.ok) { const json = await res.json(); setData(json); } } catch (e) { console.error('Failed to fetch activity', e); } }; fetchData(); const interval = setInterval(fetchData, 30000); // Poll every 30s return () => clearInterval(interval); }, []); const handleSendMessage = (e: React.FormEvent) => { e.preventDefault(); if (!chatMessage.trim()) return; const userMsg = chatMessage; setChatHistory(prev => [...prev, { role: 'user', text: userMsg }]); setChatMessage(''); // Mock AI response - would connect to n8n webhook setTimeout(() => { setChatHistory(prev => [...prev, { role: 'ai', text: `That's a great question about "${userMsg}"! I'll ask Dennis to add more info about that.` }]); }, 1000); }; if (!data) return null; return (
{/* Chat Window */} {showChat && (
Ask me anything
{chatHistory.map((msg, i) => (
{msg.text}
))}
setChatMessage(e.target.value)} placeholder="Type a message..." className="flex-1 bg-white/60 border border-white/60 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-stone-400" />
)}
{/* Activity Bubbles */}
{data.activity?.type === 'coding' && ( Working on {data.activity.details} )} {data.music?.isPlaying && ( Listening to {data.music.track} )} {/* Chat Toggle Button */} setShowChat(!showChat)} className="bg-stone-900 text-white rounded-full p-4 shadow-xl hover:bg-black transition-all" >
); };