import { useState, useEffect, useRef } from 'react' import { useNavigate } from 'react-router-dom' import { api } from '../api' export default function Support() { const [messages, setMessages] = useState([]) const [loading, setLoading] = useState(true) const [sending, setSending] = useState(false) const [input, setInput] = useState('') const [confirmation, setConfirmation] = useState(null) const bottomRef = useRef(null) const navigate = useNavigate() useEffect(() => { loadThread() }, []) useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: 'smooth' }) }, [messages]) async function loadThread() { try { const data = await api.getThread() setMessages(data.messages || []) } catch (err) { console.error(err) } finally { setLoading(false) } } async function handleSend(e) { e.preventDefault() const body = input.trim() if (!body || sending) return setSending(true) setConfirmation(null) try { const result = await api.sendSupportMessage(body) setInput('') setConfirmation(result.message) await loadThread() } catch (err) { setConfirmation(err.message) } finally { setSending(false) } } function formatTime(iso) { const d = new Date(iso) const now = new Date() const diff = now - d if (diff < 60000) return 'Just now' if (diff < 3600000) return `${Math.floor(diff / 60000)}m ago` if (diff < 86400000) return `${Math.floor(diff / 3600000)}h ago` return d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' }) + ' ' + d.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' }) } if (loading) return
Loading...
return (
{/* Header */}

Support

Ask a question — we'll get back to you

{/* Messages */}
{messages.length === 0 && (
💬
No messages yet. Ask anything about your workouts, program, or the app.
)} {messages.map(m => (
{m.body}
{formatTime(m.created_at)} {m.sender === 'user' && m.read_at && ' ✓'}
))} {confirmation && (
{confirmation}
)}
{/* Input */}
setInput(e.target.value)} placeholder="Type your question..." maxLength={2000} style={{ flex: 1, padding: '12px 14px', borderRadius: 'var(--r-full)', border: '1px solid var(--divider)', fontFamily: 'var(--font)', fontSize: '0.88rem', background: 'var(--bg)', }} />
) }