Skip to content

Commit 8e8ccb4

Browse files
author
Llorenç
committed
Change submit trigger
1 parent 16fd23e commit 8e8ccb4

File tree

1 file changed

+29
-11
lines changed
  • src/frontend/src/routes/(new-styling)/recovery-phrase

1 file changed

+29
-11
lines changed

src/frontend/src/routes/(new-styling)/recovery-phrase/+page.svelte

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
// Flag to prevent double-triggering recovery on multiple blur events
1414
let recoveryInProgress = $state(false);
1515
16+
// Timeout ID for debounced submission
17+
let submitTimeoutId = $state<number | undefined>(undefined);
18+
1619
// TODO: Use word validation instead of presence.
1720
const submitEnabled = $derived(
1821
words.every((word) => word.value.trim().length > 0),
@@ -21,6 +24,11 @@
2124
const handleKeyDownInput = (event: KeyboardEvent, currentIndex: number) => {
2225
const isLastIndex = currentIndex === words.length - 1;
2326
if (event.key === "Enter" && isLastIndex && submitEnabled) {
27+
// Clear any pending timeout and submit immediately
28+
if (submitTimeoutId !== undefined) {
29+
clearTimeout(submitTimeoutId);
30+
submitTimeoutId = undefined;
31+
}
2432
handleRecoverWithPhrase();
2533
return;
2634
}
@@ -36,6 +44,18 @@
3644
}
3745
}
3846
}
47+
48+
// Clear existing timeout and start new one for auto-submit
49+
if (submitTimeoutId !== undefined) {
50+
clearTimeout(submitTimeoutId);
51+
}
52+
53+
// Set 1 second timeout to auto-submit if all words are filled
54+
submitTimeoutId = window.setTimeout(() => {
55+
if (submitEnabled && !recoveryInProgress) {
56+
handleRecoverWithPhrase();
57+
}
58+
}, 1000);
3959
};
4060
4161
const handleRecoverWithPhrase = async () => {
@@ -92,20 +112,19 @@
92112
`recovery-phrase-${focusIndex}`,
93113
);
94114
// Don't set focus somewhere if all words are filled.
95-
if (nonNullish(nextElement) && focusIndex < words.length - 1) {
115+
if (nonNullish(nextElement) && focusIndex === words.length - 1) {
96116
nextElement.focus();
97-
} else {
98-
// This will trigger the recovery flow if all words are filled.
99-
(event.currentTarget as HTMLElement)?.blur();
100117
}
101118
};
102119
103-
const handleBlur = () => {
104-
// Auto-submit when all 24 words are complete
105-
if (submitEnabled && !recoveryInProgress) {
106-
handleRecoverWithPhrase();
107-
}
108-
};
120+
// Cleanup timeout on component unmount
121+
$effect(() => {
122+
return () => {
123+
if (submitTimeoutId !== undefined) {
124+
clearTimeout(submitTimeoutId);
125+
}
126+
};
127+
});
109128
</script>
110129

111130
<div
@@ -132,7 +151,6 @@
132151
bind:value={word.value}
133152
onkeydown={(e) => handleKeyDownInput(e, i)}
134153
onpaste={(e) => handlePaste(e, i)}
135-
onblur={handleBlur}
136154
class="peer text-text-primary ring-border-secondary focus:ring-border-brand h-8 w-full rounded-full border-none bg-transparent pl-10 text-base ring outline-none ring-inset focus:ring-2"
137155
/>
138156
<!-- Left slot -->

0 commit comments

Comments
 (0)