import { createMemo, createSignal, For, Show, onSettled } from "solid-js"; import { useNavigate } from "@solidjs/router"; import { createClient, ClientEvent, MatrixClient, OAuth2, SyncState, type SyncStateData, type IServerVersions, } from "matrix-js-sdk"; import { getSessions, removeSession, getActiveAccountId, setActiveAccountId, type StoredSession, matrixClient, } from "../matrix"; function keyParts(s: StoredSession): string { return `${s.homeserverUrl}/${s.userId}`; } interface WhoamiInfo { userId: string; displayName: string | null; } function Identity(props: { client: MatrixClient }) { const [whoami, setWhoami] = createSignal(null); const [tokenValid, setTokenValid] = createSignal(null); // onSettled replaces onMount in Solid 2; it's a one-shot setup that runs // once per mounted instance. onSettled(() => { void (async () => { try { const [who, profile] = await Promise.all([ props.client.whoami(), props.client.getProfileInfo(props.client.getUserId() ?? ""), ]); setWhoami({ userId: who.user_id, displayName: profile.displayname ?? null, }); setTokenValid(true); } catch { setTokenValid(false); } })(); }); return (

Identity

Status:{" "} {tokenValid() === null ? "checking…" : tokenValid() ? "token valid" : "token invalid"}

{(me) => (
user id
{me().userId}
display name
{me().displayName ?? "(none)"}
)}
); } interface SyncSnapshot { state: SyncState | null; error?: Error; } function SyncStatus(props: { client: MatrixClient }) { const [sync, setSync] = createSignal({ state: null }); onSettled(() => { // Read the reactive client state inside the settled lifecycle scope, // rather than in the component body. setSync({ state: props.client.getSyncState() }); const handler = ( state: SyncState, _prev: SyncState | null, data?: SyncStateData, ) => { setSync({ state, error: data?.error }); }; props.client.on(ClientEvent.Sync, handler); // onSettled accepts a returned cleanup when running under an owner. return () => { props.client.off(ClientEvent.Sync, handler); }; }); return (

Sync

state: {sync().state ?? "unknown"}

{(err) =>

error: {err().message}

}
); } function ServerInfo(props: { client: MatrixClient }) { const [versions, setVersions] = createSignal(null); onSettled(() => { void props.client.getVersions().then(setVersions); }); return (

Server

homeserver: {props.client.getHomeserverUrl()}

{(v) => (
latest supported version
{v().versions.at(-1) ?? "unknown"}
)}
); } export default function Status() { const navigate = useNavigate(); const client = createMemo(() => matrixClient()); const sessions = () => getSessions(); const activeId = () => getActiveAccountId(); const logout = (session: StoredSession) => { void (async () => { try { const metadata = await createClient({ baseUrl: session.homeserverUrl, }).getAuthMetadata(); const oauth = new OAuth2(metadata, { clientId: session.clientId, redirectUri: "urn:ietf:oauth:2.0:oob", }); const token = session.accessToken ?? session.refreshToken; if (token) await oauth.revokeToken( token, session.accessToken ? "access_token" : "refresh_token", ); } catch { /* still drop locally if revocation fails */ } removeSession(session); if (getActiveAccountId() === null) navigate("/auth/login"); window.location.reload(); })(); }; const switchSession = (e: Event & { currentTarget: HTMLSelectElement }) => { setActiveAccountId(e.currentTarget.value || null); window.location.reload(); }; return (

Client status

You aren't signed in.

Go to login

} > {(getClient) => ( <>

Active account

[+] Add account

All sessions

    {(s) => (
  • {s.userId} on {s.homeserverUrl} (device {s.deviceId}){" "}
  • )}
)} ); }