Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/components/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type ConnectState = {
isLoading: boolean;
modal: boolean;
showSettings: boolean;
deviceID: string;
password: string;
};

class Connect extends React.Component<ConnectProps, ConnectState> {
Expand All @@ -35,6 +37,8 @@ class Connect extends React.Component<ConnectProps, ConnectState> {
isLoading: false,
modal: false,
showSettings: false,
deviceID: "",
password: "",
};
this.handleCancel = this.handleCancel.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
Expand All @@ -50,13 +54,17 @@ class Connect extends React.Component<ConnectProps, ConnectState> {
}
this.setState({ isLoading: false });

// Pre-populate input fields with stored credentials if available
const keyringData = this.getKeyringDataFromURL();
if (keyringData) {
this.submit(keyringData.deviceID, keyringData.password);
this.setState({
deviceID: keyringData.deviceID,
password: keyringData.password
});
} else {
const { deviceID, password } = localStorage.getLogin();
if (deviceID && password) {
this.submit(deviceID, password);
this.setState({ deviceID, password });
}
}
}
Expand Down Expand Up @@ -89,13 +97,7 @@ class Connect extends React.Component<ConnectProps, ConnectState> {
}

handleSubmit() {
const deviceID = (
document.getElementById("deviceIdInput") as HTMLInputElement
).value;
const password = (
document.getElementById("passwordInput") as HTMLInputElement
).value;
this.submit(deviceID, password);
this.submit(this.state.deviceID, this.state.password);
}

handleCancel() {
Expand Down Expand Up @@ -156,6 +158,8 @@ class Connect extends React.Component<ConnectProps, ConnectState> {
<Input
placeholder="DeviceID"
id="deviceIdInput"
value={this.state.deviceID}
onChange={(e) => this.setState({ deviceID: e.target.value })}
ref={(i) => {
//@ts-expect-error
this.input = i;
Expand All @@ -167,6 +171,8 @@ class Connect extends React.Component<ConnectProps, ConnectState> {
<Input.Password
placeholder="Password (create for new logins)"
id="passwordInput"
value={this.state.password}
onChange={(e) => this.setState({ password: e.target.value })}
onPressEnter={this.handleSubmit}
style={{ margin: "20px 0 0 0", width: "70%" }}
/>
Expand Down