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

View file

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