()
| 38 | } |
| 39 | |
| 40 | export default function Home() { |
| 41 | const { resolvedTheme } = useTheme(); |
| 42 | const isThemeDark = resolvedTheme === "dark"; |
| 43 | const [mounted, setMounted] = useState(false); |
| 44 | const { |
| 45 | translate, |
| 46 | translating, |
| 47 | outputText, |
| 48 | setOutputText, |
| 49 | translationError, |
| 50 | } = useTranslate(); |
| 51 | const [inputText, setInputText] = useState(""); |
| 52 | const [prevquery, setPrevquery] = useState<prev[]>([]); |
| 53 | const [isHumanToSql, setIsHumanToSql] = useState(true); |
| 54 | const [isOutputTextUpperCase, setIsOutputTextUpperCase] = useState(false); |
| 55 | const [tableSchema, setTableSchema] = useState(""); |
| 56 | const [showTableSchema, setShowTableSchema] = useState(false); |
| 57 | const [history, setHistory] = useState<IHistory[]>([]); |
| 58 | const [showHistory, setShowHistory] = useState(false); |
| 59 | const [hasTranslated, setHasTranslated] = useState(false); |
| 60 | const [copied, setCopied] = useState<ITextCopied>(); |
| 61 | |
| 62 | useEffect(() => { |
| 63 | if (inputText && hasTranslated) { |
| 64 | setHistory((prevHistory) => [ |
| 65 | ...prevHistory, |
| 66 | { |
| 67 | inputText: JSON.stringify(inputText), |
| 68 | outputText: JSON.stringify(outputText), |
| 69 | tableSchema, |
| 70 | isHumanToSql, |
| 71 | }, |
| 72 | ]); |
| 73 | |
| 74 | addHistoryEntry({ |
| 75 | inputText: JSON.stringify(inputText), |
| 76 | tableSchema, |
| 77 | isHumanToSql, |
| 78 | outputText: JSON.stringify(outputText), |
| 79 | }); |
| 80 | |
| 81 | setHasTranslated(false); |
| 82 | } |
| 83 | }, [outputText]); |
| 84 | |
| 85 | useEffect(() => { |
| 86 | setMounted(true); |
| 87 | }, []); |
| 88 | |
| 89 | useEffect(() => { |
| 90 | if (translationError) toast.error(translationError); |
| 91 | }, [translationError]); |
| 92 | |
| 93 | if (!mounted) { |
| 94 | return null; |
| 95 | } |
| 96 | |
| 97 | const isValidTableSchema = (text: string) => { |
nothing calls this directly
no test coverage detected