import { useLoginInfoQuery, useLoginStatusQuery, useStartLoginMutation } from './settings-queries.js'; function errorMessage(error: Error | null): string { return error?.message ?? 'Something went wrong.'; } function sessionLabel(status: ReturnType['data']): string { if (!status) return 'Unknown'; if (!status.ready) return 'Browser unavailable'; if ('error' in status) return 'Check failed'; return { unknown: 'Unknown', authenticated: 'Authenticated', 'login-required': 'Login required', unreachable: 'Reddit unreachable', }[status.status]; } function noVncUrl(publicUrl: string | null, port: number): string { if (publicUrl) return publicUrl; return `${window.location.protocol}//${window.location.hostname}:${port}/vnc.html?autoconnect=true&resize=scale`; } export function AccessPanel() { const infoQuery = useLoginInfoQuery(); const statusQuery = useLoginStatusQuery(); const loginMutation = useStartLoginMutation(); if (infoQuery.isPending || statusQuery.isPending) { return
Loading Reddit access…
; } if (infoQuery.isError || statusQuery.isError) { const error = infoQuery.error ?? statusQuery.error; return (
Reddit access unavailable{errorMessage(error)}
); } const info = infoQuery.data; return (
Browser session

Access

{sessionLabel(statusQuery.data)}

Open Reddit in the managed browser, complete login through noVNC, then recheck the session. Credentials are never entered or displayed here.

{info.vncEnabled ? Open noVNC login window : null}
{!info.vncEnabled ?
noVNC is not available in this deployment.
: null} {info.passwordRequired ?

A VNC password is required.

: null} {loginMutation.isSuccess ?
Login page opened.
: null} {loginMutation.isError ?
{errorMessage(loginMutation.error)}
: null}
); }