Skip to content

Commit

Permalink
Clean up useCurrentInput
Browse files Browse the repository at this point in the history
  • Loading branch information
printfn committed Dec 6, 2024
1 parent bdef38e commit 22b2ddc
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions web/src/hooks/useCurrentInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function useCurrentInput() {
const [navigation, setNavigation] = useState(0);

const navigate = useCallback(
(direction: 'up' | 'down' | 'bottom') => {
(direction: 'up' | 'down') => {
setNavigation(n => {
let newValue: number;
switch (direction) {
Expand All @@ -17,14 +17,11 @@ export function useCurrentInput() {
case 'down':
newValue = Math.max(n - 1, 0);
break;
case 'bottom':
newValue = 0;
break;
}
if (newValue > 0) {
setCurrentInput(history[history.length - newValue]);
}
if (newValue === 0 && (direction === 'up' || direction === 'down')) {
if (newValue === 0) {
setCurrentInput('');
}
return newValue;
Expand All @@ -33,13 +30,10 @@ export function useCurrentInput() {
[history],
);

const onInput = useCallback(
(e: string | FormEvent<HTMLTextAreaElement>) => {
navigate('bottom');
setCurrentInput(typeof e === 'string' ? e : e.currentTarget.value);
},
[navigate],
);
const onInput = useCallback((e: string | FormEvent<HTMLTextAreaElement>) => {
setNavigation(0);
setCurrentInput(typeof e === 'string' ? e : e.currentTarget.value);
}, []);

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

0 comments on commit 22b2ddc

Please sign in to comment.