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:
+34
-6
@@ -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,
|
||||
|
||||
+20
-2
@@ -12,7 +12,8 @@
|
||||
// /runs Runs list
|
||||
// /runs/:id run detail (optional ?action=decide)
|
||||
// /runs/:id/stage/:key[?visit=N] one visit's stage pane
|
||||
// /chat Chat
|
||||
// /chat Chat list
|
||||
// /chat/:id one chat session
|
||||
// /templates template gallery
|
||||
// /templates/:key template detail
|
||||
// /settings Settings
|
||||
@@ -47,6 +48,12 @@ function parseId(value) {
|
||||
}
|
||||
|
||||
/** A non-negative safe integer (a pipeline version; 0 means latest), or null. */
|
||||
/** A chat session id segment: nonempty, bounded, URL-safe. */
|
||||
function parseChatId(value) {
|
||||
const id = String(value ?? "");
|
||||
return id !== "" && id.length <= 200 && /^[A-Za-z0-9_-]+$/.test(id) ? id : null;
|
||||
}
|
||||
|
||||
function parseVersion(value) {
|
||||
if (!ID_PATTERN.test(value)) return null;
|
||||
const version = Number(value);
|
||||
@@ -131,7 +138,14 @@ export function parseRoute(pathname, search = "") {
|
||||
|
||||
if (head === "pipelines" && second == null) return { kind: "pipelines" };
|
||||
if (head === "runs" && second == null) return { kind: "runs" };
|
||||
if (head === "chat" && second == null) return { kind: "chat" };
|
||||
if (head === "chat") {
|
||||
if (second == null) return { kind: "chat" };
|
||||
if (third == null) {
|
||||
const id = parseChatId(second);
|
||||
return id == null ? { ...DEFAULT_ROUTE } : { kind: "chatSession", id };
|
||||
}
|
||||
return { ...DEFAULT_ROUTE };
|
||||
}
|
||||
if (head === "settings" && second == null) return { kind: "settings" };
|
||||
if (head === "templates") {
|
||||
if (second == null) return { kind: "templates" };
|
||||
@@ -230,6 +244,10 @@ export function serializeRoute(route) {
|
||||
return "/runs";
|
||||
case "chat":
|
||||
return "/chat";
|
||||
case "chatSession": {
|
||||
const id = parseChatId(r.id);
|
||||
return id == null ? "/chat" : `/chat/${encode(id)}`;
|
||||
}
|
||||
case "settings":
|
||||
return "/settings";
|
||||
case "templates":
|
||||
|
||||
+23
-2
@@ -256,6 +256,7 @@ export function createChatView(rt) {
|
||||
let chatNow = Date.now();
|
||||
const renderContent = (...args) => rt.renderContent(...args);
|
||||
const focusDetailHeading = (...args) => rt.focusDetailHeading(...args);
|
||||
const closeDetail = (...args) => rt.closeDetail?.(...args);
|
||||
const renderActionFailedDialog = (...args) => rt.views.dialogs.renderActionFailedDialog(...args);
|
||||
|
||||
/** Remember one conversation's scroll position (index of the first visible row). */
|
||||
@@ -491,7 +492,9 @@ async function createNewChat() {
|
||||
}
|
||||
|
||||
/** Open a session: select it, subscribe its stream and load its newest history page. */
|
||||
async function openChatSession(id) {
|
||||
async function openChatSession(id, { updateRoute = true } = {}) {
|
||||
if (updateRoute) rt.pushRoute({ kind: "chatSession", id });
|
||||
state.view = "chat";
|
||||
if (state.chatActiveId === id && state.chatThreads.get(id)?.loaded) return;
|
||||
// Remember where the operator left the conversation being closed.
|
||||
const leaving = document.getElementById("chatTranscript");
|
||||
@@ -1954,11 +1957,29 @@ function renderChatConversation() {
|
||||
const awaiting = approval?.actionable === true || form != null;
|
||||
|
||||
const bar = h("div", { class: "chat-bar" });
|
||||
const lead = h("div", { class: "chat-bar-lead" });
|
||||
// A compact back control in the conversation header, matching the create
|
||||
// pane's own. The narrow layout is where the list is covered; on wide screens
|
||||
// the list is still visible, so CSS hides it there.
|
||||
lead.append(
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: "ghost chat-create-back chat-back",
|
||||
type: "button",
|
||||
"aria-label": "Back to chats",
|
||||
title: "Back to chats",
|
||||
onclick: () => closeDetail("chat"),
|
||||
},
|
||||
h("span", { class: "chat-create-back-glyph", "aria-hidden": "true", text: "←" }),
|
||||
),
|
||||
);
|
||||
const titles = h("div", { class: "chat-bar-titles" });
|
||||
// The open conversation is the route's one h1; the list heading above becomes
|
||||
// its h2 while the detail is open.
|
||||
titles.append(h("h1", { class: "chat-bar-title", id: "detailTitle", tabindex: "-1", text: title }));
|
||||
bar.append(titles);
|
||||
lead.append(titles);
|
||||
bar.append(lead);
|
||||
if (thread?.hasMore) {
|
||||
bar.append(
|
||||
h("button", {
|
||||
|
||||
Reference in New Issue
Block a user