refactor(ui): enhance loadSessions function to accept overrides for session loading parameters
- Updated loadSessions to include optional parameters for activeMinutes, limit, includeGlobal, and includeUnknown. - Modified refreshChat to use the new activeMinutes parameter when loading sessions. - Removed duplicate applySettingsFromUrl call in handleConnected function.
This commit is contained in:
parent
a7534dc223
commit
647e393ee5
@ -155,7 +155,7 @@ export async function handleSendChat(
|
|||||||
export async function refreshChat(host: ChatHost) {
|
export async function refreshChat(host: ChatHost) {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
loadChatHistory(host as unknown as MoltbotApp),
|
loadChatHistory(host as unknown as MoltbotApp),
|
||||||
loadSessions(host as unknown as MoltbotApp),
|
loadSessions(host as unknown as MoltbotApp, { activeMinutes: 10 }),
|
||||||
refreshChatAvatar(host),
|
refreshChatAvatar(host),
|
||||||
]);
|
]);
|
||||||
scheduleChatScroll(host as unknown as Parameters<typeof scheduleChatScroll>[0], true);
|
scheduleChatScroll(host as unknown as Parameters<typeof scheduleChatScroll>[0], true);
|
||||||
|
|||||||
@ -35,6 +35,9 @@ type LifecycleHost = {
|
|||||||
|
|
||||||
export function handleConnected(host: LifecycleHost) {
|
export function handleConnected(host: LifecycleHost) {
|
||||||
host.basePath = inferBasePath();
|
host.basePath = inferBasePath();
|
||||||
|
applySettingsFromUrl(
|
||||||
|
host as unknown as Parameters<typeof applySettingsFromUrl>[0],
|
||||||
|
);
|
||||||
syncTabWithLocation(
|
syncTabWithLocation(
|
||||||
host as unknown as Parameters<typeof syncTabWithLocation>[0],
|
host as unknown as Parameters<typeof syncTabWithLocation>[0],
|
||||||
true,
|
true,
|
||||||
@ -46,9 +49,6 @@ export function handleConnected(host: LifecycleHost) {
|
|||||||
host as unknown as Parameters<typeof attachThemeListener>[0],
|
host as unknown as Parameters<typeof attachThemeListener>[0],
|
||||||
);
|
);
|
||||||
window.addEventListener("popstate", host.popStateHandler);
|
window.addEventListener("popstate", host.popStateHandler);
|
||||||
applySettingsFromUrl(
|
|
||||||
host as unknown as Parameters<typeof applySettingsFromUrl>[0],
|
|
||||||
);
|
|
||||||
connectGateway(host as unknown as Parameters<typeof connectGateway>[0]);
|
connectGateway(host as unknown as Parameters<typeof connectGateway>[0]);
|
||||||
startNodesPolling(host as unknown as Parameters<typeof startNodesPolling>[0]);
|
startNodesPolling(host as unknown as Parameters<typeof startNodesPolling>[0]);
|
||||||
if (host.tab === "logs") {
|
if (host.tab === "logs") {
|
||||||
|
|||||||
@ -14,18 +14,29 @@ export type SessionsState = {
|
|||||||
sessionsIncludeUnknown: boolean;
|
sessionsIncludeUnknown: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function loadSessions(state: SessionsState) {
|
export async function loadSessions(
|
||||||
|
state: SessionsState,
|
||||||
|
overrides?: {
|
||||||
|
activeMinutes?: number;
|
||||||
|
limit?: number;
|
||||||
|
includeGlobal?: boolean;
|
||||||
|
includeUnknown?: boolean;
|
||||||
|
},
|
||||||
|
) {
|
||||||
if (!state.client || !state.connected) return;
|
if (!state.client || !state.connected) return;
|
||||||
if (state.sessionsLoading) return;
|
if (state.sessionsLoading) return;
|
||||||
state.sessionsLoading = true;
|
state.sessionsLoading = true;
|
||||||
state.sessionsError = null;
|
state.sessionsError = null;
|
||||||
try {
|
try {
|
||||||
|
const includeGlobal = overrides?.includeGlobal ?? state.sessionsIncludeGlobal;
|
||||||
|
const includeUnknown = overrides?.includeUnknown ?? state.sessionsIncludeUnknown;
|
||||||
|
const activeMinutes =
|
||||||
|
overrides?.activeMinutes ?? toNumber(state.sessionsFilterActive, 0);
|
||||||
|
const limit = overrides?.limit ?? toNumber(state.sessionsFilterLimit, 0);
|
||||||
const params: Record<string, unknown> = {
|
const params: Record<string, unknown> = {
|
||||||
includeGlobal: state.sessionsIncludeGlobal,
|
includeGlobal,
|
||||||
includeUnknown: state.sessionsIncludeUnknown,
|
includeUnknown,
|
||||||
};
|
};
|
||||||
const activeMinutes = toNumber(state.sessionsFilterActive, 0);
|
|
||||||
const limit = toNumber(state.sessionsFilterLimit, 0);
|
|
||||||
if (activeMinutes > 0) params.activeMinutes = activeMinutes;
|
if (activeMinutes > 0) params.activeMinutes = activeMinutes;
|
||||||
if (limit > 0) params.limit = limit;
|
if (limit > 0) params.limit = limit;
|
||||||
const res = (await state.client.request("sessions.list", params)) as
|
const res = (await state.client.request("sessions.list", params)) as
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user