Skip to content

Commit e051aae

Browse files
enowdevenowdev
authored andcommitted
fix(chat): sync project selection with active session
1 parent 1f08282 commit e051aae

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/components/layout/AppShell.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,17 @@ export const AppShell: React.FC = () => {
416416
let currentSessionId = useSessionStore.getState().activeSessionId;
417417
let currentProjectId = useProjectStore.getState().activeProjectId;
418418
const currentProjects = useProjectStore.getState().projects;
419+
const currentSessions = useSessionStore.getState().sessions;
419420

420-
// If we already have an active session, just return it
421421
if (currentSessionId) {
422-
const proj = currentProjects.find(p => p.id === currentProjectId);
422+
const activeSession = currentSessions.find((session) => session.id === currentSessionId);
423+
const sessionProjectId = activeSession?.projectId ?? currentProjectId;
424+
const proj = currentProjects.find((project) => project.id === sessionProjectId);
425+
426+
if (sessionProjectId && sessionProjectId !== currentProjectId) {
427+
setActiveProjectId(sessionProjectId);
428+
}
429+
423430
return { sessionId: currentSessionId, projectPath: proj?.path ?? '' };
424431
}
425432

src/components/sidebar/SessionList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Session } from '@/types';
1212

1313
export const SessionList: React.FC = () => {
1414
const { sessions, activeSessionId, setActiveSessionId, removeSession, addSession, setSessions } = useSessionStore();
15-
const { projects, activeProjectId } = useProjectStore();
15+
const { projects, activeProjectId, setActiveProjectId } = useProjectStore();
1616
const [expandedProjects, setExpandedProjects] = useState<Set<string>>(() => {
1717
return new Set(activeProjectId ? [activeProjectId] : []);
1818
});

0 commit comments

Comments
 (0)