import { commitLocalUpdate } from "relay-runtime" ; import { parseQuery } from "coral-common/utils" ; import { getParamsFromHashAndClearIt } from "coral-framework/helpers" ; import { parseAccessToken } from "coral-framework/lib/auth" ; import { InitLocalState } from "coral-framework/lib/bootstrap/createManaged" ; import { initLocalBaseState , LOCAL_ID } from "coral-framework/lib/relay" ; /**
 * Initializes the local state, before we start the App.
 */ const initLocalState = async ( { environment , auth = null , context , ... rest } ) => { const { error = null , accessToken = null } = getParamsFromHashAndClearIt ( context . window ) ; if ( accessToken ) { auth = parseAccessToken ( accessToken ) ; } await initLocalBaseState ( { environment , auth , context , ... rest } ) ; commitLocalUpdate ( environment , ( s ) => { const localRecord = s . get ( LOCAL_ID ) ! ; const query = parseQuery ( location . search ) ; localRecord . setValue ( query . view || "SIGN_IN" , "view" ) ; localRecord . setValue ( error , "error" ) ; } ) ; } ; export default initLocalState ;