Skip to content

Commit b948dbd

Browse files
committed
connect inputs
1 parent 2392c8d commit b948dbd

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

packages/connect-react/src/hooks/useLoginInputEventLow.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ type InputBatch = {
1616
lastTimestamp: number;
1717
};
1818

19+
const BIG_INPUT_DELTA_THRESHOLD = 3;
20+
1921
const useLoginInputEventLow = ({ inputRef, connectService, enabled }: Props) => {
2022
const inputBatchRef = useRef<InputBatch | null>(null);
23+
const previousLengthRef = useRef(0);
2124

2225
useEffect(() => {
2326
if (!enabled) {
@@ -29,6 +32,8 @@ const useLoginInputEventLow = ({ inputRef, connectService, enabled }: Props) =>
2932
return;
3033
}
3134

35+
previousLengthRef.current = input.value.length;
36+
3237
const isInputFocused = () => document.activeElement === input;
3338

3439
const resizeBatcher = createViewportBatcher(connectService, 'visualviewport-resize');
@@ -108,6 +113,21 @@ const useLoginInputEventLow = ({ inputRef, connectService, enabled }: Props) =>
108113

109114
const handleInput = () => {
110115
const timestamp = Date.now();
116+
117+
const newLength = input.value.length;
118+
const delta = newLength - previousLengthRef.current;
119+
previousLengthRef.current = newLength;
120+
121+
if (delta >= BIG_INPUT_DELTA_THRESHOLD) {
122+
connectService.enqueueLowEvent({ eventType: 'big-input-add', timestamp });
123+
return;
124+
}
125+
126+
if (delta <= -BIG_INPUT_DELTA_THRESHOLD) {
127+
connectService.enqueueLowEvent({ eventType: 'big-input-rem', timestamp });
128+
return;
129+
}
130+
111131
const currentBatch = inputBatchRef.current;
112132

113133
if (!currentBatch) {

0 commit comments

Comments
 (0)