@@ -55,7 +55,7 @@ import LanguageSelector from "./LanguageSelector";
5555import { getQuestion } from "./QuestionSelector" ;
5656
5757function App ( ) {
58- const { lang, t, questions, dbArrayBuffer, defaultQuery, isLoading } = useLanguage ( ) ;
58+ const { lang, t, questions, dbArrayBuffer, defaultQuery } = useLanguage ( ) ;
5959 const [ question , setQuestion ] = useState < Question > ( ) ;
6060 const [ database , setDatabase ] = useState < initSqlJs . Database > ( ) ;
6161 const [ error , setError ] = useState < string | null > ( null ) ;
@@ -205,10 +205,20 @@ function App() {
205205 }
206206 } , [ question ] ) ;
207207
208+ // Track which language the current question was loaded in
209+ const questionLangRef = useRef ( lang ) ;
210+ useEffect ( ( ) => {
211+ if ( question ) questionLangRef . current = lang ;
212+ } , [ question , lang ] ) ;
213+
208214 useEffect ( ( ) => {
209215 if ( ! database || ! question || query === undefined ) {
210216 return ;
211217 }
218+ // Don't write to localStorage if lang changed but question hasn't been cleared yet
219+ if ( questionLangRef . current !== lang ) {
220+ return ;
221+ }
212222 let wq = JSON . parse ( localStorage . getItem ( langKey ( lang , "writtenQuestions" ) ) || "[]" ) ;
213223 const initialLength = wq . length ;
214224 if ( query === defaultQuery || query === "" ) {
@@ -382,6 +392,9 @@ function App() {
382392 if ( ! result || ! question || evaluatedQuery !== query ) {
383393 return ;
384394 }
395+ if ( questionLangRef . current !== lang ) {
396+ return ;
397+ }
385398 const matchesPrimary = isCorrectResult ( question . evaluable_result , result ) ;
386399 const matchedAlt = ! matchesPrimary ? question . alternative_evaluable_results ?. find ( alt => isCorrectResult ( alt , result ) ) : undefined ;
387400 if ( ! matchesPrimary && ! matchedAlt ) {
@@ -781,17 +794,6 @@ function App() {
781794 } ) ;
782795 } , [ evaluatedQuery , exportQuery , exportRendererRef , getTheme , isDarkMode , exportingStatus , question , resetResult , setTheme , exportQuestion , exportView ] ) ;
783796
784- if ( isLoading ) {
785- return (
786- < div className = "App" >
787- < header className = "App-header" >
788- < h1 className = "text-6xl font-semibold my-3" > SQL Validator</ h1 >
789- < p className = "text-base text-gray-500" > Loading...</ p >
790- </ header >
791- </ div >
792- ) ;
793- }
794-
795797 return (
796798 < div className = "App" >
797799 { exportQuestion && exportQuery && < ExportRenderer query = { { isCorrect : isCorrectResult ( exportQuestion . evaluable_result , evalSql ( exportQuery ) ) || ( exportQuestion . alternative_evaluable_results ?. some ( alt => isCorrectResult ( alt , evalSql ( exportQuery ) ) ) ?? false ) , question : exportQuestion , code : exportQuery , result : evalSql ( exportQuery ) } } ref = { exportRendererRef } /> }
0 commit comments