Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autocomplete url #1204

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
31 changes: 30 additions & 1 deletion app/renderer/css/preference.css
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,43 @@ img.server-info-icon {
max-width: 450px;
}

.setting-input-value:focus {
.setting-input-value:focus,
label.setting-input-value:focus-within {
border: rgb(78 191 172 / 100%) 2px solid;
}

.invalid-input-value:focus {
border: rgb(239 83 80 / 100%) 2px solid;
}

.setting-input-add-server,
.add-server-domain,
.server-url-size-calc {
outline: 0;
margin: 0;
padding: 0;
border: 0;
float: left;
font-family: inherit;
font-size: inherit;
line-height: inherit;
color: rgb(34 44 49 / 100%);
background: inherit;
}

.setting-input-add-server {
width: 34ch;
}

.setting-input-add-server:focus + .add-server-domain {
color: inherit;
}

.server-url-size-calc {
visibility: hidden;
height: 0;
}

.manual-proxy-block {
width: 96%;
}
Expand Down
48 changes: 41 additions & 7 deletions app/renderer/js/pages/preference/new-server-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ export function initNewServerForm({$root, onChange}: NewServerFormProps): void {
<div class="server-input-container">
<div class="title">${t.__("Organization URL")}</div>
<div class="add-server-info-row">
<input
class="setting-input-value"
autofocus
placeholder="your-organization.zulipchat.com or zulip.your-organization.com"
/>
<label class="setting-input-value">
<input
class="setting-input-add-server"
autofocus
placeholder="your-organization.zulipchat.com"
/>
<span class="add-server-domain"></span>
<span class="server-url-size-calc"></span>
</label>
</div>
<div class="server-center">
<button id="connect">${t.__("Connect")}</button>
Expand Down Expand Up @@ -53,14 +57,23 @@ export function initNewServerForm({$root, onChange}: NewServerFormProps): void {
$root.textContent = "";
$root.append($newServerForm);
const $newServerUrl: HTMLInputElement = $newServerForm.querySelector(
"input.setting-input-value",
"input.setting-input-add-server",
)!;
const $serverDomain: HTMLSpanElement = $newServerForm.querySelector(
"span.add-server-domain",
)!;
const $urlSizeCalc: HTMLSpanElement = $newServerForm.querySelector(
"span.server-url-size-calc",
)!;
const urlValidationPattern = /^[a-zA-Z\d-]*$/;

async function submitFormHandler(): Promise<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 +91,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 All @@ -86,6 +110,16 @@ export function initNewServerForm({$root, onChange}: NewServerFormProps): void {
await submitFormHandler();
}
});
$newServerUrl.addEventListener("input", async () => {
$newServerUrl.value = $newServerUrl.value.trim();
const url = $newServerUrl.value;
$urlSizeCalc.textContent = url;
$newServerUrl.style.width = `${$urlSizeCalc.offsetWidth}px`;

$serverDomain.textContent = urlValidationPattern.test(url)
? ".zulipchat.com"
: "";
});

// Open create new org link in default browser
const link = "https://zulip.com/new/";
Expand Down