web/Omnibox: allow input while antibot check is ongoing & fix spinner

This commit is contained in:
wukko 2024-09-20 15:20:25 +06:00
parent 8162877a47
commit c99240339d
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2
2 changed files with 17 additions and 10 deletions

View file

@ -36,6 +36,8 @@
let isFocused = false; let isFocused = false;
let isDisabled = false; let isDisabled = false;
let isBotCheckOngoing = false;
let isLoading = false;
const validLink = (url: string) => { const validLink = (url: string) => {
try { try {
@ -57,18 +59,18 @@
goto("/", { replaceState: true }); goto("/", { replaceState: true });
} }
// FIXME: figure out why regular processing spinner
// doesn't show up after turnstile loads
$: if ($cachedInfo?.info?.cobalt?.turnstileSitekey) { $: if ($cachedInfo?.info?.cobalt?.turnstileSitekey) {
if ($turnstileLoaded) { if ($turnstileLoaded) {
isDisabled = false; isBotCheckOngoing = false;
} else { } else {
isDisabled = true; isBotCheckOngoing = true;
} }
} else {
isBotCheckOngoing = false;
} }
const pasteClipboard = () => { const pasteClipboard = () => {
if (isDisabled || $dialogs.length > 0) { if ($dialogs.length > 0 || isDisabled || isLoading) {
return; return;
} }
@ -77,9 +79,11 @@
if (matchLink) { if (matchLink) {
$link = matchLink[0]; $link = matchLink[0];
if (!isBotCheckOngoing) {
await tick(); // wait for button to render await tick(); // wait for button to render
downloadButton.download($link); downloadButton.download($link);
} }
}
}); });
}; };
@ -88,7 +92,7 @@
}; };
const handleKeydown = (e: KeyboardEvent) => { const handleKeydown = (e: KeyboardEvent) => {
if (!linkInput || $dialogs.length > 0 || isDisabled) { if (!linkInput || $dialogs.length > 0 || isDisabled || isLoading) {
return; return;
} }
@ -135,8 +139,8 @@
class:focused={isFocused} class:focused={isFocused}
class:downloadable={validLink($link)} class:downloadable={validLink($link)}
> >
<div id="input-link-icon" class:loading={isDisabled}> <div id="input-link-icon" class:loading={isLoading || isBotCheckOngoing}>
{#if isDisabled} {#if isLoading || isBotCheckOngoing}
<IconLoader2 /> <IconLoader2 />
{:else} {:else}
<IconLink /> <IconLink />
@ -168,6 +172,7 @@
url={$link} url={$link}
bind:this={downloadButton} bind:this={downloadButton}
bind:disabled={isDisabled} bind:disabled={isDisabled}
bind:loading={isLoading}
/> />
{/if} {/if}
</div> </div>

View file

@ -10,6 +10,7 @@
export let url: string; export let url: string;
export let disabled = false; export let disabled = false;
export let loading = false;
$: buttonText = ">>"; $: buttonText = ">>";
$: buttonAltText = $t("a11y.save.download"); $: buttonAltText = $t("a11y.save.download");
@ -31,6 +32,7 @@
const changeDownloadButton = (state: DownloadButtonState) => { const changeDownloadButton = (state: DownloadButtonState) => {
disabled = state !== "idle"; disabled = state !== "idle";
loading = state === "think" || state === "check";
buttonText = { buttonText = {
idle: ">>", idle: ">>",