diff --git a/web/src/pages/index.tsx b/web/src/pages/index.tsx index 33c4265..cf1136d 100644 --- a/web/src/pages/index.tsx +++ b/web/src/pages/index.tsx @@ -222,7 +222,6 @@ type Followup = { type State = { state: "idle"; - followups: Followup[]; } | { state: "loading"; phase: "semantic" | "prompt" | "llm"; @@ -244,7 +243,8 @@ const Home: NextPage = () => { const [ entries, setEntries ] = useState([]); const [ runningIndex, setRunningIndex ] = useState(0); - const [ loadState, setLoadState ] = useState({state: "idle", followups: []}); + const [ loadState, setLoadState ] = useState({state: "idle"}); + const [ followups, setFollowups ] = useState([]); const search = async ( query: string, @@ -286,7 +286,8 @@ const Home: NextPage = () => { if (!res.ok) { setLoading(false); - setLoadState({state: "idle", followups: []}); + setLoadState({state: "idle"}); + setFollowups([]); setEntries([...new_entries, {role: "error", content: "POST Error: " + res.status}]); return; } @@ -358,14 +359,7 @@ const Home: NextPage = () => { case "done": - // append the response to the entries, add any potential followup questions, reset to normal - var followups: Followup[] = []; - var i = 0; - while ('followup_' + i in data) { - followups = [...followups, data['followup_' + i]]; - i++; - } - + // append the response to the entries, reset to normal setLoadState((s) => { if (s.state === "streaming") { setEntries([...new_entries, s.response]); @@ -373,9 +367,18 @@ const Home: NextPage = () => { } - return {state: "idle", followups: followups}; + return {state: "idle"}; }); + // add any potential followup questions + var fqs: Followup[] = []; + var i = 0; + while ('followup_' + i in data) { + fqs = [...fqs, data['followup_' + i]]; + i++; + } + setFollowups(fqs); + break read; case "error": @@ -429,7 +432,7 @@ const Home: NextPage = () => { {(() => { if (loadState.state === "idle") { return
{ - loadState.followups.map((followup, i) => { + followups.map((followup, i) => { return
  • +
    + setQuery(e.target.value)} + onKeyDown={(e) => { + // if , blur the input box + if (e.key === "Escape") e.currentTarget.blur(); + // if without , submit the form (if it's not empty) + if (e.key === "Enter" && !e.shiftKey) { + e.preventDefault(); + if (query.trim() !== "") search(query, setQuery, setLoading); + } + }} + /> + +
    ); };