Mark the session on screen as Current in the session lists
- The conversation page tells the rail and the sessions modal which session it shows (announceShownSession, useShownSession); they reload, so a session reopened by ?session_id= shows at once. - Only that session is Current and greyed out (the active one without ?session_id=); the active row then leads back to it. - The rail lists the session on screen even when it's older than its latest sessions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -15,6 +15,11 @@ type Params = {
|
||||
* How many to load, latest first; the modal leaves it out for a page.
|
||||
*/
|
||||
limit?: number;
|
||||
/**
|
||||
* Reloads the list whenever it changes (the session the page shows,
|
||||
* which loading it may have reopened).
|
||||
*/
|
||||
refresh_key?: string | number | null;
|
||||
};
|
||||
|
||||
type ChangedSession = {
|
||||
@@ -51,7 +56,7 @@ function belongsToConversation({
|
||||
* session started in the conversation (or named once its first reply is
|
||||
* in) shows without a reload.
|
||||
*/
|
||||
export default function useBotSessions({ bot_id, workspace_id, open, limit }: Params) {
|
||||
export default function useBotSessions({ bot_id, workspace_id, open, limit, refresh_key }: Params) {
|
||||
const [query, setQuery] = useState("");
|
||||
const [sessions, setSessions] = useState<BotSessionListItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -111,7 +116,7 @@ export default function useBotSessions({ bot_id, workspace_id, open, limit }: Pa
|
||||
stale = true;
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [open, query, bot_id, workspace_id, limit, revision]);
|
||||
}, [open, query, bot_id, workspace_id, limit, revision, refresh_key]);
|
||||
|
||||
const act = async ({ id, path, body }: { id: number | "new"; path: "new-session" | "reopen-session"; body: Record<string, unknown> }) => {
|
||||
if (busy_id) return;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { lastShownSession, ShownSessionEvent } from "@/src/functions/frontend/announce-shown-session";
|
||||
import type { ShownSession } from "@/src/types";
|
||||
|
||||
type Params = {
|
||||
bot_id: number;
|
||||
workspace_id?: number | null;
|
||||
};
|
||||
|
||||
function isFor({ shown, bot_id, workspace_id }: Params & { shown: ShownSession | null }) {
|
||||
return Boolean(
|
||||
shown && shown.bot_id == bot_id && (shown.workspace_id || null) == (workspace_id || null),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The session the conversation page shows, when it's this conversation's
|
||||
* (`announceShownSession`): a session opened by `?session_id=`, a
|
||||
* reopened one or the active one.
|
||||
*/
|
||||
export default function useShownSession({ bot_id, workspace_id }: Params) {
|
||||
const [shown, setShown] = useState<ShownSession | null>(() =>
|
||||
isFor({ shown: lastShownSession, bot_id, workspace_id }) ? lastShownSession : null,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const listener = (e: Event) => {
|
||||
const detail = (e as CustomEvent<ShownSession>).detail;
|
||||
|
||||
if (isFor({ shown: detail, bot_id, workspace_id })) setShown(detail);
|
||||
};
|
||||
|
||||
window.addEventListener(ShownSessionEvent, listener);
|
||||
return () => window.removeEventListener(ShownSessionEvent, listener);
|
||||
}, [bot_id, workspace_id]);
|
||||
|
||||
return shown?.session || null;
|
||||
}
|
||||
Reference in New Issue
Block a user