Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
printfn committed Dec 6, 2024
1 parent 9687d3d commit 3fb08f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
6 changes: 3 additions & 3 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function NewTabLink({ children, href }: { children: ReactNode; href: string }) {

export default function App({ widget = false }: { widget?: boolean }) {
const [output, setOutput] = useState<ReactNode>(widget ? <></> : exampleContent);
const { currentInput, addToHistory, onInput, upArrow, downArrow } = useCurrentInput();
const { currentInput, submit, onInput, upArrow, downArrow } = useCurrentInput();
const [variables, setVariables] = useState('');
const [hint, setHint] = useState('');
useEffect(() => {
Expand Down Expand Up @@ -103,7 +103,7 @@ export default function App({ widget = false }: { widget?: boolean }) {

startTransition(async () => {
const request = <p>{`> ${currentInput}`}</p>;
addToHistory(currentInput);
submit();
const fendResult = await fend(currentInput, 1000000000, variables);
if (!fendResult.ok && fendResult.message === 'cancelled') {
return;
Expand All @@ -124,7 +124,7 @@ export default function App({ widget = false }: { widget?: boolean }) {
inputHint.current?.scrollIntoView();
});
},
[currentInput, addToHistory, variables, onInput, downArrow, upArrow],
[currentInput, submit, variables, onInput, downArrow, upArrow],
);
useEffect(() => {
document.addEventListener('click', focus);
Expand Down
15 changes: 6 additions & 9 deletions web/src/hooks/useCurrentInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FormEvent, useCallback, useState } from 'react';
import { useHistory } from './useHistory';

export function useCurrentInput() {
const { history, addToHistory: saveToHistory } = useHistory();
const { history, addToHistory } = useHistory();
const [currentInput, setCurrentInput] = useState('');
const [navigation, setNavigation] = useState(0);

Expand Down Expand Up @@ -53,13 +53,10 @@ export function useCurrentInput() {
navigate('down');
}, [navigate]);

const addToHistory = useCallback(
(newEntry: string) => {
saveToHistory(newEntry);
setNavigation(0);
},
[saveToHistory],
);
const submit = useCallback(() => {
addToHistory(currentInput);
setNavigation(0);
}, [currentInput, addToHistory]);

return { currentInput, addToHistory, onInput, downArrow, upArrow };
return { currentInput, submit, onInput, downArrow, upArrow };
}

0 comments on commit 3fb08f4

Please sign in to comment.