// ───────────────────────────────────────────────────────────── // Dashboard — Rooms listing page // ───────────────────────────────────────────────────────────── 'use client'; import { useState, useEffect } from 'react'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { Plus, Code2, Users, Clock, Globe, Lock, MoreVertical, Trash2, Settings, LogOut, } from 'lucide-react'; import { roomsApi } from '../../../lib/api'; import { useAuthStore } from '../../../stores/authStore'; import { formatRelativeTime, cn } from '../../../lib/utils'; import type { Room } from '../../../types'; export default function RoomsPage() { const router = useRouter(); const { user, isAuthenticated, logout } = useAuthStore(); const [rooms, setRooms] = useState([]); const [isLoading, setIsLoading] = useState(true); const [showCreateModal, setShowCreateModal] = useState(false); useEffect(() => { if (!isAuthenticated) { router.push('/login'); return; } loadRooms(); }, [isAuthenticated]); const loadRooms = async () => { try { const data = await roomsApi.list() as Room[]; setRooms(data); } catch (error) { console.error('Failed to load rooms:', error); } finally { setIsLoading(false); } }; const handleCreateRoom = async (data: any) => { try { const room = await roomsApi.create(data) as Room; setRooms([room, ...rooms]); setShowCreateModal(false); router.push(`/room/${room.id}`); } catch (error) { console.error('Failed to create room:', error); } }; return (
{/* Header */}
CodeSync
{user?.name?.charAt(0).toUpperCase()}
{user?.name}
{/* Content */}

Your Rooms

Create or join coding rooms to collaborate in real-time

{/* Rooms Grid */} {isLoading ? (
{[1, 2, 3].map((i) => (
))}
) : rooms.length === 0 ? (

No rooms yet

Create your first room to start collaborating

) : (
{rooms.map((room) => ( ))}
)}
{/* Create Room Modal */} {showCreateModal && ( setShowCreateModal(false)} onCreate={handleCreateRoom} /> )}
); } // ─── Room Card ─────────────────────────────────────────────── function RoomCard({ room }: { room: Room }) { return (

{room.name}

{room.isPublic ? ( ) : ( )}
{room.language} {formatRelativeTime(room.updatedAt)}
); } // ─── Create Room Modal ─────────────────────────────────────── function CreateRoomModal({ onClose, onCreate }: { onClose: () => void; onCreate: (data: any) => void }) { const [name, setName] = useState(''); const [language, setLanguage] = useState('javascript'); const [isPublic, setIsPublic] = useState(false); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (!name.trim()) return; onCreate({ name, language, isPublic }); }; return (
e.stopPropagation()}>

Create New Room

setName(e.target.value)} required autoFocus />
setIsPublic(e.target.checked)} className="rounded border-editor-border" />
); }