Skip to content

Commit 7d8a6f6

Browse files
committed
perf: speed up autocomplete in create job form
1 parent 4e388ed commit 7d8a6f6

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/algora_web/live/jobs_live.ex

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ defmodule AlgoraWeb.JobsLive do
167167
label="Email"
168168
data-domain-target
169169
phx-hook="DeriveDomain"
170-
phx-blur="email_changed"
170+
phx-change="email_changed"
171+
phx-debounce="300"
171172
/>
172173
<.input field={@form[:url]} label="Job Posting URL" />
173174
<.input field={@form[:company_url]} label="Company URL" data-domain-source />
@@ -197,7 +198,7 @@ defmodule AlgoraWeb.JobsLive do
197198
<div class="flex gap-2 items-center">
198199
<%= if url = get_change(@form.source, :company_url) do %>
199200
<.link
200-
href={url}
201+
href={"https://" <> url}
201202
target="_blank"
202203
class="text-muted-foreground hover:text-foreground"
203204
>
@@ -244,11 +245,12 @@ defmodule AlgoraWeb.JobsLive do
244245
{:noreply, socket}
245246
end
246247

247-
def handle_event("email_changed", %{"value" => email}, socket) do
248-
{:noreply,
249-
socket
250-
|> start_async(:fetch_metadata, fn -> Algora.Crawler.fetch_user_metadata(email) end)
251-
|> assign(:user_metadata, AsyncResult.loading())}
248+
def handle_event("email_changed", %{"job_posting" => %{"email" => email}}, socket) do
249+
if String.match?(email, ~r/^[^\s]+@[^\s]+$/i) do
250+
{:noreply, start_async(socket, :fetch_metadata, fn -> Algora.Crawler.fetch_user_metadata(email) end)}
251+
else
252+
{:noreply, socket}
253+
end
252254
end
253255

254256
@impl true

0 commit comments

Comments
 (0)