import { createResource, createSignal, For, Show } from "solid-js"; import { api, type TokenInfo } from "./api"; import { ago } from "./live"; import { useSession } from "./session"; /** * The only place individual phones are visible. * * Positions belong to the account, so a token is a credential and nothing else. * Listing them with last-seen is what makes a forgotten phone in a drawer — the * one that drags the live marker back and forth — visible and revocable. */ export default function Settings() { const me = useSession().me; const [tokens, { refetch }] = createResource(() => api.tokens()); const [message, setMessage] = createSignal(null); const now = Math.floor(Date.now() / 1000); async function revoke(t: TokenInfo) { if (!confirm(`Revoke "${t.name}"? That phone has to log in again.`)) return; await api.revokeToken(t.token_id); void refetch(); } async function revokeOthers() { if (!confirm("Revoke every device token on this account?")) return; const { revoked } = await api.revokeOthers(); setMessage(`${revoked} token(s) revoked`); void refetch(); } return (

account

{me.display_name} ({me.username}){me.is_admin ? " · admin" : ""}

devices

{(m) =>

{m()}

}
no devices logged in

}> {(t) => (
{t.name} {t.platform}
{t.last_seen_at ? `seen ${ago(t.last_seen_at, now)} ago` : "never seen"} {t.last_src_ip ? ` · ${t.last_src_ip}` : ""} {t.last_transport ? ` · ${t.last_transport}` : ""} {t.os_api_level ? ` · API ${t.os_api_level}` : ""}
)}
); } function PasswordForm() { const [current, setCurrent] = createSignal(""); const [next, setNext] = createSignal(""); const [status, setStatus] = createSignal(null); async function submit(e: Event) { e.preventDefault(); try { await api.changePassword(current(), next()); // Changing the password revokes every device token, by design. setStatus("changed — every device must log in again"); setCurrent(""); setNext(""); } catch (e) { setStatus(e instanceof Error ? e.message : String(e)); } } return (
setCurrent(e.currentTarget.value)} /> setNext(e.currentTarget.value)} /> {(s) =>

{s()}

}
); }