Spaces:
Paused
Paused
Download frontend/apps/customer/src/components/ChatWindow.tsx from 3SCError404/miracle: direct link, hf CLI and curl.
- Browser
- Download file 2.9 kB
-
https://huggingface.co/spaces/3SCError404/miracle/resolve/main/frontend/apps/customer/src/components/ChatWindow.tsx
- Command line
-
hf download hf://spaces/3SCError404/miracle/frontend/apps/customer/src/components/ChatWindow.tsx
-
curl -L -o ChatWindow.tsx https://huggingface.co/spaces/3SCError404/miracle/resolve/main/frontend/apps/customer/src/components/ChatWindow.tsx
2.9 kB
| import React, { useState, useRef, useEffect } from 'react'; | |
| import { motion, AnimatePresence } from 'framer-motion'; | |
| import { Button, Input } from '@nexus/shared'; | |
| import styles from './ChatWindow.module.css'; | |
| interface Message { | |
| role: 'user' | 'assistant'; | |
| content: string; | |
| } | |
| interface ChatWindowProps { | |
| messages: Message[]; | |
| onSendMessage: (text: string) => void; | |
| loading?: boolean; | |
| } | |
| export const ChatWindow: React.FC<ChatWindowProps> = ({ messages, onSendMessage, loading }) => { | |
| const [input, setInput] = useState(''); | |
| const scrollRef = useRef<HTMLDivElement>(null); | |
| useEffect(() => { | |
| if (scrollRef.current) { | |
| scrollRef.current.scrollTop = scrollRef.current.scrollHeight; | |
| } | |
| }, [messages, loading]); | |
| const handleSend = () => { | |
| if (!input.trim()) return; | |
| onSendMessage(input); | |
| setInput(''); | |
| }; | |
| return ( | |
| <div className={styles.container}> | |
| <div className={styles.messages} ref={scrollRef}> | |
| <AnimatePresence mode="popLayout"> | |
| {messages.length === 0 ? ( | |
| <motion.div | |
| key="welcome" | |
| initial={{ opacity: 0, scale: 0.95 }} | |
| animate={{ opacity: 1, scale: 1 }} | |
| exit={{ opacity: 0, scale: 0.9 }} | |
| className={styles.welcome} | |
| > | |
| <h2>Nexus is Ready</h2> | |
| <p>How can I assist you with your workspace today?</p> | |
| </motion.div> | |
| ) : ( | |
| messages.map((msg, idx) => ( | |
| <motion.div | |
| key={idx} | |
| initial={{ opacity: 0, y: 10, scale: 0.95 }} | |
| animate={{ opacity: 1, y: 0, scale: 1 }} | |
| transition={{ type: 'spring', damping: 20, stiffness: 300 }} | |
| className={`${styles.bubble} ${styles[msg.role]}`} | |
| > | |
| <p className={styles.content}>{msg.content}</p> | |
| </motion.div> | |
| )) | |
| )} | |
| {loading && ( | |
| <motion.div | |
| key="loading" | |
| initial={{ opacity: 0, y: 5 }} | |
| animate={{ opacity: 1, y: 0 }} | |
| exit={{ opacity: 0 }} | |
| className={`${styles.bubble} ${styles.assistant} ${styles.loading}`} | |
| > | |
| <div className={styles.dot}></div> | |
| <div className={styles.dot}></div> | |
| <div className={styles.dot}></div> | |
| </motion.div> | |
| )} | |
| </AnimatePresence> | |
| </div> | |
| <div className={styles.footer}> | |
| <Input | |
| placeholder="Ask Nexus anything..." | |
| value={input} | |
| onChange={(e) => setInput(e.target.value)} | |
| onKeyPress={(e) => e.key === 'Enter' && handleSend()} | |
| className={styles.input} | |
| /> | |
| <Button onClick={handleSend} loading={loading} className={styles.sendBtn}> | |
| Send | |
| </Button> | |
| </div> | |
| </div> | |
| ); | |
| }; | |