File size: 1,473 Bytes
9853b20
 
 
 
 
007aef6
9853b20
 
 
 
 
 
 
 
 
 
 
 
 
007aef6
9853b20
 
007aef6
9853b20
 
007aef6
9853b20
 
 
007aef6
9853b20
 
 
 
 
 
 
 
 
 
007aef6
 
9853b20
 
 
007aef6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use client'

import { useState, useEffect, useRef } from 'react'
import type { MessageData } from 'lib/messages'
import { formatTime } from 'lib/utils'
import { Chat } from './Chat'

interface TestRoomClientProps {
  initialCode?: string
  roomName?: string
}

export function TestRoomClient({ initialCode = 'TST01', roomName = 'Test místnost' }: TestRoomClientProps) {
  const demoRoomId = 'demo-room'
  const [messages, setMessages] = useState<MessageData[]>([
    { id: 'm1', room_id: demoRoomId, content: 'Vítejte v testovací místnosti!', created_at: new Date(Date.now() - 100000).toISOString(), code_id: initialCode },
    { id: 'm2', room_id: demoRoomId, content: 'Zkuste napsat zprávu níže.', created_at: new Date(Date.now() - 50000).toISOString(), code_id: 'OTHER' }
  ])

  const messagesEndRef = useRef<HTMLDivElement>(null)

  useEffect(() => {
    messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' })
  }, [messages])

  const handleSend = (content: string) => {
    const msg: MessageData = {
      id: Date.now().toString(),
      room_id: demoRoomId,
      content,
      created_at: new Date().toISOString(),
      code_id: initialCode
    }

    setMessages(prev => [...prev, msg])
  }

  return (
    <div className="page leftright">
      <div className="frame">
        <Chat messages={messages} currentCodeId={initialCode} roomName={roomName} onSend={handleSend} />
        <div ref={messagesEndRef} />
      </div>
    </div>
  )
}