import React, { useState } from "react" import { WordChip } from "./WordChip" import { Spinner } from "./Spinner" import { Word } from "../interfaces" async function checkText(text: string): Promise { const encodedText = encodeURIComponent(text); const response = await fetch(`/check?text=${encodedText}`); const data = await response.json(); console.log(data); return data.words; } export default function App() { const [threshold, setThreshold] = useState(-5.0) const [context, setContext] = useState("") const [wordlist, setWordlist] = useState("") const [showWholePrompt, setShowWholePrompt] = useState(false) // const [text, setText] = useState("I just drove to the store to but eggs, but they had some.") const [text, setText] = useState("I drove to the stove to but eggs") const [mode, setMode] = useState<"edit" | "check">("edit") const [words, setWords] = useState([]) const [isLoading, setIsLoading] = useState(false) const check = async (text: string) => { setIsLoading(true) try { const checkedWords = await checkText(text) setWords(checkedWords) } finally { setIsLoading(false) setMode("check") } } const toggleMode = async () => { if (mode === "edit") { setIsLoading(true) await check(text) } else { setMode("edit") } } const handleReplace = async (index: number, newWord: string) => { console.log("handleReplace", index, newWord) const updatedWords = words.map((w, i) => { if (i === index) { return { text: newWord, logprob: 0, replacements: [] } } return w }) setWords(updatedWords) const newText = updatedWords.map(w => w.text).join("") setText(newText) await check(newText) } let result if (mode === "edit") { result = (
{isLoading && }