Skip to content

Commit

Permalink
server_form: Added autocomplete function to url.
Browse files Browse the repository at this point in the history
Autocompletes when the user passes only org url,
in the server url input.

Fixes zulip#1012
  • Loading branch information
aryanshridhar authored and manila committed May 6, 2022
1 parent 588d32f commit 71c69f5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion 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 @@ -78,6 +80,17 @@ export function initNewServerForm({$root, onChange}: NewServerFormProps): void {
onChange();
}

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";
}

return serverUrl;
}

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

0 comments on commit 71c69f5

Please sign in to comment.