batch3 T8: chat->file click, Session.tsx rewires to Workspace, sidebar polish
- MessageBubble & ToolCallCard: detect path-like strings in rendered text via regex requiring slash+extension; clicks dispatch open_file_in_browser - Session.tsx: now renders <Workspace sessionId projectId>; on mount, emits session_loaded so sidebar can highlight even deep-linked sessions not in the recent_sessions cache - ProjectSidebar: active project's chevron visually disabled (50% opacity, cursor-not-allowed) and click no-op; activeSession from useSidebar used as fallback when active session isn't in cache Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,43 +1,43 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Link, useParams } from 'react-router-dom';
|
||||
import { ChevronLeft } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
import { api } from '@/api/client';
|
||||
import type { Session as SessionType } from '@/api/types';
|
||||
import { useSessionStream } from '@/hooks/useSessionStream';
|
||||
import { sessionEvents } from '@/hooks/sessionEvents';
|
||||
import { MessageList } from '@/components/MessageList';
|
||||
import { ChatInput } from '@/components/ChatInput';
|
||||
import { Workspace } from '@/components/Workspace';
|
||||
import { ModelPicker } from '@/components/ModelPicker';
|
||||
|
||||
export function Session() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const stream = useSessionStream(id);
|
||||
const [session, setSession] = useState<SessionType | null>(null);
|
||||
const [name, setName] = useState('');
|
||||
const [editingName, setEditingName] = useState(false);
|
||||
const lastErrorRef = useRef<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (stream.error && stream.error !== lastErrorRef.current) {
|
||||
lastErrorRef.current = stream.error;
|
||||
toast.error(stream.error);
|
||||
}
|
||||
if (!stream.error) {
|
||||
lastErrorRef.current = null;
|
||||
}
|
||||
}, [stream.error]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!id) return;
|
||||
setSession(null);
|
||||
let cancelled = false;
|
||||
api.sessions
|
||||
.get(id)
|
||||
.then((s) => {
|
||||
if (cancelled) return;
|
||||
setSession(s);
|
||||
setName(s.name);
|
||||
// Emit unconditionally — the sidebar's session_loaded handler
|
||||
// updates activeSession; redundant when the session is already in
|
||||
// the recent_sessions cache but harmless. This lets the sidebar
|
||||
// highlight the parent project for deep-linked sessions that
|
||||
// aren't in the cache.
|
||||
sessionEvents.emit({
|
||||
type: 'session_loaded',
|
||||
session_id: id,
|
||||
project_id: s.project_id,
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [id]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -68,13 +68,6 @@ export function Session() {
|
||||
setEditingName(false);
|
||||
}
|
||||
|
||||
async function handleSend(content: string) {
|
||||
if (!id) return;
|
||||
await api.messages.send(id, content);
|
||||
}
|
||||
|
||||
const streaming = stream.messages.some((m) => m.status === 'streaming');
|
||||
|
||||
return (
|
||||
<div className="flex-1 flex flex-col min-h-0">
|
||||
<header className="border-b px-4 py-2 flex items-center gap-2 shrink-0">
|
||||
@@ -122,14 +115,11 @@ export function Session() {
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{!stream.connected && (
|
||||
<span className="text-xs text-muted-foreground">reconnecting…</span>
|
||||
)}
|
||||
</header>
|
||||
|
||||
{id && <MessageList messages={stream.messages} sessionId={id} />}
|
||||
|
||||
<ChatInput disabled={streaming} onSend={handleSend} />
|
||||
{id && session && (
|
||||
<Workspace sessionId={id} projectId={session.project_id} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user