11import type React from "react" ;
2- import type { ReactNode } from "react" ;
2+ import { type ReactNode , useEffect , useState } from "react" ;
33import "./App.css" ;
4+ import {
5+ type I18nApi ,
6+ I18nContext ,
7+ useViewModel ,
8+ } from "@element-hq/web-shared-components" ;
49import { InlineSpinner } from "@vector-im/compound-web" ;
5- import { useViewModel } from "@element-hq/web-shared-components" ;
610import { Client } from "./Client.tsx" ;
711import { Encryption } from "./Encryption.tsx" ;
12+ import { LoadingScreen } from "./LoadingScreen/LoadingScreen.tsx" ;
813import { Login } from "./Login.tsx" ;
914import { OidcCallback } from "./OidcCallback.tsx" ;
15+ import { I18nTest } from "./components/I18nTest.tsx" ;
1016import { useClientStoreContext } from "./context/ClientStoreContext" ;
1117import { useClientStoresContext } from "./context/ClientStoresContext" ;
1218import { useSessionStoreContext } from "./context/SessionStoreContext" ;
13- import { ClientState } from "./viewmodel/client-view.types " ;
19+ import { createI18nApi } from "./utils/i18nApi.ts " ;
1420import { ClientViewModel } from "./viewmodel/ClientViewModel" ;
21+ import { ClientState } from "./viewmodel/client-view.types" ;
1522
1623console . log ( "running App.tsx" ) ;
1724
1825const App : React . FC = ( ) => {
1926 const [ clientViewModel , setClientViewModel ] = useClientStoreContext ( ) ;
2027 const [ , addClientStore ] = useClientStoresContext ( ) ;
2128 const sessionStore = useSessionStoreContext ( ) ;
29+ const i18nApi = useI18nApi ( ) ;
2230
2331 // Check if we're on the OIDC callback route
2432 const isOidcCallback = window . location . pathname === "/oidc/callback" ;
@@ -38,10 +46,9 @@ const App: React.FC = () => {
3846 clientState === ClientState . LoadingSession
3947 ) {
4048 component = (
41- < div className = "mx_LoadingSession" >
42- < InlineSpinner size = { 32 } />
49+ < LoadingScreen >
4350 < h2 > Loading Session...</ h2 >
44- </ div >
51+ </ LoadingScreen >
4552 ) ;
4653 } else if ( clientState === ClientState . SettingUpEncryption ) {
4754 component = encryptionViewModel ? (
@@ -76,7 +83,34 @@ const App: React.FC = () => {
7683 ) : null ;
7784 }
7885
79- return < div className = "mx_App" > { component } </ div > ;
86+ if ( ! i18nApi ) {
87+ return (
88+ < div className = "mx_App" >
89+ < LoadingScreen > Loading translations</ LoadingScreen >
90+ </ div >
91+ ) ;
92+ }
93+ return (
94+ < div className = "mx_App" >
95+ < I18nContext . Provider value = { i18nApi } >
96+ { component }
97+ </ I18nContext . Provider >
98+ </ div >
99+ ) ;
80100} ;
81101
82102export default App ;
103+
104+ /**
105+ * A hook that initializes and provides an I18n API instance.
106+ * @returns
107+ */
108+ function useI18nApi ( ) : I18nApi | undefined {
109+ const [ i18nApi , setI18nApi ] = useState < I18nApi > ( ) ;
110+
111+ useEffect ( ( ) => {
112+ createI18nApi ( ) . then ( ( api ) => setI18nApi ( api ) ) ;
113+ } , [ ] ) ;
114+
115+ return i18nApi ;
116+ }
0 commit comments