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,
|
2026-02-09 22:23:09 +00:00
|
|
|
MessageSquare
|
2026-01-26 13:12:17 +00:00
|
|
|
} 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-02-09 22:23:09 +00:00
|
|
|
<div className="flex-1 flex flex-col items-center justify-center text-muted-foreground space-y-4 animate-empty-state-in">
|
|
|
|
|
<div className="w-24 h-24 rounded-full bg-muted flex items-center justify-center">
|
|
|
|
|
<MessageSquare className="w-10 h-10 text-muted-foreground" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-center">
|
|
|
|
|
<p className="text-sm font-medium text-foreground mb-1">
|
|
|
|
|
No conversation selected
|
|
|
|
|
</p>
|
|
|
|
|
<p className="text-xs text-muted-foreground">
|
|
|
|
|
Pick a channel from the sidebar to start chatting.
|
|
|
|
|
</p>
|
2026-01-11 02:20:52 +00:00
|
|
|
</div>
|
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-02-08 23:13:27 +00:00
|
|
|
className="text-muted-foreground/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 && (
|
2026-02-09 22:23:09 +00:00
|
|
|
<div className="flex flex-col items-center justify-center h-[50vh] text-center space-y-4 animate-empty-state-in">
|
|
|
|
|
<div className="w-14 h-14 rounded-full bg-muted flex items-center justify-center">
|
|
|
|
|
<MessageSquare className="w-7 h-7 text-muted-foreground" />
|
2026-01-11 02:20:52 +00:00
|
|
|
</div>
|
|
|
|
|
<div>
|
2026-02-09 22:23:09 +00:00
|
|
|
<p className="text-foreground font-medium">No messages yet</p>
|
2026-02-08 23:13:27 +00:00
|
|
|
<p className="text-sm text-muted-foreground mt-1">
|
2026-02-09 22:23:09 +00:00
|
|
|
Send the first message to start the conversation.
|
2026-01-13 18:47:57 +00:00
|
|
|
</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
|
|
|
};
|