Skip to content

Commit 22b2ddc

Browse files
committed
Clean up useCurrentInput
1 parent bdef38e commit 22b2ddc

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

web/src/hooks/useCurrentInput.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function useCurrentInput() {
77
const [navigation, setNavigation] = useState(0);
88

99
const navigate = useCallback(
10-
(direction: 'up' | 'down' | 'bottom') => {
10+
(direction: 'up' | 'down') => {
1111
setNavigation(n => {
1212
let newValue: number;
1313
switch (direction) {
@@ -17,14 +17,11 @@ export function useCurrentInput() {
1717
case 'down':
1818
newValue = Math.max(n - 1, 0);
1919
break;
20-
case 'bottom':
21-
newValue = 0;
22-
break;
2320
}
2421
if (newValue > 0) {
2522
setCurrentInput(history[history.length - newValue]);
2623
}
27-
if (newValue === 0 && (direction === 'up' || direction === 'down')) {
24+
if (newValue === 0) {
2825
setCurrentInput('');
2926
}
3027
return newValue;
@@ -33,13 +30,10 @@ export function useCurrentInput() {
3330
[history],
3431
);
3532

36-
const onInput = useCallback(
37-
(e: string | FormEvent<HTMLTextAreaElement>) => {
38-
navigate('bottom');
39-
setCurrentInput(typeof e === 'string' ? e : e.currentTarget.value);
40-
},
41-
[navigate],
42-
);
33+
const onInput = useCallback((e: string | FormEvent<HTMLTextAreaElement>) => {
34+
setNavigation(0);
35+
setCurrentInput(typeof e === 'string' ? e : e.currentTarget.value);
36+
}, []);
4337

4438
const upArrow = useCallback(() => {
4539
if (currentInput.trim().length !== 0 && navigation === 0) {

0 commit comments

Comments
 (0)