web: give chat details a real back route

Opening a chat now pushes /chat/:id, so Android/browser Back returns to the
chat list rather than the previous destination. The conversation header owns a
compact Back to chats control matching the create pane, replacing the
full-width Back to list row on phones.
This commit is contained in:
2026-10-20 03:25:31 +01:00
parent 526c19fc21
commit c291327610
6 changed files with 90 additions and 10 deletions
+34 -6
View File
@@ -1004,9 +1004,9 @@ function closeDetail(view) {
? { root: ".list.runs", attribute: "data-run-id", value: String(state.selectedRunId) }
: null;
if (view === "chat") {
state.chatActiveId = null;
state.chatCreate = null;
renderContent();
const route = { kind: "chat" };
pushRoute(route);
applyRoute(route);
restoreListFocus(restore);
return;
}
@@ -1204,7 +1204,9 @@ function renderContent() {
// The transcript, not the pane, is chat's one scroller, so its detail body
// is not wrapped in a second pane-scroll.
const pane = h("section", { class: "detail-pane", "aria-label": "Chat detail" });
if (detailOpen) pane.append(backControl(view));
// The conversation and create panes each put their own compact Back control
// in the chat bar; the generic full-width pane-back row is for the other
// detail panes, which have no header of their own.
pane.append(state.chatCreate ? renderChatCreate() : renderChatConversation());
layout.append(pane);
}
@@ -1458,6 +1460,8 @@ function viewForRoute(route) {
return "runs";
case "template":
return "templates";
case "chatSession":
return "chat";
case "runs":
case "chat":
case "settings":
@@ -1674,9 +1678,32 @@ async function applyRoute(route) {
return;
}
if (r.kind === "chat") {
renderContent();
if (r.kind === "chat" || r.kind === "chatSession") {
state.view = "chat";
if (!state.chatLoaded) await loadCurrentView();
if (r.kind === "chat") {
state.chatActiveId = null;
state.chatCreate = null;
renderContent();
return;
}
// A chat detail is a real history entry: opening one pushes /chat/:id, so
// Back (including Android's back gesture) returns to the chat list rather
// than the previous destination. An id the server no longer lists falls
// back to the list instead of leaving a dead pane.
const known =
state.chatThreads.has(r.id) || state.chatSessions.some((session) => session.id === r.id);
if (!connected() || !known) {
state.chatActiveId = null;
if (`${location.pathname}${location.search}` !== "/chat") {
replaceRoute({ kind: "chat" });
}
renderContent();
return;
}
state.chatActiveId = r.id;
renderContent();
await openChatSession(r.id, { updateRoute: false });
return;
}
@@ -2318,6 +2345,7 @@ const runtime = {
setServerUrlDraft,
pushRoute,
applyRoute,
closeDetail,
openConfiguredEndpoint,
onReconnectClicked,
selectPipeline,