Skip to content

Commit

Permalink
new_server_form: Add URL autocomplete to new server form
Browse files Browse the repository at this point in the history
  • Loading branch information
manila committed May 6, 2022
1 parent a9cf2cc commit 609ee96
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions app/renderer/js/pages/preference/new-server-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export function initNewServerForm({$root, onChange}: NewServerFormProps): void {
$saveServerButton.textContent = "Connecting...";
let serverConf;
try {
serverConf = await DomainUtil.checkDomain($newServerUrl.value.trim());
serverConf = await DomainUtil.checkDomain(
await autoComplete($newServerUrl.value.trim()),
);
} catch (error: unknown) {
$saveServerButton.textContent = "Connect";
await dialog.showMessageBox({
Expand All @@ -73,20 +75,21 @@ export function initNewServerForm({$root, onChange}: NewServerFormProps): void {
});
return;
}

await DomainUtil.addDomain(serverConf);
onChange();
}

autoComplete(url: string): string {
const pattern = /^[a-zA-Z\d-]*$/;
let serverUrl = url.trim();
async function autoComplete(url: string): Promise<string> {
const pattern = /^[a-zA-Z\d-]*$/;
let serverUrl = url.trim();

if (pattern.test(serverUrl)) {
serverUrl = 'https://' + serverUrl + '.zulipchat.com';
}
if (pattern.test(serverUrl)) {
serverUrl = "https://" + serverUrl + ".zulipchat.com";
}

return serverUrl;
}
return serverUrl;
}

$saveServerButton.addEventListener("click", async () => {
await submitFormHandler();
Expand Down

0 comments on commit 609ee96

Please sign in to comment.