2025-12-24 11:51:40 +00:00
|
|
|
import React, { useEffect, useRef, useState } from 'react';
|
2025-12-13 02:34:34 +00:00
|
|
|
import { useChatStore } from '../store/chatStore';
|
2025-12-03 21:56:50 +00:00
|
|
|
import { ChatMessageComponent } from './ChatMessage';
|
|
|
|
|
import { useChat } from '../hooks/useChat';
|
2025-12-24 11:51:40 +00:00
|
|
|
import { MessageSearch } from './MessageSearch';
|
|
|
|
|
import { TypingIndicator } from './TypingIndicator';
|
2026-01-26 13:12:17 +00:00
|
|
|
import {
|
|
|
|
|
Search, X, Disc,
|
|
|
|
|
Clock,
|
|
|
|
|
MessageSquare, Wifi
|
|
|
|
|
} from 'lucide-react';
|
2025-12-24 11:51:40 +00:00
|
|
|
import { Button } from '@/components/ui/button';
|
2026-01-11 02:20:52 +00:00
|
|
|
import { cn } from '@/lib/utils';
|
2026-01-16 11:31:40 +00:00
|
|
|
import { useUser } from '@/features/auth/hooks/useUser';
|
2025-12-03 21:56:50 +00:00
|
|
|
|
|
|
|
|
interface ChatRoomProps {
|
|
|
|
|
conversationId: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const ChatRoom: React.FC<ChatRoomProps> = ({ conversationId }) => {
|
2026-01-11 02:20:52 +00:00
|
|
|
const { messages, wsStatus } = useChatStore();
|
2025-12-03 21:56:50 +00:00
|
|
|
const { fetchHistory } = useChat();
|
2026-01-16 11:31:40 +00:00
|
|
|
const { data: user } = useUser();
|
|
|
|
|
const currentUserId = user?.id;
|
2025-12-03 21:56:50 +00:00
|
|
|
const messagesEndRef = useRef<HTMLDivElement>(null);
|
2025-12-24 11:51:40 +00:00
|
|
|
const [showSearch, setShowSearch] = useState(false);
|
2026-01-13 18:47:57 +00:00
|
|
|
const [highlightedMessageId, setHighlightedMessageId] = useState<
|
|
|
|
|
string | null
|
|
|
|
|
>(null);
|
2025-12-03 21:56:50 +00:00
|
|
|
|
|
|
|
|
const currentMessages = messages[conversationId] || [];
|
2026-01-03 17:48:45 +00:00
|
|
|
const fetchingRef = useRef<{ [key: string]: boolean }>({});
|
|
|
|
|
|
2025-12-03 21:56:50 +00:00
|
|
|
useEffect(() => {
|
2026-01-13 18:47:57 +00:00
|
|
|
if (
|
|
|
|
|
conversationId &&
|
|
|
|
|
!messages[conversationId] &&
|
|
|
|
|
!fetchingRef.current[conversationId]
|
|
|
|
|
) {
|
2026-01-03 17:48:45 +00:00
|
|
|
fetchingRef.current[conversationId] = true;
|
|
|
|
|
fetchHistory(conversationId).finally(() => {
|
2026-01-11 02:20:52 +00:00
|
|
|
// Fetch complete
|
2026-01-03 17:48:45 +00:00
|
|
|
});
|
2025-12-03 21:56:50 +00:00
|
|
|
}
|
2026-01-03 17:48:45 +00:00
|
|
|
}, [conversationId, messages[conversationId], fetchHistory]);
|
2025-12-03 21:56:50 +00:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-01-11 02:20:52 +00:00
|
|
|
if (messagesEndRef.current) {
|
|
|
|
|
messagesEndRef.current.scrollIntoView({ behavior: 'smooth' });
|
|
|
|
|
}
|
|
|
|
|
}, [currentMessages.length, conversationId]); // Scroll on new messages or channel switch
|
2025-12-03 21:56:50 +00:00
|
|
|
|
2025-12-24 11:51:40 +00:00
|
|
|
const handleMessageSelect = (messageId: string) => {
|
|
|
|
|
setHighlightedMessageId(messageId);
|
|
|
|
|
const messageElement = document.getElementById(`message-${messageId}`);
|
|
|
|
|
if (messageElement) {
|
|
|
|
|
messageElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
|
|
|
setTimeout(() => setHighlightedMessageId(null), 3000);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-03 21:56:50 +00:00
|
|
|
if (!conversationId) {
|
|
|
|
|
return (
|
2026-01-11 02:20:52 +00:00
|
|
|
<div className="flex-1 flex flex-col items-center justify-center text-kodo-secondary opacity-50 space-y-4">
|
|
|
|
|
<div className="w-24 h-24 rounded-full bg-white/5 flex items-center justify-center animate-pulse">
|
2026-01-16 10:40:13 +00:00
|
|
|
<Wifi className="w-10 h-10 text-kodo-steel opacity-50" />
|
2026-01-11 02:20:52 +00:00
|
|
|
</div>
|
2026-01-13 18:47:57 +00:00
|
|
|
<p className="text-sm font-mono uppercase tracking-widest">
|
|
|
|
|
Awaiting Frequency Selection
|
|
|
|
|
</p>
|
2025-12-03 21:56:50 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-01-11 02:20:52 +00:00
|
|
|
<div className="flex-1 flex flex-col h-full overflow-hidden">
|
|
|
|
|
{/* Search Header Overlay */}
|
2026-01-13 18:47:57 +00:00
|
|
|
<div
|
|
|
|
|
className={cn(
|
feat(web): UI premium Discord/Spotify-like — tokens, shadows, focus, layout
Plan UI premium 6–8 semaines (design system, shell, Storybook, a11y):
- Design system: DESIGN_TOKENS.md, APP_SHELL.md, FULL_LAYOUT_PAGE.md. Single source
for layout/shell (index.css), shadows (design-system.css), durations/easing.
- Tokens: shadow-cover-depth, shadow-gold-glow, shadow-fab-glow; layout max-height
(max-h-layout-drawer, max-h-layout-panel, max-h-layout-list). All duration-200/300/500
replaced by --duration-fast/normal/slow. Arbitrary shadows replaced by token classes.
- Shell & player: Sidebar, Header, GlobalPlayer, MiniPlayer, PlayerQueue, PlayerControls,
AudioPlayer use tokens; focus-visible on Sidebar, PlayerQueue, DropdownMenuTrigger/Item,
TabsTrigger. Typography: text-[10px]/[9px] → text-xs where applicable.
- ESLint: no-restricted-syntax (warn) for w-/h-/rounded-/shadow-/text-/spacing arbitrary.
- Scripts: report-arbitrary-values.mjs, capture/compare/generate visual; visual-complete.spec.ts.
- Stories full layout: Dashboard, Playlists, Library, Settings, Profile in DashboardLayout.stories.
- .cursorrules + README: DESIGN_TOKENS, APP_SHELL, visual commands, no arbitrary without justification.
- apps/web/.gitignore: e2e test artifacts (test-results-visual, playwright-report-visual).
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 16:15:58 +00:00
|
|
|
'absolute top-0 left-0 right-0 z-20 px-4 py-2 transition-all duration-[var(--duration-normal)]',
|
2026-01-13 18:47:57 +00:00
|
|
|
showSearch
|
|
|
|
|
? 'bg-kodo-void/90 backdrop-blur-md border-b border-white/10'
|
|
|
|
|
: 'bg-transparent pointer-events-none',
|
|
|
|
|
)}
|
|
|
|
|
>
|
2025-12-24 11:51:40 +00:00
|
|
|
{showSearch ? (
|
2026-01-11 02:20:52 +00:00
|
|
|
<div className="flex items-center gap-2 max-w-2xl mx-auto">
|
2025-12-24 11:51:40 +00:00
|
|
|
<div className="flex-1">
|
|
|
|
|
<MessageSearch
|
|
|
|
|
conversationId={conversationId}
|
|
|
|
|
onMessageSelect={handleMessageSelect}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={() => setShowSearch(false)}
|
2026-01-11 02:20:52 +00:00
|
|
|
className="hover:bg-white/10"
|
2025-12-24 11:51:40 +00:00
|
|
|
>
|
|
|
|
|
<X className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
2026-01-11 02:20:52 +00:00
|
|
|
<div className="flex justify-end pointer-events-auto">
|
2025-12-24 11:51:40 +00:00
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={() => setShowSearch(true)}
|
2026-01-16 09:51:30 +00:00
|
|
|
className="text-kodo-secondary/50 hover:text-white hover:bg-white/5 bg-black/20 backdrop-blur-sm rounded-full h-8 px-4 border border-white/5"
|
2025-12-24 11:51:40 +00:00
|
|
|
>
|
2026-01-11 02:20:52 +00:00
|
|
|
<Search className="h-3 w-3 mr-2" />
|
|
|
|
|
<span className="text-xs font-mono uppercase">Search Log</span>
|
2025-12-24 11:51:40 +00:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-01-11 02:20:52 +00:00
|
|
|
<div className="flex-1 overflow-y-auto custom-scrollbar p-6 space-y-4 scroll-smooth">
|
|
|
|
|
{/* Welcome Message for Empty Room */}
|
|
|
|
|
{currentMessages.length === 0 && (
|
aesthetic-improvements: align spacing to 8px grid (Action 11.2.1.3)
- Created automated script (scripts/align-8px-grid.py) to align all spacing to 8px grid
- Replaced non-8px-aligned spacing: gap-3/p-3/m-3 (12px) → gap-4/p-4/m-4 (16px), gap-5/p-5/m-5 (20px) → gap-6/p-6/m-6 (24px), gap-10/p-10/m-10 (40px) → gap-12/p-12/m-12 (48px), gap-20/p-20/m-20 (80px) → gap-24/p-24/m-24 (96px)
- Preserved: 4px values (gap-1, p-1, m-1) as they may be intentional fine-tuning, responsive breakpoints (sm:, md:, lg:), test files, documentation
- Modified files across all components to ensure consistent 8px grid alignment
- Action 11.2.1.3: Align all elements to 8px grid - COMPLETE
2026-01-16 10:50:46 +00:00
|
|
|
<div className="flex flex-col items-center justify-center h-[50vh] text-center space-y-4 opacity-60">
|
2026-02-08 23:08:42 +00:00
|
|
|
<div className="w-12 h-12 rounded-xl bg-muted/10 flex items-center justify-center border border-border/20">
|
aesthetic-improvements: reduce decorative cyan in error and chat components (80/20 rule, batch 6)
- NotFoundPage: decorative icon background (bg-kodo-cyan/20 → bg-kodo-steel/20, icon text-kodo-cyan → text-kodo-steel)
- ServerErrorPage: informational status box (bg-kodo-cyan/10 → bg-kodo-steel/10, border-kodo-cyan → border-kodo-steel, icon/text text-kodo-cyan → text-kodo-steel)
- ChatRoom: empty state icon background (bg-kodo-cyan/10 → bg-kodo-steel/10, border-kodo-cyan/20 → border-kodo-steel/20, icon text-kodo-cyan → text-kodo-steel)
- PlaybackHeatmap: stats box background (bg-kodo-cyan/10 → bg-kodo-steel/10, text-kodo-cyan → text-kodo-steel)
- Total: ~4 files, ~5 instances replaced
- Preserved: Active/functional states (ChatInput drag active overlay, ChatRoom highlighted message, TrackFilters active filters badge, PlaylistBatchActions batch mode banner, PlaybackHeatmap intensity visualization - functional), semantic status indicators (TrackHistory updated action - semantic color)
- Action 11.3.1.3 in progress (sixth batch: error pages and chat components)
2026-01-16 10:15:52 +00:00
|
|
|
<MessageSquare className="w-6 h-6 text-kodo-steel" />
|
2026-01-11 02:20:52 +00:00
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<p className="text-white font-medium">Channel Established</p>
|
2026-01-13 18:47:57 +00:00
|
|
|
<p className="text-sm text-kodo-secondary mt-1">
|
|
|
|
|
Begin transmission on this frequency.
|
|
|
|
|
</p>
|
2026-01-11 02:20:52 +00:00
|
|
|
</div>
|
2025-12-03 21:56:50 +00:00
|
|
|
</div>
|
2026-01-11 02:20:52 +00:00
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Message Stream */}
|
|
|
|
|
{currentMessages.map((msg, index) => {
|
2026-01-16 11:31:40 +00:00
|
|
|
const isMe = currentUserId ? msg.sender_id === currentUserId : false;
|
2026-01-13 18:47:57 +00:00
|
|
|
const isSequence =
|
|
|
|
|
index > 0 && currentMessages[index - 1].sender_id === msg.sender_id;
|
|
|
|
|
|
2026-01-11 02:20:52 +00:00
|
|
|
return (
|
2025-12-24 11:51:40 +00:00
|
|
|
<div
|
|
|
|
|
key={msg.id}
|
|
|
|
|
id={`message-${msg.id}`}
|
2026-01-11 02:20:52 +00:00
|
|
|
className={cn(
|
feat(web): UI premium Discord/Spotify-like — tokens, shadows, focus, layout
Plan UI premium 6–8 semaines (design system, shell, Storybook, a11y):
- Design system: DESIGN_TOKENS.md, APP_SHELL.md, FULL_LAYOUT_PAGE.md. Single source
for layout/shell (index.css), shadows (design-system.css), durations/easing.
- Tokens: shadow-cover-depth, shadow-gold-glow, shadow-fab-glow; layout max-height
(max-h-layout-drawer, max-h-layout-panel, max-h-layout-list). All duration-200/300/500
replaced by --duration-fast/normal/slow. Arbitrary shadows replaced by token classes.
- Shell & player: Sidebar, Header, GlobalPlayer, MiniPlayer, PlayerQueue, PlayerControls,
AudioPlayer use tokens; focus-visible on Sidebar, PlayerQueue, DropdownMenuTrigger/Item,
TabsTrigger. Typography: text-[10px]/[9px] → text-xs where applicable.
- ESLint: no-restricted-syntax (warn) for w-/h-/rounded-/shadow-/text-/spacing arbitrary.
- Scripts: report-arbitrary-values.mjs, capture/compare/generate visual; visual-complete.spec.ts.
- Stories full layout: Dashboard, Playlists, Library, Settings, Profile in DashboardLayout.stories.
- .cursorrules + README: DESIGN_TOKENS, APP_SHELL, visual commands, no arbitrary without justification.
- apps/web/.gitignore: e2e test artifacts (test-results-visual, playwright-report-visual).
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 16:15:58 +00:00
|
|
|
'transition-all duration-[var(--duration-slow)] animate-slideUp',
|
2026-01-13 18:47:57 +00:00
|
|
|
highlightedMessageId === msg.id &&
|
2026-02-08 23:08:42 +00:00
|
|
|
'bg-muted/10 rounded-xl -mx-4 px-4 py-2 ring-1 ring-kodo-steel/30',
|
2026-01-11 02:20:52 +00:00
|
|
|
)}
|
2025-12-24 11:51:40 +00:00
|
|
|
>
|
|
|
|
|
<ChatMessageComponent message={msg} />
|
|
|
|
|
</div>
|
2026-01-11 02:20:52 +00:00
|
|
|
);
|
|
|
|
|
})}
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2025-12-24 11:51:40 +00:00
|
|
|
<TypingIndicator conversationId={conversationId} />
|
2026-01-11 02:20:52 +00:00
|
|
|
<div ref={messagesEndRef} className="h-4" />
|
2025-12-03 21:56:50 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2026-01-13 18:47:57 +00:00
|
|
|
};
|