// gomuks - A Matrix client written in Go. // Copyright (C) 2024 Tulir Asokan // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . import React, { useCallback, useEffect, useState } from "react" import type Client from "../../api/client.ts" import "./LoginScreen.css" import { ClientState } from "../../api/types/hievents.ts" export interface LoginScreenProps { client: Client clientState: ClientState } export const LoginScreen = ({ client }: LoginScreenProps) => { const [username, setUsername] = useState("") const [password, setPassword] = useState("") const [homeserverURL, setHomeserverURL] = useState("") const [error, setError] = useState("") const login = useCallback((evt: React.FormEvent) => { evt.preventDefault() client.login(homeserverURL, username, password).then( () => {}, err => setError(err.toString()), ) }, [homeserverURL, username, password, client]) const resolveHomeserver = useCallback(() => { client.discoverHomeserver(username).then( resp => setHomeserverURL(resp["m.homeserver"].base_url), err => setError(`Failed to resolve homeserver: ${err}`), ) }, [client, username]) useEffect(() => { if (!username.startsWith("@") || !username.includes(":") || !username.includes(".")) { return } const timeout = setTimeout(resolveHomeserver, 500) return () => { clearTimeout(timeout) } }, [username, resolveHomeserver]) return

gomuks web

setUsername(evt.target.value)} /> setPassword(evt.target.value)} /> setHomeserverURL(evt.target.value)} />
{error &&
{error}
}
}