incognitolm commited on
Commit
a5154d0
·
verified ·
1 Parent(s): 405d05f

Update public/js/app.js

Browse files
Files changed (1) hide show
  1. public/js/app.js +5 -2
public/js/app.js CHANGED
@@ -41,6 +41,9 @@ onSessionChange((event, data) => {
41
  if (data.id === currentSessionId) renderSession(data);
42
  }
43
  if (event === 'created') {
 
 
 
44
  switchSession(data.id);
45
  if (window.innerWidth < 768) collapseSidebar();
46
  }
@@ -69,10 +72,10 @@ function triggerCenterSend() {
69
  clearFilePreviewRow();
70
 
71
  if (!currentSessionId) {
72
- // Create session first, then send
73
  const pendingText = text, pendingAttach = attachments;
74
  const unsub = onSessionChange((ev, s) => {
75
- if (ev !== 'created') return;
76
  unsub();
77
  doSend(pendingText, pendingAttach);
78
  });
 
41
  if (data.id === currentSessionId) renderSession(data);
42
  }
43
  if (event === 'created') {
44
+ // Set activeSession immediately before switchSession so any pending
45
+ // send (from triggerCenterSend) uses the correct session id.
46
+ setActiveSession(data.id);
47
  switchSession(data.id);
48
  if (window.innerWidth < 768) collapseSidebar();
49
  }
 
72
  clearFilePreviewRow();
73
 
74
  if (!currentSessionId) {
75
+ // Create session first, then send after both 'created' AND 'switched' have fired
76
  const pendingText = text, pendingAttach = attachments;
77
  const unsub = onSessionChange((ev, s) => {
78
+ if (ev !== 'switched' || !s) return; // wait for switched (which sets activeSessionId)
79
  unsub();
80
  doSend(pendingText, pendingAttach);
81
  });