Fix default homeserver value

This commit is contained in:
Robert Long 2021-10-14 11:53:21 -07:00
parent 85f42cc2d0
commit d5a1952dfb

View file

@ -21,7 +21,9 @@ import { FieldRow, InputField, Button, ErrorMessage } from "./Input";
import { Center, Content, Info, Modal } from "./Layout"; import { Center, Content, Info, Modal } from "./Layout";
export function LoginPage({ onLogin }) { export function LoginPage({ onLogin }) {
const homeserverRef = useRef(); const [homeserver, setHomeServer] = useState(
`${window.location.protocol}//${window.location.host}`
);
const usernameRef = useRef(); const usernameRef = useRef();
const passwordRef = useRef(); const passwordRef = useRef();
const history = useHistory(); const history = useHistory();
@ -31,11 +33,7 @@ export function LoginPage({ onLogin }) {
const onSubmitLoginForm = useCallback( const onSubmitLoginForm = useCallback(
(e) => { (e) => {
e.preventDefault(); e.preventDefault();
onLogin( onLogin(homeserver, usernameRef.current.value, passwordRef.current.value)
homeserverRef.current.value,
usernameRef.current.value,
passwordRef.current.value
)
.then(() => { .then(() => {
if (location.state && location.state.from) { if (location.state && location.state.from) {
history.replace(location.state.from); history.replace(location.state.from);
@ -45,7 +43,7 @@ export function LoginPage({ onLogin }) {
}) })
.catch(setError); .catch(setError);
}, },
[onLogin, location, history] [onLogin, location, history, homeserver]
); );
return ( return (
@ -61,8 +59,8 @@ export function LoginPage({ onLogin }) {
<FieldRow> <FieldRow>
<InputField <InputField
type="text" type="text"
ref={homeserverRef} value={homeserver}
value={`${window.location.protocol}//${window.location.host}`} onChange={(e) => setHomeServer(e.target.value)}
placeholder="Homeserver" placeholder="Homeserver"
label="Homeserver" label="Homeserver"
autoCorrect="off" autoCorrect="off"