@@ -25,16 +25,18 @@ async function sendPing() {
2525
2626export function LandingHome ( ) {
2727 const {
28- initStore, timeSeries, variable, plotOn ,
29- setZMeta, setVariables, setTitleDescription,
28+ initStore, timeSeries, variable, storeFromURL ,
29+ setZMeta, setVariables, setTitleDescription, setOpenVariables , setStoreFromURL ,
3030 } = useGlobalStore ( useShallow ( state => ( {
3131 initStore : state . initStore ,
3232 timeSeries : state . timeSeries ,
3333 variable : state . variable ,
34- plotOn : state . plotOn ,
34+ storeFromURL : state . storeFromURL ,
3535 setZMeta : state . setZMeta ,
3636 setVariables : state . setVariables ,
3737 setTitleDescription : state . setTitleDescription ,
38+ setOpenVariables : state . setOpenVariables ,
39+ setStoreFromURL : state . setStoreFromURL ,
3840 } ) ) )
3941
4042 const { currentStore, fetchKey,
@@ -49,27 +51,27 @@ export function LandingHome() {
4951 setUseNC : state . setUseNC
5052 } ) ) )
5153
52- function resetSlices ( ) {
53- setZSlice ( [ 0 , null ] )
54- setYSlice ( [ 0 , null ] )
55- setXSlice ( [ 0 , null ] )
56- }
57-
5854 useEffect ( ( ) => {
59- resetSlices ( ) ;
55+ void fetchKey ;
56+ setZSlice ( [ 0 , null ] ) ;
57+ setYSlice ( [ 0 , null ] ) ;
58+ setXSlice ( [ 0 , null ] ) ;
6059 if ( initStore . startsWith ( 'local:' ) ) {
6160 const path = initStore . replace ( 'local:' , '' ) ;
62- if ( ! NETCDF_EXT_REGEX . test ( path ) ) return ; // TODO: handled zarr
61+ if ( ! NETCDF_EXT_REGEX . test ( path ) ) return ;
6362 const filename = path . split ( '/' ) . pop ( ) ?? 'file.nc' ;
6463 fetch ( `/file?path=${ encodeURIComponent ( path ) } ` )
6564 . then ( res => {
6665 if ( ! res . ok ) throw new Error ( `HTTP ${ res . status } ` ) ;
6766 return res . blob ( ) ;
6867 } )
69- . then ( blob => {
70- loadNetCDF ( blob , filename ) ;
71- useGlobalStore . setState ( { openVariables : true } )
72- return
68+ . then ( async blob => {
69+ await loadNetCDF ( blob , filename ) ;
70+ if ( storeFromURL ) {
71+ setOpenVariables ( true ) ;
72+ setStoreFromURL ( false ) ;
73+ }
74+ return ;
7375 } )
7476 . catch ( e => useGlobalStore . getState ( ) . setStatus ( `Failed to load: ${ e instanceof Error ? e . message : String ( e ) } ` ) ) ;
7577 return ;
@@ -86,23 +88,40 @@ export function LandingHome() {
8688 // Clear after use
8789 useZarrStore . getState ( ) . setIcechunkOptions ( null ) ;
8890 useZarrStore . getState ( ) . setFetchOptions ( null ) ;
89- } , [ initStore , fetchKey , setCurrentStore ] )
91+ } , [ initStore , fetchKey , setCurrentStore , setUseNC , setZSlice , setYSlice , setXSlice , storeFromURL , setOpenVariables , setStoreFromURL ] ) ;
9092
9193 useEffect ( ( ) => {
94+ const { initStore } = useGlobalStore . getState ( ) ;
95+ if ( initStore . startsWith ( 'local' ) ) return ;
96+
9297 let isMounted = true ;
98+ const activeStore = currentStore ;
9399
94- GetTitleDescription ( currentStore ) . then ( ( result ) => {
95- if ( isMounted ) setTitleDescription ( result ) ;
100+ GetTitleDescription ( activeStore ) . then ( ( result ) => {
101+ if ( isMounted && currentStore === activeStore ) setTitleDescription ( result ) ;
96102 } ) ;
97103
98- const fullmetadata = GetZarrMetadata ( currentStore ) ;
104+ const fullmetadata = GetZarrMetadata ( activeStore ) ;
99105 const variables = GetVariableNames ( fullmetadata ) ;
100106
101- fullmetadata . then ( e => setZMeta ( e ) )
102- variables . then ( e => setVariables ( e ) )
107+ fullmetadata . then ( ( e ) => {
108+ if ( isMounted && currentStore === activeStore ) setZMeta ( e ) ;
109+ } ) ;
110+ variables . then ( ( e ) => {
111+ if ( isMounted && currentStore === activeStore ) {
112+ setVariables ( e ) ;
113+ const { storeFromURL } = useGlobalStore . getState ( ) ;
114+ if ( storeFromURL ) {
115+ setOpenVariables ( true ) ;
116+ setStoreFromURL ( false ) ;
117+ }
118+ }
119+ } ) ;
103120
104- return ( ) => { isMounted = false ; } ;
105- } , [ currentStore , setZMeta , setVariables , setTitleDescription ] )
121+ return ( ) => {
122+ isMounted = false ;
123+ } ;
124+ } , [ currentStore , setZMeta , setVariables , setTitleDescription , setOpenVariables , setStoreFromURL ] ) ;
106125
107126 useEffect ( ( ) => {
108127 if ( process . env . NODE_ENV !== "development" ) {
0 commit comments