@@ -6,8 +6,7 @@ import {ThemeName} from '../types';
66const LOG_PREFIX = '[AppConfig]' ;
77
88const BASE_API_URL = process . env . REACT_APP_API_URL || ( window . location . origin + window . location . pathname ) ;
9- // Add loading state tracking
10- let isLoadingConfig = false ;
9+
1110let loadConfigPromise : Promise < any > | null = null ;
1211const STORAGE_KEYS = {
1312 THEME : 'theme' ,
@@ -65,29 +64,17 @@ export const themeStorage = {
6564 }
6665} ;
6766
67+ export interface AppConfig {
68+ applicationName : string ;
69+ singleInput : boolean ;
70+ showMenubar : boolean ;
71+ }
6872
6973// Add config cache
7074let cachedConfig : any = null ;
7175const CONFIG_CACHE_KEY = 'app_config_cache' ;
72- const CONFIG_CACHE_TTL = 24 * 60 * 60 * 1000 ; // 24 hours
73- // Try to load cached config from localStorage
74- try {
75- const cached = localStorage . getItem ( CONFIG_CACHE_KEY ) ;
76- if ( cached ) {
77- const { config, timestamp} = JSON . parse ( cached ) ;
78- if ( Date . now ( ) - timestamp < CONFIG_CACHE_TTL ) {
79- cachedConfig = config ;
80- console . info ( `${ LOG_PREFIX } Loaded valid config from cache` ) ;
81- } else {
82- localStorage . removeItem ( CONFIG_CACHE_KEY ) ;
83- console . info ( `${ LOG_PREFIX } Removed expired config cache` ) ;
84- }
85- }
86- } catch ( error ) {
87- console . warn ( `${ LOG_PREFIX } Error loading cached config:` , error ) ;
88- }
8976
90- export const fetchAppConfig = async ( sessionId : string ) => {
77+ export const fetchAppConfig : ( sessionId : string ) => Promise < AppConfig > = async ( sessionId : string ) => {
9178 try {
9279 // Return cached config if available
9380 if ( cachedConfig ) {
@@ -99,8 +86,6 @@ export const fetchAppConfig = async (sessionId: string) => {
9986 console . info ( `${ LOG_PREFIX } Config fetch already in progress, reusing promise` ) ;
10087 return loadConfigPromise ;
10188 }
102- // Set loading state
103- isLoadingConfig = true ;
10489 loadConfigPromise = ( async ( ) => {
10590
10691 console . info ( `${ LOG_PREFIX } Fetching app config:` , {
@@ -188,7 +173,6 @@ export const fetchAppConfig = async (sessionId: string) => {
188173 return data ;
189174 } ) ( ) ;
190175 const result = await loadConfigPromise ;
191- isLoadingConfig = false ;
192176 loadConfigPromise = null ;
193177 return result ;
194178
@@ -199,7 +183,6 @@ export const fetchAppConfig = async (sessionId: string) => {
199183 url : BASE_API_URL ? `${ BASE_API_URL } /appInfo` : '/appInfo' ,
200184 env : process . env . NODE_ENV
201185 } ) ;
202- isLoadingConfig = false ;
203186 loadConfigPromise = null ;
204187 throw error ;
205188 }
0 commit comments