* fix: adding confirmation modal to confirm gateway url change * refactor: added modal instead of confirm prompt * fix(ui): reconnect after confirming gateway url (#2880) (thanks @0xacb) --------- Co-authored-by: 0xacb <amccbaptista@gmail.com>
This commit is contained in:
parent
109ac1c549
commit
a7534dc223
5 changed files with 62 additions and 1 deletions
|
|
@ -42,6 +42,7 @@ import { renderNodes } from "./views/nodes";
|
||||||
import { renderOverview } from "./views/overview";
|
import { renderOverview } from "./views/overview";
|
||||||
import { renderSessions } from "./views/sessions";
|
import { renderSessions } from "./views/sessions";
|
||||||
import { renderExecApprovalPrompt } from "./views/exec-approval";
|
import { renderExecApprovalPrompt } from "./views/exec-approval";
|
||||||
|
import { renderGatewayUrlConfirmation } from "./views/gateway-url-confirmation";
|
||||||
import {
|
import {
|
||||||
approveDevicePairing,
|
approveDevicePairing,
|
||||||
loadDevices,
|
loadDevices,
|
||||||
|
|
@ -578,6 +579,7 @@ export function renderApp(state: AppViewState) {
|
||||||
: nothing}
|
: nothing}
|
||||||
</main>
|
</main>
|
||||||
${renderExecApprovalPrompt(state)}
|
${renderExecApprovalPrompt(state)}
|
||||||
|
${renderGatewayUrlConfirmation(state)}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ type SettingsHost = {
|
||||||
basePath: string;
|
basePath: string;
|
||||||
themeMedia: MediaQueryList | null;
|
themeMedia: MediaQueryList | null;
|
||||||
themeMediaHandler: ((event: MediaQueryListEvent) => void) | null;
|
themeMediaHandler: ((event: MediaQueryListEvent) => void) | null;
|
||||||
|
pendingGatewayUrl?: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function applySettings(host: SettingsHost, next: UiSettings) {
|
export function applySettings(host: SettingsHost, next: UiSettings) {
|
||||||
|
|
@ -98,7 +99,7 @@ export function applySettingsFromUrl(host: SettingsHost) {
|
||||||
if (gatewayUrlRaw != null) {
|
if (gatewayUrlRaw != null) {
|
||||||
const gatewayUrl = gatewayUrlRaw.trim();
|
const gatewayUrl = gatewayUrlRaw.trim();
|
||||||
if (gatewayUrl && gatewayUrl !== host.settings.gatewayUrl) {
|
if (gatewayUrl && gatewayUrl !== host.settings.gatewayUrl) {
|
||||||
applySettings(host, { ...host.settings, gatewayUrl });
|
host.pendingGatewayUrl = gatewayUrl;
|
||||||
}
|
}
|
||||||
params.delete("gatewayUrl");
|
params.delete("gatewayUrl");
|
||||||
shouldCleanUrl = true;
|
shouldCleanUrl = true;
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ export type AppViewState = {
|
||||||
execApprovalQueue: ExecApprovalRequest[];
|
execApprovalQueue: ExecApprovalRequest[];
|
||||||
execApprovalBusy: boolean;
|
execApprovalBusy: boolean;
|
||||||
execApprovalError: string | null;
|
execApprovalError: string | null;
|
||||||
|
pendingGatewayUrl: string | null;
|
||||||
configLoading: boolean;
|
configLoading: boolean;
|
||||||
configRaw: string;
|
configRaw: string;
|
||||||
configRawOriginal: string;
|
configRawOriginal: string;
|
||||||
|
|
@ -165,6 +166,8 @@ export type AppViewState = {
|
||||||
handleNostrProfileImport: () => Promise<void>;
|
handleNostrProfileImport: () => Promise<void>;
|
||||||
handleNostrProfileToggleAdvanced: () => void;
|
handleNostrProfileToggleAdvanced: () => void;
|
||||||
handleExecApprovalDecision: (decision: "allow-once" | "allow-always" | "deny") => Promise<void>;
|
handleExecApprovalDecision: (decision: "allow-once" | "allow-always" | "deny") => Promise<void>;
|
||||||
|
handleGatewayUrlConfirm: () => void;
|
||||||
|
handleGatewayUrlCancel: () => void;
|
||||||
handleConfigLoad: () => Promise<void>;
|
handleConfigLoad: () => Promise<void>;
|
||||||
handleConfigSave: () => Promise<void>;
|
handleConfigSave: () => Promise<void>;
|
||||||
handleConfigApply: () => Promise<void>;
|
handleConfigApply: () => Promise<void>;
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,7 @@ export class MoltbotApp extends LitElement {
|
||||||
@state() execApprovalQueue: ExecApprovalRequest[] = [];
|
@state() execApprovalQueue: ExecApprovalRequest[] = [];
|
||||||
@state() execApprovalBusy = false;
|
@state() execApprovalBusy = false;
|
||||||
@state() execApprovalError: string | null = null;
|
@state() execApprovalError: string | null = null;
|
||||||
|
@state() pendingGatewayUrl: string | null = null;
|
||||||
|
|
||||||
@state() configLoading = false;
|
@state() configLoading = false;
|
||||||
@state() configRaw = "{\n}\n";
|
@state() configRaw = "{\n}\n";
|
||||||
|
|
@ -448,6 +449,21 @@ export class MoltbotApp extends LitElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleGatewayUrlConfirm() {
|
||||||
|
const nextGatewayUrl = this.pendingGatewayUrl;
|
||||||
|
if (!nextGatewayUrl) return;
|
||||||
|
this.pendingGatewayUrl = null;
|
||||||
|
applySettingsInternal(
|
||||||
|
this as unknown as Parameters<typeof applySettingsInternal>[0],
|
||||||
|
{ ...this.settings, gatewayUrl: nextGatewayUrl },
|
||||||
|
);
|
||||||
|
this.connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGatewayUrlCancel() {
|
||||||
|
this.pendingGatewayUrl = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Sidebar handlers for tool output viewing
|
// Sidebar handlers for tool output viewing
|
||||||
handleOpenSidebar(content: string) {
|
handleOpenSidebar(content: string) {
|
||||||
if (this.sidebarCloseTimer != null) {
|
if (this.sidebarCloseTimer != null) {
|
||||||
|
|
|
||||||
39
ui/src/ui/views/gateway-url-confirmation.ts
Normal file
39
ui/src/ui/views/gateway-url-confirmation.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
import { html, nothing } from "lit";
|
||||||
|
|
||||||
|
import type { AppViewState } from "../app-view-state";
|
||||||
|
|
||||||
|
export function renderGatewayUrlConfirmation(state: AppViewState) {
|
||||||
|
const { pendingGatewayUrl } = state;
|
||||||
|
if (!pendingGatewayUrl) return nothing;
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<div class="exec-approval-overlay" role="dialog" aria-modal="true" aria-live="polite">
|
||||||
|
<div class="exec-approval-card">
|
||||||
|
<div class="exec-approval-header">
|
||||||
|
<div>
|
||||||
|
<div class="exec-approval-title">Change Gateway URL</div>
|
||||||
|
<div class="exec-approval-sub">This will reconnect to a different gateway server</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="exec-approval-command mono">${pendingGatewayUrl}</div>
|
||||||
|
<div class="callout danger" style="margin-top: 12px;">
|
||||||
|
Only confirm if you trust this URL. Malicious URLs can compromise your system.
|
||||||
|
</div>
|
||||||
|
<div class="exec-approval-actions">
|
||||||
|
<button
|
||||||
|
class="btn primary"
|
||||||
|
@click=${() => state.handleGatewayUrlConfirm()}
|
||||||
|
>
|
||||||
|
Confirm
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="btn"
|
||||||
|
@click=${() => state.handleGatewayUrlCancel()}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue